Ejemplo n.º 1
0
    def __init__(self, piece_positions=range(8), pawn_positions=range(8)):
        self.sideboard, self.passant_loc = [], tuple()
        self.player_turn, self.turn_count, self.draw_count, self.passant_count = 'White', 1.0, 0, 0.0
        self.checkmate, self.active_player_in_check, self.draw = False, False, False
        colour_generator = Utils.white_black()

        # Generate empty board
        self.squares = [[Pieces.Empty(next(colour_generator), location=(row, col)) for col in range(8)] for row in range(8)]

        # instantiate pieces
        for col in piece_positions:
            type_ = Globals.BACK_LINE[col]
            self.squares[0][col] = eval('Pieces.'+type_)('Black', self, (0, col))
            self.squares[7][col] = eval('Pieces.'+type_)('White', self, (7, col))
        for col in pawn_positions:
            self.squares[1][col] = Pieces.Pawn('Black', self, (1, col))
            self.squares[6][col] = Pieces.Pawn('White', self, (6, col))

        # initialise pieces
        self.update_pieces()
Ejemplo n.º 2
0
 def clear(self):
     """ remove all pieces from an already extant Board object
     """
     colour_generator = main.white_black()
     self.squares = [[Pieces.Empty(next(colour_generator), location=(row, col)) for col in range(8)] for row in range(8)]
Ejemplo n.º 3
0
 def wipe(self):
     for space in self.board:
         space = P.Empty()
Ejemplo n.º 4
0
W_ROOKS = [P.Rook(0, P.WHITE), P.Rook(5, P.WHITE)]
W_KNIGHTS = [P.Knight(1, P.WHITE), P.Knight(6, P.WHITE)]
W_BISHOPS = [P.Bishop(2, P.WHITE), P.Bishop(7, P.WHITE)]
W_QUEEN = P.Queen(3, P.WHITE)
W_KING = P.King(4, P.WHITE)
W_PAWNS = []

B_ROOKS = [P.Rook(8, P.BLACK), P.Rook(13, P.BLACK)]
B_KNIGHTS = [P.Knight(9, P.BLACK), P.Knight(14, P.BLACK)]
B_BISHOPS = [P.Bishop(10, P.BLACK), P.Bishop(15, P.BLACK)]
B_QUEEN = P.Queen(11, P.BLACK)
B_KING = P.King(12, P.BLACK)
B_PAWNS = []

EMPTY = P.Empty()

for i in range(0, 8):
    W_PAWNS.append(P.Pawn(16 + i, P.WHITE))
    B_PAWNS.append(P.Pawn(24 + i, P.BLACK))


class Board():
    def __init__(self, blank=False):
        self.board = [
        ]  # The game's current state, represented as a 2d array of Piece and Empty objects
        self.unmoved = list(range(
            0, 32))  # The ids of all pieces that haven't moved
        self.whiteChecked = False  # True when white's king is in check
        self.blackChecked = False  # True when black's king is in check
        self.turn = P.WHITE