#!/usr/bin/env python import socket import time import random s=socket.socket(socket.AF_INET, socket.SOCK_STREAM) s.connect(("194.106.195.60",9502)) # fetch manual data = s.recv(1024) print "MANUAL: " + data down = 1 solved = 0 while 1: # fetch board board = s.recv(1024).split("\n") print "BOARD: " + str(board) if "Solved" in board[0]: # print "SUCCESS!!!\n" print board solved += 1 print "\nSolved: " + str(solved) board = s.recv(1024).split("\n") print "FLAG: " + str(board) # print "BOARD: " + str(board) if down == 1: solution = "" found = 0 for y in range(0,9): line = board[y] for x in range(10): if line[x] == "-": solution = solution + str(y+1) + str(x) found = 1 if found == 1: break if found == 0: line = board[9] pos = line.find("---") if pos != -1: solution = "9" + str(pos+1) else: pos = line.find("--") if pos != -1: solution = "9" + str(pos+1) if solution == "": solution = "9" + str(random.randint(0,9)) print "GOING UP..." down = 0 else: solution = "" found = 0 for y in range(9,0,-1): line = board[y] for x in range(10): if line[x] == "-": solution = solution + str(y-1) + str(x) found = 1 if found == 1: break if found == 0: line = board[0] pos = line.find("---") if pos != -1: solution = "0" + str(pos+1) else: pos = line.find("--") if pos != -1: solution = "0" + str(pos+1) if solution == "": solution = "0" + str(random.randint(0,9)) print "GOING DOWN..." down = 1 print "SOLUTION: " + solution s.send(solution) # time.sleep(1) s.close()