예제 #1
0
파일: main.py 프로젝트: ahuff44/go-bot
 def play(self, board, last_move):
     print board
     inp = raw_input("> ")
     if inp in ["p", "pass"]:
         self.send_pass()
         # TODO: return Pass()
         return utils.Either(True, Coord.from_numeric(board.size, (-1, 1)))
     else:
         coord = Coord.from_visual(board.size, inp)
         self.send_move(coord)
         return utils.Either(True, coord)
예제 #2
0
파일: main.py 프로젝트: ahuff44/go-bot
 def get_all(self, url, params={}, headers={}, LIMIT=1000):
     data = self.get(url, params=params, headers=headers)
     if data["count"] > LIMIT:
         return utils.Either(False, "You are not allowed to retrieve more than %d records at once"%LIMIT)
     else:
         aggregate = copy.copy(data["results"])
         while data["next"]:
             next_url = data["next"]
             data = self.get(next_url, headers=headers) # TODO: include headers here?
             aggregate.extend(data["results"])
         return utils.Either(True, aggregate)
예제 #3
0
파일: main.py 프로젝트: ahuff44/go-bot
 def play(self, board, last_move):
     legal = board.legal_coords()
     # print "legal moves: {}".format(map(str, legal))
     if legal:
         coord = random.choice(list(legal))
         # print "randomly chose {}".format(coord)
         self.send_move(coord)
         return utils.Either(True, coord)
     else:
         # TODO: return Pass()
         self.send_pass()
         return utils.Either(True, Coord.from_numeric(board.size, (-1, 1)))
예제 #4
0
파일: main.py 프로젝트: ahuff44/go-bot
    def play(self, board, last_move):
        POLL_PERIOD = 5
        MAX_POLL_ATTEMPTS = 10
        for attempt_num in xrange(MAX_POLL_ATTEMPTS):
            self.api.log("Poll attempt #%d..."%attempt_num)
            game = self.api.get_game(self.game_id)

            x, y, time = game["gamedata"]["moves"][-1]
            coord = Coord.from_numeric(board.size, (x, y))

            if last_move != coord:
                print "Recieved opponent's move:", coord
                return utils.Either(True, coord)
            sleep(POLL_PERIOD)
        return utils.Either(False, "Gave up polling for opponent response")
예제 #5
0
파일: main.py 프로젝트: ahuff44/go-bot
def play_game(p1, p2, fetch_board):
    # assumes p1 will go first
    board = fetch_board()
    e_p2_move = utils.Either(True, None)
    while True:
        e_p1_move = p1.play(board, e_p2_move.contents())
        if type(e_p1_move) != type(utils.Either(True, 0)):
            raise Exception, "Bad return type from Go_Strategy interface; must return an Either"
        # TODO: also enforce that board has one new move... another reason to make a Game() object
        print "Got p1's move: {}".format(e_p1_move.contents())

        # TODO: replace with if board != fetch_board(): raise Error
        board = fetch_board()

        e_p2_move = p2.play(board, e_p1_move.contents())
        if type(e_p1_move) != type(utils.Either(True, 0)): # TODO: this is ugly
            raise Exception, "Bad return type from Go_Strategy interface; must return an Either"
        # TODO: also enforce that board has one new move... another reason to make a Game() object
        print "Got p2's move: {}".format(e_p2_move.contents())

        # TODO: replace with if board != fetch_board(): raise Error
        board = fetch_board()
예제 #6
0
파일: main.py 프로젝트: ahuff44/go-bot
 def play(self, board):
     # TODO: s/Coord(...)/Pass()
     return utils.Either(True, Coord.from_numeric(board.size, (-1, -1)))