Exemplo n.º 1
0
    def __init__(self, textmode=False):
        self.textmode = textmode
        self.pieces.append(Pieces.Rook(self.BLACK))
        self.pieces.append(Pieces.Knight(self.BLACK))
        self.pieces.append(Pieces.Bishop(self.BLACK))
        self.pieces.append(Pieces.Queen(self.BLACK))
        self.pieces.append(Pieces.King(self.BLACK))
        self.pieces.append(Pieces.Bishop(self.BLACK))
        self.pieces.append(Pieces.Knight(self.BLACK))
        self.pieces.append(Pieces.Rook(self.BLACK))

        for i in range(9, 17):
            self.pieces.append(Pieces.Pawn(self.BLACK))

        for i in range(17, 65 - 16):
            self.pieces.append(None)

        for i in range(65 - 16, 65 - 8):
            self.pieces.append(Pieces.Pawn(self.WHITE))

        self.pieces.append(Pieces.Rook(self.WHITE))
        self.pieces.append(Pieces.Knight(self.WHITE))
        self.pieces.append(Pieces.Bishop(self.WHITE))
        self.pieces.append(Pieces.Queen(self.WHITE))
        self.pieces.append(Pieces.King(self.WHITE))
        self.pieces.append(Pieces.Bishop(self.WHITE))
        self.pieces.append(Pieces.Knight(self.WHITE))
        self.pieces.append(Pieces.Rook(self.WHITE))
Exemplo n.º 2
0
    def __init__(self, grid, screen):
        # White
        grid[0][0] = Pieces.Rook("White", 0, 0, screen)
        grid[0][7] = Pieces.Rook("White", 0, 7, screen)

        grid[0][1] = Pieces.Knight("White", 0, 1, screen)
        grid[0][6] = Pieces.Knight("White", 0, 6, screen)

        grid[0][2] = Pieces.Bishop("White", 0, 2, screen)
        grid[0][5] = Pieces.Bishop("White", 0, 5, screen)

        grid[0][4] = Pieces.Queen("White", 0, 4, screen)
        grid[0][3] = Pieces.King("White", 0, 3, screen)
        for x in range(8):
            grid[1][x] = Pieces.Pawn("White", 1, x, screen)

        # Black changes in some comments
        grid[7][0] = Pieces.Rook("Black", 7, 0, screen)
        grid[7][7] = Pieces.Rook("Black", 7, 7, screen)

        grid[7][1] = Pieces.Knight("Black", 7, 1, screen)
        grid[7][6] = Pieces.Knight("Black", 7, 6, screen)

        grid[7][2] = Pieces.Bishop("Black", 7, 2, screen)
        grid[7][5] = Pieces.Bishop("Black", 7, 5, screen)

        grid[7][4] = Pieces.Queen("Black", 7, 4, screen)
        grid[7][3] = Pieces.King("Black", 7, 3, screen)
        for y in range(8):
            grid[6][y] = Pieces.Pawn("Black", 6, y, screen)
        self.grid = grid
        return
Exemplo n.º 3
0
 def readyToPlay(self):
     board = [
         [
             Pieces.Rook(Color.WHITE, self),
             Pieces.Knight(Color.WHITE, self),
             Pieces.Bishop(Color.WHITE, self),
             Pieces.King(Color.WHITE, self),
             Pieces.Queen(Color.WHITE, self),
             Pieces.Bishop(Color.WHITE, self),
             Pieces.Knight(Color.WHITE, self),
             Pieces.Rook(Color.WHITE, self),
         ],
         [Pieces.Pawn(Color.WHITE, self) for i in range(8)],
         [PieceName.NONE for i in range(8)],
         [PieceName.NONE for i in range(8)],
         [PieceName.NONE for i in range(8)],
         [PieceName.NONE for i in range(8)],
         [Pieces.Pawn(Color.BLACK, self) for i in range(8)],
         [
             Pieces.Rook(Color.BLACK, self),
             Pieces.Knight(Color.BLACK, self),
             Pieces.Bishop(Color.BLACK, self),
             Pieces.King(Color.BLACK, self),
             Pieces.Queen(Color.BLACK, self),
             Pieces.Bishop(Color.BLACK, self),
             Pieces.Knight(Color.BLACK, self),
             Pieces.Rook(Color.BLACK, self),
         ],
     ]
     for i in range(8):
         for j in range(8):
             self.__playboard[i][j].piece_setter(board[i][j])
     return
