Skip to content

Instantly share code, notes, and snippets.

@danya02
Created November 15, 2022 13:15
Show Gist options
  • Save danya02/826cb5ebce014a3b71526271e3c35f40 to your computer and use it in GitHub Desktop.
Save danya02/826cb5ebce014a3b71526271e3c35f40 to your computer and use it in GitHub Desktop.
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