def move_search(self, starting_node, time_limit, current_player, other_player): self.player = current_player self.other_player = other_player possible_moves = starting_node.get_valid_moves(current_player) if len(possible_moves) == 1: # print "Only 1 Possible Move:", possible_moves[0] return possible_moves[0] depth = 0 score = -sys.maxint - 1 move = None time_start = datetime.datetime.now() self.time_done = time_start + datetime.timedelta(seconds=time_limit) time_cutoff = time_start + datetime.timedelta(seconds=time_limit/2.0) self.cutoff = False WIN = sys.maxint - 1000 self.queue = PriorityQueue(len(possible_moves)) self.first = True while datetime.datetime.now() < time_cutoff and not self.cutoff and starting_node.empty_spaces >= depth: depth += 1 (new_move, new_score) = self.alpha_beta_wrapper(starting_node, depth, current_player, other_player) if new_move is not None and not self.cutoff: move = new_move score = new_score # print "Got to Depth:", depth # else: # print "Cutoff at depth", depth # print "Chose move: %s at depth: %s" % (move, depth) Logger.report_depth(depth) return move
def setup_headless_game(self): self.headless = True # player one, same as in game_state_logger.py self.now_playing = player.ComputerPlayer(color=BLACK, time_limit=self.timeout, headless=self.headless, strategy=randint(0,2)) # player two, same as in game_state_logger.py self.other_player = player.ComputerPlayer(color=WHITE, time_limit=self.timeout, headless=self.headless, strategy=randint(0,2)) self.board = board.Board() Logger.set_player_names([self.now_playing.name, self.other_player.name])
def setup_headless_game(self): self.headless = True # player one, same as in game_state_logger.py self.now_playing = player.RandomPlayer(color=BLACK, time_limit=self.timeout, headless=self.headless) # player two, same as in game_state_logger.py self.other_player = DeepLearningPlayer(color=WHITE, time_limit=self.timeout, headless=self.headless, epochs=0) # self.other_player = DeepLearningPlayer(color=WHITE, time_limit=self.timeout, headless=self.headless) self.board = board.Board() Logger.set_player_names( [self.now_playing.name, self.other_player.name])
def run(self, games=1): print "Game started: %s vs %s, time limit: %is" % (self.now_playing.name, self.other_player.name, self.timeout) if not self.headless: self.gui.show_game(self.board) while True: winner = self.board.game_won() if winner is not None: Logger.report_winner(winner) break self.now_playing.set_current_board(self.board) if self.board.get_valid_moves(self.now_playing.color) != []: self.board = self.now_playing.get_move() if not self.headless: self.gui.update(self.board, self.other_player) self.now_playing, self.other_player = self.other_player, self.now_playing if not self.headless: self.gui.show_winner(winner, self.board) self.restart(games - 1)
def apply_move(self, move): if not self.headless: self.gui.flash_move(move, self.color) self.current_board.apply_move(move, self.color) Logger.report(color=self.color, original_board=self.current_board)