Exemplo n.º 4
0
    def setup_initial_pieces(self):
        for [row, colour] in [[0, "BLACK"], [7, "WHITE"]]:
            self.board[row][0] = pcs.Rook(colour)
            self.board[row][1] = pcs.Knight(colour)
            self.board[row][2] = pcs.Bishop(colour)
            self.board[row][5] = pcs.Bishop(colour)
            self.board[row][6] = pcs.Knight(colour)
            self.board[row][7] = pcs.Rook(colour)
            for column in range(8):
                if colour == "BLACK":
                    self.board[row + 1][column] = pcs.Pawn(colour)
                else:
                    self.board[row - 1][column] = pcs.Pawn(colour)
            #temp
            self.board[row][0].update_role(roles.BasicRole())
            self.board[row][1].update_role(roles.BasicRole())
            self.board[row][2].update_role(roles.BasicRole())
            self.board[row][5].update_role(roles.BasicRole())
            self.board[row][6].update_role(roles.BasicRole())
            self.board[row][7].update_role(roles.BasicRole())

        self.board[0][3] = pcs.Queen("BLACK")
        self.board[0][4] = pcs.King("BLACK")
        self.board[7][3] = pcs.King("WHITE")
        self.board[7][4] = pcs.Queen("WHITE")

        #temp
        self.board[0][3].update_role(roles.BasicRole())
        self.board[0][4].update_role(roles.BasicRole())
        self.board[7][3].update_role(roles.BasicRole())
        self.board[7][4].update_role(roles.BasicRole())
Exemplo n.º 5
0
def init(color):

    #intialization of board based on the color
    if color.lower() == "white":
        board[0][0] = Pieces.Rook("Black")
        board[0][1] = Pieces.Knight("Black")
        board[0][2] = Pieces.Bishop("Black")
        board[0][3] = Pieces.Queen("Black")
        board[0][4] = Pieces.King("Black")
        board[0][5] = Pieces.Bishop("Black")
        board[0][6] = Pieces.Knight("Black")
        board[0][7] = Pieces.Rook("Black")

        for x in range(8):
            board[1][x] = Pieces.Pawn("Black")

        board[7][0] = Pieces.Rook("White")
        board[7][1] = Pieces.Knight("White")
        board[7][2] = Pieces.Bishop("White")
        board[7][3] = Pieces.Queen("White")
        board[7][4] = Pieces.King("White")
        board[7][5] = Pieces.Bishop("White")
        board[7][6] = Pieces.Knight("White")
        board[7][7] = Pieces.Rook("White")

        for x in range(8):
            board[6][x] = Pieces.Pawn("White")

    else:
        board[0][0] = Pieces.Rook("White")
        board[0][1] = Pieces.Knight("White")
        board[0][2] = Pieces.Bishop("White")
        board[0][3] = Pieces.King("White")
        board[0][4] = Pieces.Queen("White")
        board[0][5] = Pieces.Bishop("White")
        board[0][6] = Pieces.Knight("White")
        board[0][7] = Pieces.Rook("White")

        for x in range(8):
            board[1][x] = Pieces.Pawn("White")

        board[7][0] = Pieces.Rook("Black")
        board[7][1] = Pieces.Knight("Black")
        board[7][2] = Pieces.Bishop("Black")
        board[7][3] = Pieces.King("Black")
        board[7][4] = Pieces.Queen("Black")
        board[7][5] = Pieces.Bishop("Black")
        board[7][6] = Pieces.Knight("Black")
        board[7][7] = Pieces.Rook("Black")

        for x in range(8):
            board[6][x] = Pieces.Pawn("Black")
Exemplo n.º 6
0
    def return_positions(self, piece, game):
        move_able = []
        cur_row, cur_col = game.get_piece_pos(piece)
        # Refer to get_direction_of for understanding of the code statement below
        for quadrant in range(self.quadrant_corners):
            y_dir = self.get_direction_of(quadrant, self.COL_INDEX)

            if piece.get_piece_name() == Pieces.Pawn().get_piece_name():
                piece_direction = game.get_piece_directions()[
                    piece.get_color()]
                if piece_direction != y_dir:
                    continue

            elif piece.get_piece_name() == Pieces.King().get_piece_name():
                if not piece.is_moved():  # Haven't Moved
                    pass

            for distance in range(1, self.max_distance + 1):
                new_row = cur_row + distance * y_dir
                if self.is_movable(game, piece, new_row, cur_col):
                    # Will King be threaten
                    move_able.append([new_row, cur_col])
                    if game.get_space(*move_able[-1]):
                        break
                else:
                    break
        return move_able
 def init_board(self):
     piece_dict = {
         "P":
         lambda row, col, board, color: p.Pawn(row, col, board, color, self.
                                               special_move_mem),
         "N":
         lambda row, col, board, color: p.Knight(row, col, board, color),
         "B":
         lambda row, col, board, color: p.Bishop(row, col, board, color),
         "Q":
         lambda row, col, board, color: p.Queen(row, col, board, color),
         "K":
         lambda row, col, board, color: p.King(row, col, board, color),
         "R":
         lambda row, col, board, color: p.Rook(row, col, board, color),
     }
     for row in range(0, 8):
         for col in range(0, 8):
             piece = self.string_board[row][col]
             if piece != "..":
                 piece_color = piece[0]
                 if piece_color == 'b':
                     piece_color = "black"
                 else:
                     piece_color = "white"
                 piece_type = piece[1]
                 self.string_board[row][col] = piece_dict[piece_type](
                     row, col, self.string_board, piece_color)
                 if piece_color == "black":
                     self.black_playable_pieces.append(
                         self.string_board[row][col])
                 else:
                     self.white_playable_pieces.append(
                         self.string_board[row][col])
     return self.string_board
Exemplo n.º 8
0
 def __init__(self):
     super(Chess,
           self).__init__(600,
                          600,
                          resizable=False,
                          caption='Chess',
                          config=pyglet.gl.Config(double_buffer=True),
                          vsync=False)
     self.wKing = p.King(4, 0)
     self.bKing = p.King(4, 7, False)
     self.board = [[
         p.Rook(0, 0),
         p.Knight(1, 0),
         p.Bishop(2, 0),
         p.Queen(3, 0), self.wKing,
         p.Bishop(5, 0),
         p.Knight(6, 0),
         p.Rook(7, 0)
     ], [p.Pawn(i, 1) for i in range(8)], [None for i in range(8)],
                   [None for i in range(8)], [None for i in range(8)],
                   [None for i in range(8)],
                   [p.Pawn(i, 6, False) for i in range(8)],
                   [
                       p.Rook(0, 7, False),
                       p.Knight(1, 7, False),
                       p.Bishop(2, 7, False),
                       p.Queen(3, 7, False), self.bKing,
                       p.Bishop(5, 7, False),
                       p.Knight(6, 7, False),
                       p.Rook(7, 7, False)
                   ]]
     self.validsprites = []
     for i in range(8):
         rowsprites = []
         for j in range(8):
             sprite = pyglet.sprite.Sprite(self.validImg, 75 * j, 75 * i)
             sprite.visible = False
             rowsprites.append(sprite)
         self.validsprites.append(rowsprites)
     self.wQueen = pyglet.sprite.Sprite(self.spritesheet[7], 131.25, 225)
     self.wRook = pyglet.sprite.Sprite(self.spritesheet[10], 218.75, 225)
     self.wBishop = pyglet.sprite.Sprite(self.spritesheet[8], 306.25, 225)
     self.wKnight = pyglet.sprite.Sprite(self.spritesheet[9], 393.75, 225)
     self.bQueen = pyglet.sprite.Sprite(self.spritesheet[1], 131.25, 225)
     self.bRook = pyglet.sprite.Sprite(self.spritesheet[4], 218.75, 225)
     self.bBishop = pyglet.sprite.Sprite(self.spritesheet[2], 306.25, 225)
     self.bKnight = pyglet.sprite.Sprite(self.spritesheet[3], 393.75, 225)
