Created
November 15, 2022 13:15
-
-
Save danya02/826cb5ebce014a3b71526271e3c35f40 to your computer and use it in GitHub Desktop.
Program for testing https://www.codingame.com/ide/puzzle/shadows-of-the-knight-episode-1
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import subprocess | |
import random | |
ROOM_SIZE = 100 | |
xb = random.randint(0, ROOM_SIZE) | |
yb = random.randint(0, ROOM_SIZE) | |
xs = random.randint(0, ROOM_SIZE) | |
ys = random.randint(0, ROOM_SIZE) | |
print("Open prog") | |
prog = subprocess.Popen(['python3', 'testable.py'], stdin=subprocess.PIPE, stdout=subprocess.PIPE, text=True) | |
steps = 0 | |
print(ROOM_SIZE, ROOM_SIZE, file=prog.stdin) | |
print(999, file=prog.stdin) | |
print(xs, ys, file=prog.stdin) | |
steps = 99 | |
while (xs, ys) != (xb, yb): | |
steps -= 1 | |
if steps == 0: | |
print("Loop!") | |
print("True position: ", xb, yb) | |
exit(1) | |
print("Current position is", xs, ys) | |
code = '' | |
if ys < yb: code += 'D' | |
if ys > yb: code += 'U' | |
if xs < xb: code += 'R' | |
if xs > xb: code += 'L' | |
print("Dir: ", code) | |
print(code, file=prog.stdin, flush=True) | |
import sys | |
sys.stdin = prog.stdout | |
xs, ys = map(int, input().split()) | |
print("Result OK") | |
print("Current position is", xs, ys) | |
print("True position: ", xb, yb) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment