def get_input(self, go: Game, piece_type): self.load_dict() # print(board.n_move) # go.visualize_board() if go.count_player_stones(piece_type) <= 0: self.side = piece_type self.opponent = 1 if self.side == 2 else 2 self.cache = {} open("cache.txt", "w").close() if go.is_position_valid(2, 2, self.side, True): copy_board = copy.deepcopy(go) copy_board.next_board(2, 2, self.side, True) # print("Minimax: piece_type = {}".format(self.side), \ # "current board value = {}".format(self.total_score(copy_board, self.side))) return 2, 2 if go.is_game_finished(): return else: # score, action = self._max(board) depth = DEPTH if go.n_move > 18: depth = 24 - go.n_move elif go.n_move < 8: # return aggressive_action(go, piece_type) depth = 1 action = self.alpha_beta_cutoff_search(go, depth) copy_board = copy.deepcopy(go) if action != "PASS": # print(action) copy_board.next_board(action[0], action[1], self.side, True) # print("Minimax: piece_type = {}".format(self.side), \ # "current board value = {}".format(self.total_score(copy_board, self.side))) self.save_dict() return action # board.move(action[0], action[1], self.side)
def get_input(self, board: Game, piece_type): if board.count_player_stones(piece_type) <= 0: self.side = piece_type self.opponent = 1 if self.side == 2 else 2 if board.is_position_valid(2, 2, self.side, True): copy_board = copy.deepcopy(board) copy_board.next_board(2, 2, self.side, True) # print("Minimax_old: piece_type = {}".format(self.side), \ # "current board value = {}".format(self.total_score(copy_board, self.side))) return 2, 2 if board.is_game_finished(): return else: # score, action = self._max(board) action = self.alpha_beta_cutoff_search(board, DEPTH) if action != "PASS": copy_board = copy.deepcopy(board) copy_board.next_board(action[0], action[1], self.side, True) # print("Minimax_old: piece_type = {}".format(self.side), \ # "current board value = {}".format(self.total_score(copy_board, self.side))) return action # board.move(action[0], action[1], self.side)