Exemplo n.º 9
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()
Exemplo n.º 10
0
 def is_movable(self, board, piece, new_row, new_col):
     space = board.get_space(new_row, new_col)
     piece_type = piece.get_piece_name()
     if not board.is_on_board(new_row, new_col):
         return False
     elif space and space.get_color() == piece.get_color(
     ):  # Runs into same colored piece
         return False
     elif Pieces.Pawn().get_piece_name() == piece_type:
         return self.is_valid_pawn_move(board, piece, new_row, new_col,
                                        self)
     # Other
     return True
Exemplo n.º 11
0
 def retractMove(self):
     if len(self.movesMade) == 0:
         return
     [move, piece] = self.movesMade.pop()
     fr, to = move.unpack()
     self.pieces[fr] = self.pieces[to]
     # Put captured piece back in the correct place in case of en passant
     if self.madeEnPassant[-1]:
         capturedPieceCol = move.to[1]
         # Offset is -1 for black, +1 for white
         if self.pieces[fr].colour == self.WHITE:
             offset = +1
         else:
             offset = -1
         capturedPieceRow = move.to[0] + offset
         self.pieces[capturedPieceRow * 8 +
                     capturedPieceCol] = Pieces.Pawn(1 -
                                                     self.pieces[fr].colour)
     else:
         self.pieces[to] = piece
     if isinstance(move, Move.PromotionMove):
         self.pieces[fr] = Pieces.Pawn(self.pieces[fr].colour)
     self.doublePawnPush.pop()
     self.madeEnPassant.pop()
Exemplo n.º 12
0
    def create_pieces(self):
        # Kings
        self.pieces['white'].append(Pieces.King(True, (4, 0)))
        self.pieces['black'].append(Pieces.King(False, (4, 7)))

        # Pawns
        for x in range(8):
            self.pieces['white'].append(Pieces.Pawn(True, (x, 1)))
            #self.pieces['black'].append(Pieces.Pawn(False, (x, 6)))

        # White Pieces
        # TODO: Move List
        # TODO: Win Screen
        # TODO: Resign and draw
        # TODO: Clock
        #self.pieces['white'].append(Pieces.Knight(True, (1, 0)))
        #self.pieces['white'].append(Pieces.Knight(True, (6, 0)))
        #self.pieces['white'].append(Pieces.Bishop(True, (2, 0)))
        self.pieces['white'].append(Pieces.Bishop(True, (5, 0)))
        self.pieces['white'].append(Pieces.Rook(True, (0, 0)))
        #self.pieces['white'].append(Pieces.Rook(True, (7, 0)))
        self.pieces['white'].append(Pieces.Queen(True, (3, 0)))

        # Black Pieces
        #self.pieces['black'].append(Pieces.Knight(False, (1, 7)))
        #self.pieces['black'].append(Pieces.Knight(False, (6, 7)))
        #self.pieces['black'].append(Pieces.Bishop(False, (2, 7)))
        self.pieces['black'].append(Pieces.Bishop(False, (5, 7)))
        #self.pieces['black'].append(Pieces.Rook(False, (0, 7)))
        self.pieces['black'].append(Pieces.Rook(False, (7, 7)))
        self.pieces['black'].append(Pieces.Queen(False, (3, 7)))

        # TODO: Move this to end of turn
        # Show pieces
        for x in self.pieces['white']:
            self.pieces_grid[x.pos] = x
            self.labels[x.pos[0]][x.pos[1]].config(text=' ' + x.display + ' ',
                                                   fg='silver')
        for x in self.pieces['black']:
            self.pieces_grid[x.pos] = x
            self.labels[x.pos[0]][x.pos[1]].config(text=' ' + x.display + ' ',
                                                   fg='brown')
