Skip to content

Instantly share code, notes, and snippets.

Created December 7, 2020 22:27
What would you like to do?
# This is an ASCII space game where you are a ship ^ at the bottom of the field
# dodging ‘rocks’ represented by ‘0’ characters. To play, just connect via ‘nc’
# to the port 5555. You have to move left and right with the arrow keys, pressing
# enter each time, but the game gets too fast to play by hand. To solve it, I
# wrote a simple bot to play the game by moving left and right based on the next
# 2 rocks. It doesn’t account for every possible case, but got lucky enough to
# win the first try. After you win, a new HTTP service starts listening on port
# 7878 (it prints a message), which contains the flag for download.
import socket, sys
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
sock.connect(('target', 5555))
def move_left():
def move_right():
board = sock.recv(1000)
status = sock.recv(1000)
if len(board) < 100:
lines = board[1:].decode('ascii').split("\r\n")
my_pos = lines[-2].find("^")
rock_pos = lines[-4].find("0")
next_rock_pos = lines[-5].find("0")
if my_pos == rock_pos:
if my_pos - 1 != next_rock_pos:
if my_pos != 1:
elif my_pos + 1 != next_rock_pos:
print(rock_pos, next_rock_pos, my_pos)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment