Exemplo n.º 1
0
 def make_capture_1_move(self, curr_board, stone, point):
     curr_board = board(curr_board)
     updated_board = curr_board.place(stone, point)
     stones_to_remove = board(updated_board).get_no_liberties(get_opponent_stone(stone))
     if len(stones_to_remove) > 0:
         return True
     return False
Exemplo n.º 2
0
 def randomize_next_move(self, n, curr_board, stone, point, boards):
     if n == 1:
         return boards
     curr_board = board(curr_board)
     updated_board = curr_board.place(stone, point)
     new_boards = [updated_board] + boards[:min(2, len(boards))]
     opponent_random_move = self.next_player_move(stone, new_boards)
     if opponent_random_move == "pass":
         new_boards = [new_boards[0]] + [new_boards[0]] + [new_boards[1]]
     else:
         new_boards = [board(new_boards[0]).place(get_opponent_stone(stone), opponent_random_move)] + \
                      [new_boards[0]] + [new_boards[1]]
     point = self.make_a_move_dumb(new_boards)
     return self.randomize_next_move(n - 1, new_boards[0], stone, point, new_boards)
Exemplo n.º 3
0
    def ab_minimax(self, depth, max_depth, is_maximizer, alpha, beta, boards):
        curr_board = boards[0]
        if is_maximizer:
            legal_moves = get_legal_moves(boards, self.stone)
        else:
            legal_moves = get_legal_moves(boards,
                                          get_opponent_stone(self.stone))
        if (depth == max_depth) or (len(legal_moves) == 0):
            return [self.heuristic(curr_board),
                    "hello"]  # heuristic for game evaluation
        updated_board = curr_board
        if is_maximizer:
            max_eval = [alpha, None]
            for move in legal_moves:
                if move != "pass":
                    updated_board = board(curr_board).place(self.stone, move)
                updated_history = update_board_history(updated_board, boards)
                result = self.ab_minimax(depth + 1, max_depth,
                                         not is_maximizer, alpha, beta,
                                         updated_history)
                result[1] = move
                max_eval = max(max_eval, result, key=lambda x: x[0])
                alpha = max(alpha, result[0])
                if beta <= alpha:
                    break
            return max_eval

        else:
            min_eval = [beta, None]
            for move in legal_moves:
                if move != "pass":
                    updated_board = board(curr_board).place(self.stone, move)
                updated_history = update_board_history(updated_board, boards)
                result = self.ab_minimax(depth + 1, max_depth,
                                         not is_maximizer, alpha, beta,
                                         updated_history)
                result[1] = move
                min_eval = min(min_eval, result, key=lambda x: x[0])
                beta = min(beta, result[0])
                if beta <= alpha:
                    break
            return min_eval
Exemplo n.º 4
0
 def handle_move(self, input):
     self.game_output.append(self.board_history)
     if input == "pass":
         if self.pass_count == 1:
             self.game_output.append(self.get_winner())
             return False
         self.update_board_history(self.board_history[0])
         self.pass_count += 1
         self.swap_player()
         return True
     stone = self.current_player.stone
     move = [input, self.board_history]
     if rule_checker().check_validity(stone, move):
         new_board0 = board(self.board_history[0]).place(stone, input)
         new_board0 = board(new_board0).capture(get_opponent_stone(stone))
         self.update_board_history(new_board0)
         self.pass_count = 0
         self.swap_player()
         return True
     else:
         self.game_output.append(self.cheated())
         return False
Exemplo n.º 5
0
 def next_player_move(self, stone, new_boards):
     next_player = player(get_opponent_stone(stone))
     next_player.register_flag = True
     next_player.receive_flag = True
     return next_player.make_a_move_dumb(new_boards)