Exemplo n.º 13
0
 def return_positions(self, piece, game):
     move_able = []
     cur_row, cur_col = game.get_piece_pos(piece)
     # Refer to get_direction_of for understanding of the code statement below
     for quadrant in range(self.quadrant_corners):
         row_dir, col_dir = self.get_direction_of(
             quadrant,
             self.ROW_INDEX), self.get_direction_of(quadrant,
                                                    self.COL_INDEX)
         for distance in range(1, self.max_distance + 1):
             new_row, new_col = cur_row + distance * col_dir, cur_col + distance * row_dir
             if self.is_movable(game, piece, new_row, new_col):
                 # Will King be threaten
                 if piece.get_piece_name() == Pieces.Pawn().get_piece_name(
                 ):
                     if not self.is_valid_pawn_move(game, piece, new_row,
                                                    new_col, self):
                         break
                 move_able.append([new_row, new_col])
                 if game.get_space(*move_able[-1]):
                     break
             else:
                 break
     return move_able
Exemplo n.º 14
0
testCase3 = B.Board()
testCase3 = Logic.move_piece(testCase3, 4, 1, P.Move((4, 3), P.NON_CAPTURE))
testCase3 = Logic.move_piece(testCase3, 0, 6, P.Move((0, 4), P.NON_CAPTURE))
testCase3 = Logic.move_piece(testCase3, 3, 0, P.Move((5, 2)))
testCase3 = Logic.move_piece(testCase3, 1, 6, P.Move((1, 4), P.NON_CAPTURE))
testCase3 = Logic.move_piece(testCase3, 5, 0, P.Move((2, 3)))
testCase3 = Logic.move_piece(testCase3, 1, 4, P.Move((1, 3), P.NON_CAPTURE))
testCase3 = Logic.move_piece(testCase3, 5, 2, P.Move((5, 6)))

testCase4 = B.Board(True)
testCase4.board[0][0] = P.King(testCase4.whiteKingId, P.WHITE)
testCase4.board[1][0] = P.Rook(100, P.WHITE)
testCase4.board[2][0] = P.Rook(101, P.WHITE)
testCase4.board[2][1] = P.Queen(102, P.BLACK)
testCase4.board[7][1] = P.Pawn(103, P.WHITE)
testCase4.board[0][2] = P.Pawn(104, P.WHITE)
testCase4.board[1][2] = P.Knight(105, P.BLACK)
testCase4.board[2][3] = P.Knight(106, P.BLACK)
testCase4.board[4][5] = P.Pawn(107, P.BLACK)
testCase4.board[1][6] = P.Pawn(108, P.BLACK)
testCase4.board[6][6] = P.Pawn(109, P.BLACK)
testCase4.board[7][6] = P.Pawn(110, P.BLACK)
testCase4.board[2][7] = P.Bishop(111, P.BLACK)
testCase4.board[3][7] = P.Rook(112, P.BLACK)
testCase4.board[6][7] = P.King(testCase4.blackKingId, P.BLACK)
testCase4.unmoved = [103, 108, 109, 110, 111]
testCase4.initializePosVals()


