Exemplo n.º 1
0
    def calculate_legal_moves(self, board):
        legal_moves = []
        piece_position = board.index(self)

        for current_offset in self.CANDIDATE_MOVE_COORDINATES:
            destination_coordinate = piece_position + (self.direction *
                                                       current_offset)
            if not is_valid_tile_coordinate(destination_coordinate):
                continue

            if current_offset == 8 and not self.is_tile_occupied(
                    board, destination_coordinate):
                # TODO: PAWN promotion square
                legal_moves.append(destination_coordinate)

            # # TODO: ADD first move check (maybe not needed because of row check)
            elif current_offset == 16 and \
                    (piece_is_in_given_row(piece_position, 6) and self.color == WHITE or
                     piece_is_in_given_row(piece_position, 1) and self.color == BLACK):
                behind_candidate_destination_coordinate = piece_position + (
                    self.direction * 8)
                if not self.is_tile_occupied(board, behind_candidate_destination_coordinate) and \
                    not self.is_tile_occupied(board, destination_coordinate):
                    legal_moves.append(destination_coordinate)

            elif current_offset == 7 and not \
                    (piece_is_in_given_column(piece_position, 7) and self.color == WHITE or
                     piece_is_in_given_column(piece_position, 0) and self.color == BLACK):
                if self.is_tile_occupied(board, destination_coordinate):
                    piece_on_candidate = board[destination_coordinate]
                    if self.color != piece_on_candidate.color:
                        # TODO: Add promotion square
                        legal_moves.append(destination_coordinate)

                # elif TODO: Add enpassantPawn

            elif current_offset == 9 and not \
                    (piece_is_in_given_column(piece_position, 0) and self.color == WHITE or
                     piece_is_in_given_column(piece_position, 7) and self.color == BLACK):
                if self.is_tile_occupied(board, destination_coordinate):
                    piece_on_candidate = board[destination_coordinate]
                    if self.color != piece_on_candidate.color:
                        # TODO: Add promotion square
                        legal_moves.append(destination_coordinate)
                # elif TODO: Add enpassantPawn

        return legal_moves
Exemplo n.º 2
0
 def __is_eight_column_exclusion(self, current_position, candidate_offset):
     return piece_is_in_given_column(
         current_position,
         7) and (candidate_offset == -15 or candidate_offset == -6
                 or candidate_offset == 10 or candidate_offset == 17)
Exemplo n.º 3
0
 def __is_seventh_column_exclusion(self, current_position,
                                   candidate_offset):
     return piece_is_in_given_column(current_position,
                                     6) and (candidate_offset == -6
                                             or candidate_offset == 10)
Exemplo n.º 4
0
 def __is_second_column_exclusion(self, current_position, candidate_offset):
     return piece_is_in_given_column(current_position,
                                     1) and (candidate_offset == -10
                                             or candidate_offset == 6)
Exemplo n.º 5
0
 def __is_first_column_exclusion(self, current_position, candidate_offset):
     return piece_is_in_given_column(
         current_position,
         0) and (candidate_offset == -17 or candidate_offset == -10
                 or candidate_offset == 6 or candidate_offset == 15)