示例#1
0
    def beta_play(self, board_history):
        # work in progress
        current_board = board_history[0]
        opponent_point = MaybeStone.flip_stone(self.stone)
        all_opponent_connections = []
        for point in Board.get_points(current_board, opponent_point):
            all_opponent_connections.append(get_blob(current_board, point))

        all_opponent_liberties = []
        for connection in all_opponent_connections:
            all_opponent_liberties.append(
                get_blob_liberties(current_board, connection))

        connections_with_one_liberty = set()
        for liberties_set in all_opponent_liberties:
            if len(liberties_set) == 1:
                connections_with_one_liberty.union(liberties_set)

        for row, maybe_stones in enumerate(current_board):
            for column, maybe_stone in enumerate(current_board):
                if (column, row) in connections_with_one_liberty:
                    try:
                        RuleChecker.check_move(self.stone, (column, row),
                                               board_history)
                        return Point.point_to_string((column, row))
                    except IllegalMoveError:
                        pass
                    except ImproperHistoryError as e:
                        # raise PlayerCommandError('Invalid history') from e
                        return 'This history makes no sense!'

        return 'pass'
示例#2
0
文件: referee.py 项目: zbash75/Go
    def execute_turn(self, action):
        # Check for double pass
        if action == "pass":
            if not self.last_turn_was_pass:
                self.last_turn_was_pass = True
                self._update_history(self.board_hist[0])
                return deepcopy(self.board_hist)

            elif self.last_turn_was_pass:
                return self.end_game()

        elif action == "GO has gone crazy!" or action == "This history makes no sense!":
            if self.current_turn == "B":
                return self.end_game(self.black_player)
            else:
                return self.end_game(self.white_player)

        else:
            self.last_turn_was_pass = False
            action = Point.string_to_point(action)
            try:
                new_board = RuleChecker.check_move(self.current_turn, action,
                                                   self.board_hist)

                self._update_history(new_board)

                return deepcopy(self.board_hist)

            except RuleCheckerError as e:
                if self.current_turn == "B":
                    return self.end_game(self.black_player)
                else:
                    return self.end_game(self.white_player)
示例#3
0
    def dumb_play(self, board_history):
        if self.stone == None:
            raise PlayerCommandError(
                'You need to set the stone before you can play.')

        current_board = board_history[0]
        for column, maybe_stones in enumerate(current_board):
            for row, maybe_stone in enumerate(current_board):
                try:
                    RuleChecker.check_move(self.stone, (column, row),
                                           board_history)
                    return Point.point_to_string((column, row))
                except IllegalMoveError:
                    pass
                except ImproperHistoryError as e:
                    # raise PlayerCommandError('Invalid history') from e
                    return 'This history makes no sense!'

        return 'pass'
示例#4
0
    def n1play(self, board_history):
        if self.stone == None:
            raise PlayerCommandError(
                'You need to set the stone before you can play.')

        current_board = copy.deepcopy(board_history[0])
        opponent_point = MaybeStone.flip_stone(self.stone)

        for column_index in range(MAX_COLUMN):
            for row_index in range(MAX_ROW):
                if self.check_for_adjacent_stones(opponent_point,
                                                  (column_index, row_index),
                                                  current_board):
                    try:
                        # Try putting a stone in the current position
                        new_board = RuleChecker.check_move(
                            self.stone, (column_index, row_index),
                            board_history)
                        try:
                            Board.place(current_board, self.stone,
                                        (column_index, row_index))
                            # See if capture occurred by comparing with just placing
                            if current_board != new_board:
                                return Point.point_to_string(
                                    (column_index, row_index))
                            else:
                                Board.remove(current_board, self.stone,
                                             (column_index, row_index))
                        except BoardStateError as e:
                            pass
                    except IllegalMoveError as e:
                        pass
                    except ImproperHistoryError as e:
                        # raise PlayerCommandError('Invalid history') from e
                        return 'This history makes no sense!'

        return self.dumb_play(board_history)