@pytest.mark.parametrize("b,color,expectedAnswer",
Exemplo n.º 15
0
    def undo_move(self, is_test=False):

        if len(self.move_log) >= 1:
            undo = self.move_log.pop()
            piece_moved = undo.piece_moved
            piece_captured = undo.piece_captured
            self.board[undo.start_row][undo.start_col] = piece_moved
            self.change_cords(piece_moved, undo.start_row, undo.start_col,
                              False)
            self.board[undo.end_row][undo.end_col] = piece_captured

            if piece_captured != "..":
                self.change_cords(piece_captured, undo.end_row, undo.end_col,
                                  False)
                if piece_captured.color == "black":
                    self.black_playable_pieces.append(piece_captured)
                else:
                    self.white_playable_pieces.append(piece_captured)

            if len(self.move_log) == 0:
                self.is_first_move = True

            if not is_test:
                self.white_to_move = not self.white_to_move
                self.redo_move_log.append(undo)

            # update pawn promotion move
            if undo.is_pawn_promotion:
                replacement_piece = p.Pawn(undo.start_row, undo.start_col,
                                           self.board, piece_moved.color,
                                           self.special_move_mem)
                self.board[undo.start_row][undo.start_col] = replacement_piece
                # adding the pawn to the pieces on the board
                if replacement_piece.color == "white":
                    self.white_playable_pieces.append(replacement_piece)
                    self.white_playable_pieces.remove(piece_moved)
                else:
                    self.black_playable_pieces.append(replacement_piece)
                    self.white_playable_pieces.remove(piece_moved)
                # removing the queen from the board
                self.change_cords(piece_moved, 8, 8, True)

            # update en_passnt move
            if undo.is_enpassant:
                self.board[undo.end_row][undo.end_col] = ".."
                self.board[undo.start_row][undo.end_col] = undo.piece_captured
                self.change_cords(piece_captured, undo.start_row, undo.end_col,
                                  False)

            # # update castling move
            # if undo.is_castle:
            #     if undo.end_col - undo.start_col == 2: #kingside castle
            #         old_rook = self.board[undo.end_row][undo.end_col - 1]
            #         new_rook = p.Rook(undo.start_row, undo.end_col+1, self.board, piece_moved.color)
            #         if old_rook.color == "black":
            #             self.black_playable_pieces.remove(old_rook)
            #             self.black_playable_pieces.append(new_rook)
            #         else:
            #             self.white_playable_pieces.remove(old_rook)
            #             self.white_playable_pieces.append(new_rook)

            #         self.change_cords(old_rook, 8, 8, True)
            #         self.board[undo.end_row][undo.end_col-1] = ".."
            #         self.board[undo.end_row][undo.end_col+1] = new_rook

            #     elif undo.start_col - undo.end_col == 2: # queenside castle
            #         old_rook = self.board[undo.end_row][undo.end_col+1]
            #         new_rook = p.Rook(undo.end_row, undo.start_col -4, self.board, piece_moved.color)
            #         if old_rook.color == "black":
            #             self.black_playable_pieces.remove(old_rook)
            #             self.black_playable_pieces.append(new_rook)
            #         else:
            #             self.white_playable_pieces.remove(old_rook)
            #             self.white_playable_pieces.append(new_rook)

            #         self.change_cords(old_rook, 8, 8, True)
            #         self.board[undo.end_row][undo.end_col+1] = ".."
            #         self.board[undo.end_row][undo.start_col-4] = new_rook

            #undo castle log

            self.castling_log.pop()
            self.current_castle_state.white_kingside = self.castling_log[
                -1].white_kingside
            self.current_castle_state.white_queenside = self.castling_log[
                -1].white_queenside
            self.current_castle_state.black_kingside = self.castling_log[
                -1].black_kingside
            self.current_castle_state.black_queenside = self.castling_log[
                -1].black_queenside
            self.checkmate = False
            self.stalemate = False
Exemplo n.º 16
0
                moves2.remove(move2)
                found = True
                break
        
        if not found:
            break
    
    return len(moves2) == 0

board = B.Board(True)


"""------------PAWN TESTS----------"""

pawnStart = deepcopy(board)
pawnStart.board[1][1] = P.Pawn(0, P.WHITE)

pawnStartBlocked1 = deepcopy(pawnStart)
pawnStartBlocked1.board[1][2] = P.Pawn(1, P.BLACK)
pawnStartBlocked1.unmoved.remove(1)

pawnStartBlocked2 = deepcopy(pawnStart)
pawnStartBlocked2.board[1][3] = P.Pawn(1, P.BLACK)
pawnStartBlocked2.unmoved.remove(1)

pawnCaptureAndPassent = deepcopy(board)
pawnCaptureAndPassent.board[4][4] = P.Pawn(0, P.WHITE)
pawnCaptureAndPassent.board[3][4] = P.Pawn(1, P.BLACK)
pawnCaptureAndPassent.board[5][5] = P.Pawn(2, P.BLACK)
pawnCaptureAndPassent.passentable = (3, 4)
pawnCaptureAndPassent.unmoved.remove(0)
Exemplo n.º 17
0
unknownError = B.Board()
unknownError = Logic.move_piece(unknownError, 4, 1,
                                P.Move((4, 3), P.NON_CAPTURE))
unknownError = Logic.move_piece(unknownError, 6, 6,
                                P.Move((6, 4), P.NON_CAPTURE))
unknownError = Logic.move_piece(unknownError, 3, 0, P.Move((5, 2)))
unknownError = Logic.move_piece(unknownError, 5, 7, P.Move((6, 6)))
unknownError = Logic.move_piece(unknownError, 5, 0, P.Move((2, 3)))
unknownError = Logic.move_piece(unknownError, 0, 6,
                                P.Move((0, 4), P.NON_CAPTURE))
unknownError = Logic.move_piece(unknownError, 5, 2, P.Move((5, 6)))
unknownError.initializePosVals()

crash = B.Board(True)
crash.board[5][0] = P.Bishop(100, P.WHITE)
crash.board[2][1] = P.Pawn(101, P.WHITE)
crash.board[4][1] = P.Pawn(102, P.WHITE)
crash.board[5][1] = P.King(crash.whiteKingId, P.WHITE)
crash.board[0][2] = P.Pawn(103, P.WHITE)
crash.board[2][2] = P.Pawn(104, P.WHITE)
crash.board[5][2] = P.Knight(105, P.WHITE)
crash.board[2][3] = P.Bishop(106, P.BLACK)
crash.board[3][3] = P.Rook(107, P.WHITE)
crash.board[4][3] = P.King(crash.blackKingId, P.BLACK)
crash.board[6][3] = P.Pawn(108, P.WHITE)
crash.board[0][4] = P.Pawn(109, P.BLACK)
crash.board[1][4] = P.Pawn(110, P.BLACK)
crash.board[6][4] = P.Pawn(111, P.WHITE)
crash.board[0][7] = P.Rook(112, P.BLACK)
crash.board[1][7] = P.Knight(113, P.BLACK)
crash.board[2][7] = P.Rook(114, P.WHITE)
Exemplo n.º 18
0
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
        self.whiteKingId = 4
        self.blackKingId = 12
        self.whiteTotalPieceVal = 0
Exemplo n.º 19
0
def gen_pawns(board: Board, wk, bk):
    for i in range(board.size):
        board.white_pieces.add(Pieces.Pawn(
            board, board.get_square((i, board.size - 2)), white, wk))
        board.black_pieces.add(Pieces.Pawn(
            board, board.get_square((i, 1)), black, bk))
Exemplo n.º 20
0
import Pieces, Player, TheChessEngine

gameBoard = TheChessEngine.ChessBoard()

# white pawns

wp1 = Pieces.Pawn(input('please input a name for white Pawn #' + str(Pawn.white_piece_index + 1) + ': '),
           team=Colors.WHITE,
           location=(0, 1))
wp2 = Pawn(input('please input a name for white Pawn #' + str(Pawn.white_piece_index + 1) + ': '),
           team=Colors.WHITE,
           location=(1, 1))
wp3 = Pawn(input('please input a name for white Pawn #' + str(Pawn.white_piece_index + 1) + ': '),
           team=Colors.WHITE,
           location=(2, 1))
wp4 = Pawn(input('please input a name for white Pawn #' + str(Pawn.white_piece_index + 1) + ': '),
           team=Colors.WHITE,
           location=(3, 1))
wp5 = Pawn(input('please input a name for white Pawn #' + str(Pawn.white_piece_index + 1) + ': '),
           team=Colors.WHITE,
           location=(4, 1))
wp6 = Pawn(input('please input a name for white Pawn #' + str(Pawn.white_piece_index + 1) + ': '),
           team=Colors.WHITE,
           location=(5, 1))
wp7 = Pawn(input('please input a name for white Pawn #' + str(Pawn.white_piece_index + 1) + ': '),
           team=Colors.WHITE,
           location=(6, 1))
wp8 = Pawn(input('please input a name for white Pawn #' + str(Pawn.white_piece_index + 1) + ': '),
           team=Colors.WHITE,
           location=(7, 1))