Exemplo n.º 1
0
    def init_board(self):
        new_b = []
        for i in range(64):
            # white
            if i == 0 or i == 7:
                new_b.append(Tile(Rook('W')))
            elif i == 1 or i == 6:
                new_b.append(Tile(Knight('W')))
            elif i == 2 or i == 5:
                new_b.append(Tile(Bishop('W')))
            elif i == 3:
                new_b.append(Tile(Queen('W')))
            elif i == 4:
                new_b.append(Tile(King('W')))
            elif i >= 8 and i <= 15:
                new_b.append(Tile(Pawn('W')))
            # black
            elif i == 56 or i == 63:
                new_b.append(Tile(Rook('B')))
            elif i == 57 or i == 62:
                new_b.append(Tile(Knight('B')))
            elif i == 58 or i == 61:
                new_b.append(Tile(Bishop('B')))
            elif i == 59:
                new_b.append(Tile(Queen('B')))
            elif i == 60:
                new_b.append(Tile(King('B')))
            elif i >= 48 and i <= 55:
                new_b.append(Tile(Pawn('B')))
            # empty
            else:
                new_b.append(Tile())

        return new_b
Exemplo n.º 2
0
    def fill_board(self):
        for key in self.__letter_mapping:
            self[key + '7'] = Pawn(BLACK, self)
            self[key + '2'] = Pawn(WHITE, self)

        self['A1'] = Rook(WHITE, self)
        self['H1'] = Rook(WHITE, self)
        self['A8'] = Rook(BLACK, self)
        self['H8'] = Rook(BLACK, self)

        self['B1'] = Knight(WHITE, self)
        self['G1'] = Knight(WHITE, self)
        self['B8'] = Knight(BLACK, self)
        self['G8'] = Knight(BLACK, self)

        self['C1'] = Bishop(WHITE, self)
        self['F1'] = Bishop(WHITE, self)
        self['C8'] = Bishop(BLACK, self)
        self['F8'] = Bishop(BLACK, self)

        self['D1'] = Queen(WHITE, self)
        self['D8'] = Queen(BLACK, self)

        self['E1'] = King(WHITE, self)
        self['E8'] = King(BLACK, self)
Exemplo n.º 3
0
 def test_bishop_attacks(self):
     bishop1 = Bishop(Colour.WHITE, (3, 3))
     pawn1 = Pawn(Colour.WHITE, (2, 2))
     pawn2 = Pawn(Colour.BLACK, (4, 4))
     pawn3 = Pawn(Colour.BLACK, (5, 5))
     self.assertEquals(set(bishop1.list_attacks([pawn1, pawn2, pawn3])),
                       set([((4, 4))]))
Exemplo n.º 4
0
    def add_pieces(self):
        """ Appends the proper pieces and locations to each team list.
        
        Team lists are used to get the possible moves and easily
        check the capture status of a piece.
        """

        self.wp.append(King(4, 7, True))
        self.wp.append(Queen(3, 7, True))
        self.wp.append(Rook(0, 7, True))
        self.wp.append(Rook(7, 7, True))
        self.wp.append(Knight(1, 7, True))
        self.wp.append(Knight(6, 7, True))
        self.wp.append(Bishop(2, 7, True))
        self.wp.append(Bishop(5, 7, True))
        for i in range(8):
            self.wp.append(Pawn(i, 6, True))

        self.bp.append(King(4, 0, False))
        self.bp.append(Queen(3, 0, False))
        self.bp.append(Rook(0, 0, False))
        self.bp.append(Rook(7, 0, False))
        self.bp.append(Knight(1, 0, False))
        self.bp.append(Knight(6, 0, False))
        self.bp.append(Bishop(2, 0, False))
        self.bp.append(Bishop(5, 0, False))
        for i in range(8):
            self.bp.append(Pawn(i, 1, False))
Exemplo n.º 5
0
    def __init__(self):
        self.board = [[None for j in range(8)] for i in range(8)]
        self.pieces = []
        
        # set white board
        pieces = []
        for i in range(8):
            pieces.append(Pawn(i, 1, COLOR.WHITE))
        pieces.append(Rook(0, 0, COLOR.WHITE))
        pieces.append(Rook(7 ,0, COLOR.WHITE))
        pieces.append(Knight(1, 0, COLOR.WHITE))
        pieces.append(Knight(6, 0, COLOR.WHITE))
        pieces.append(Bishop(2, 0, COLOR.WHITE))
        pieces.append(Bishop(5, 0, COLOR.WHITE))
        pieces.append(King(3, 0, COLOR.WHITE))
        pieces.append(Queen(4, 0, COLOR.WHITE))

        #set black peices
        for i in range(8):
            pieces.append(Pawn(i, 6, COLOR.BLACK))
        pieces.append(Rook(0, 7, COLOR.BLACK))
        pieces.append(Rook(7 ,7, COLOR.BLACK))
        pieces.append(Knight(1, 7, COLOR.BLACK))
        pieces.append(Knight(6, 7, COLOR.BLACK))
        pieces.append(Bishop(2, 7, COLOR.BLACK))
        pieces.append(Bishop(5, 7, COLOR.BLACK))
        pieces.append(King(3, 7, COLOR.BLACK))
        pieces.append(Queen(4, 7, COLOR.BLACK))

        for _piece in pieces:
            self.pieces.append(_piece)
            self.board[_piece._x][_piece._y] = _piece
Exemplo n.º 6
0
    def _init_pieces(self):
        if not self._positions:
            king = King(color=self._color)
            self._positions.update({str(king.position): king})

            queen = Queen(color=self._color)
            self._positions.update({str(queen.position): queen})

            for i in range(1, 9):
                pawn = Pawn(self._color, col=i)
                self._positions.update({str(pawn.position): pawn})

            knight = Knight(self._color, col=2)
            self._positions.update({str(knight.position): knight})

            knight = Knight(self._color, col=7)
            self._positions.update({str(knight.position): knight})

            rook = Rook(self._color, col=1)
            self._positions.update({str(rook.position): rook})

            rook = Rook(self._color, col=8)
            self._positions.update({str(rook.position): rook})

            bishop = Bishop(self._color, col=3)
            self._positions.update({str(bishop.position): bishop})

            bishop = Bishop(self._color, col=6)
            self._positions.update({str(bishop.position): bishop})
Exemplo n.º 7
0
def parse(fin):
    white_pieces = []
    black_pieces = []
    with open(fin, "r") as file_in:
        lines = file_in.read().splitlines()
        for line in lines:
            if int(line[-1:]) > 0:
                for idx in range(0, int(line[-1:])):
                    if (line[-7:-2] == 'WHITE'):
                        temp = line[:-8]
                        if (temp == 'BISHOP'):
                            white_pieces.append(Bishop(Position(), True))
                        elif (temp == 'KNIGHT'):
                            white_pieces.append(Knight(Position(), True))
                        elif (temp == 'QUEEN'):
                            white_pieces.append(Queen(Position(), True))
                        elif (temp == 'ROOK'):
                            white_pieces.append(Rook(Position(), True))

                    elif (line[-7:-2] == 'BLACK'):
                        temp = line[:-8]
                        if (temp == 'BISHOP'):
                            black_pieces.append(Bishop(Position(), False))
                        elif (temp == 'KNIGHT'):
                            black_pieces.append(Knight(Position(), False))
                        elif (temp == 'QUEEN'):
                            black_pieces.append(Queen(Position(), False))
                        elif (temp == 'ROOK'):
                            black_pieces.append(Rook(Position(), False))

    file_in.close()
    return white_pieces, black_pieces
Exemplo n.º 8
0
    def test_init(self):
        xs = [chr(ord('a') + i) for i in range(0, 8)]
        ys = [i for i in range(1, 9)]

        for x, y in product(xs, ys):
            b = Bishop(x, y)
            verifica = []
            count = 0
            for n in range(1, 9):
                if n <= 8:
                    count += 1
                    moves = list(product([ord(b.pos_in_x) + count], [b.pos_in_y + count]))
                    for x_m, y_m in moves:
                        if ord('a') <= x_m <= ord('h') and 1 <= y_m <= 8:
                            verifica.append((chr(x_m), y_m))
                    moves.clear()
            count = 0
            for n in range(1, 9):
                if n <= 8:
                    count += 1
                    moves_1 = list(product([ord(b.pos_in_x) - count], [b.pos_in_y + count]))
                    for x_m, y_m in moves_1:
                        if ord('a') <= x_m <= ord('h') and 1 <= y_m <= 8:
                            verifica.append((chr(x_m), y_m))
                    moves_1.clear()

            count = 0
            for n in range(1, 9):
                count += 1
                moves_2 = list(product([ord(b.pos_in_x) - count], [b.pos_in_y - count]))
                for x_m, y_m in moves_2:
                    if ord('a') <= x_m <= ord('h') and 1 <= y_m <= 8:
                        verifica.append((chr(x_m), y_m))
                moves_2.clear()

            count = 0
            for n in range(1, 9):
                count += 1
                moves_3 = list(product([ord(b.pos_in_x) + count], [b.pos_in_y - count]))
                for x_m, y_m in moves_3:
                    if ord('a') <= x_m <= ord('h') and 1 <= y_m <= 8:
                        verifica.append((chr(x_m), y_m))
                moves_3.clear()

            try:
                self.assertTrue(sorted(verifica) == sorted(b.possible_poss()))


            except:
                print('Something is wrong')
                break
Exemplo n.º 9
0
def mainThread():
    
    table = Table()
    table.addpiece(1, 0, Pawn(1, 0, pawn_color, table.table_map))
    table.addpiece(1, 1, Pawn(1, 1, pawn_color, table.table_map))
    table.addpiece(1, 2, Pawn(1, 2, pawn_color, table.table_map))
    table.addpiece(1, 3, Pawn(1, 3, pawn_color, table.table_map))
    table.addpiece(1, 4, Pawn(1, 4, pawn_color, table.table_map))
    table.addpiece(1, 5, Pawn(1, 5, pawn_color, table.table_map))
    table.addpiece(1, 6, Pawn(1, 6, pawn_color, table.table_map))
    table.addpiece(1, 7, Pawn(1, 7, pawn_color, table.table_map))
    
    table.addpiece(0, 0, Tower(0, 0, tower_color, table.table_map))
    table.addpiece(0, 1, Horse(0, 1, horse_color, table.table_map))
    table.addpiece(0, 2, Bishop(0, 2, bishop_color, table.table_map))
    table.addpiece(0, 3, King(0, 3, king_color, table.table_map))
    table.addpiece(0, 4, Queen(0, 4, quin_color, table.table_map))
    table.addpiece(0, 5, Bishop(0, 5, bishop_color, table.table_map))
    table.addpiece(0, 6, Horse(0, 6, horse_color, table.table_map))
    table.addpiece(0, 7, Tower(0, 7, tower_color, table.table_map))
    
    
    table.addpiece(6, 0, Pawn(6, 0, pawn_color, table.table_map, True))
    table.addpiece(6, 1, Pawn(6, 1, pawn_color, table.table_map, True))
    table.addpiece(6, 2, Pawn(6, 2, pawn_color, table.table_map, True))
    table.addpiece(6, 3, Pawn(6, 3, pawn_color, table.table_map, True))
    table.addpiece(6, 4, Pawn(6, 4, pawn_color, table.table_map, True))
    table.addpiece(6, 5, Pawn(6, 5, pawn_color, table.table_map, True))
    table.addpiece(6, 6, Pawn(6, 6, pawn_color, table.table_map, True))
    table.addpiece(6, 7, Pawn(6, 7, pawn_color, table.table_map, True))
    
    table.addpiece(7, 0, Tower(7, 0, tower_color, table.table_map))
    table.addpiece(7, 1, Horse(7, 1, horse_color, table.table_map))
    table.addpiece(7, 2, Bishop(7, 2, bishop_color, table.table_map))
    table.addpiece(7, 3, King(7, 3, king_color, table.table_map))
    table.addpiece(7, 4, Queen(7, 4, quin_color, table.table_map))
    table.addpiece(7, 5, Bishop(7, 5, bishop_color, table.table_map))
    table.addpiece(7, 6, Horse(7, 6, horse_color, table.table_map))
    table.addpiece(7, 7, Tower(7, 7, tower_color, table.table_map))
    
    while True: 
        for evento in py.event.get():
            if evento.type == py.QUIT:
                py.quit()
                
        display.fill((255,255,255))
        table.render(display, py, font)
        py.display.flip()
        time.tick(64)
Exemplo n.º 10
0
 def setBoard(self, fen):
     row, column = 0, 0
     for character in fen:
         if character == 'R':
             self.addPiece(Rook(column, row, 'w', self.board.board))
             column += 1
         elif character == 'r':
             self.addPiece(Rook(column, row, 'b', self.board.board))
             column += 1
         elif character == 'N':
             self.addPiece(Knight(column, row, 'w', self.board.board))
             column += 1
         elif character == 'n':
             self.addPiece(Knight(column, row, 'b', self.board.board))
             column += 1
         elif character == 'B':
             self.addPiece(Bishop(column, row, 'w', self.board.board))
             column += 1
         elif character == 'b':
             self.addPiece(Bishop(column, row, 'b', self.board.board))
             column += 1
         elif character == 'P':
             self.addPiece(Pawn(column, row, 'w', self.board.board))
             column += 1
         elif character == 'p':
             self.addPiece(Pawn(column, row, 'b', self.board.board))
             column += 1
         elif character == 'K':
             self.addPiece(King(column, row, 'w', self.board.board))
             column += 1
         elif character == 'k':
             self.addPiece(King(column, row, 'b', self.board.board))
             column += 1
         elif character == 'Q':
             self.addPiece(Queen(column, row, 'w', self.board.board))
             column += 1
         elif character == 'q':
             self.addPiece(Queen(column, row, 'b', self.board.board))
             column += 1
         elif character == '/':
             column = 0
             row += 1
         else:
             if character >= '1' and character <= '9':
                 column += int(character)
             elif character == ' ':
                 i = fen.index(character) + 1
                 self.whitesTurn = True if fen[i] == 'w' else False
                 return
Exemplo n.º 11
0
    def create_standard_game(self):
        from bishop import Bishop
        from king import King
        from knight import Knight
        from pawn import Pawn
        from queen import Queen
        from rook import Rook
        self.set_piece(Rook(0, Alliance.WHITE))
        self.set_piece(Knight(1, Alliance.WHITE))
        self.set_piece(Bishop(2, Alliance.WHITE))
        self.set_piece(Queen(3, Alliance.WHITE))
        self.set_piece(King(4, Alliance.WHITE))
        self.set_piece(Bishop(5, Alliance.WHITE))
        self.set_piece(Knight(6, Alliance.WHITE))
        self.set_piece(Rook(7, Alliance.WHITE))
        self.set_piece(Pawn(8, Alliance.WHITE))
        self.set_piece(Pawn(9, Alliance.WHITE))
        self.set_piece(Pawn(10, Alliance.WHITE))
        self.set_piece(Pawn(11, Alliance.WHITE))
        self.set_piece(Pawn(12, Alliance.WHITE))
        self.set_piece(Pawn(13, Alliance.WHITE))
        self.set_piece(Pawn(14, Alliance.WHITE))
        self.set_piece(Pawn(15, Alliance.WHITE))

        self.set_piece(Pawn(48, Alliance.BLACK))
        self.set_piece(Pawn(49, Alliance.BLACK))
        self.set_piece(Pawn(50, Alliance.BLACK))
        self.set_piece(Pawn(51, Alliance.BLACK))
        self.set_piece(Pawn(52, Alliance.BLACK))
        self.set_piece(Pawn(53, Alliance.BLACK))
        self.set_piece(Pawn(54, Alliance.BLACK))
        self.set_piece(Pawn(55, Alliance.BLACK))
        self.set_piece(Rook(56, Alliance.BLACK))
        self.set_piece(Knight(57, Alliance.BLACK))
        self.set_piece(Bishop(58, Alliance.BLACK))
        self.set_piece(Queen(59, Alliance.BLACK))
        self.set_piece(King(60, Alliance.BLACK))
        self.set_piece(Bishop(61, Alliance.BLACK))
        self.set_piece(Knight(62, Alliance.BLACK))
        self.set_piece(Rook(63, Alliance.BLACK))

        self.set_move_alliance(Alliance.WHITE)
Exemplo n.º 12
0
    def __init__(self) -> None:
        """Setup the board with all the pieces on the starting positions."""
        self._squares: Dict[str, Square] = {
            coord: Square(coord)
            for coord in map("".join,
                             itertools.product(self._FILES, self._RANKS))
        }

        self["a8"].piece = Rook(Color.BLACK)
        self["b8"].piece = Knight(Color.BLACK)
        self["c8"].piece = Bishop(Color.BLACK)
        self["d8"].piece = Queen(Color.BLACK)
        self["e8"].piece = King(Color.BLACK)
        self["f8"].piece = Bishop(Color.BLACK)
        self["g8"].piece = Knight(Color.BLACK)
        self["h8"].piece = Rook(Color.BLACK)
        self["a1"].piece = Rook(Color.WHITE)
        self["b1"].piece = Knight(Color.WHITE)
        self["c1"].piece = Bishop(Color.WHITE)
        self["d1"].piece = Queen(Color.WHITE)
        self["e1"].piece = King(Color.WHITE)
        self["f1"].piece = Bishop(Color.WHITE)
        self["g1"].piece = Knight(Color.WHITE)
        self["h1"].piece = Rook(Color.WHITE)

        for file in self._FILES:
            self[f"{file}7"].piece = Pawn(Color.BLACK)
            self[f"{file}2"].piece = Pawn(Color.WHITE)

        # Set the adjacent Square nodes for each Square.
        for i in range(8):
            for j in range(8):
                sq = self._get(i, j)
                sq["n"] = self._get(i, j + 1)
                sq["e"] = self._get(i + 1, j)
                sq["s"] = self._get(i, j - 1)
                sq["w"] = self._get(i - 1, j)
                sq["ne"] = self._get(i + 1, j + 1)
                sq["se"] = self._get(i + 1, j - 1)
                sq["sw"] = self._get(i - 1, j - 1)
                sq["nw"] = self._get(i - 1, j + 1)
Exemplo n.º 13
0
    def initializePieces(self):
        self.board[4][0] = King(self.window, False, 4, 0, self.pieces_image[0])
        self.black_king = self.board[4][0]

        self.board[3][0] = Queen(self.window, False, 3, 0, self.pieces_image[1])
        self.board[0][0] = Rook(self.window, False, 0, 0, self.pieces_image[4])
        self.board[7][0] = Rook(self.window, False, 7, 0, self.pieces_image[4])
        self.board[6][0] = Knight(self.window, False, 6, 0, self.pieces_image[3])
        self.board[1][0] = Knight(self.window, False, 1, 0, self.pieces_image[3])
        self.board[2][0] = Bishop(self.window, False, 2, 0, self.pieces_image[2])
        self.board[5][0] = Bishop(self.window, False, 5, 0, self.pieces_image[2])

        self.board[4][7] = King(self.window, True, 4, 7, self.pieces_image[0 + 6])
        self.white_king = self.board[4][7]

        self.board[3][7] = Queen(self.window, True, 3, 7, self.pieces_image[1 + 6])
        self.board[0][7] = Rook(self.window, True, 0, 7, self.pieces_image[4 + 6])
        self.board[7][7] = Rook(self.window, True, 7, 7, self.pieces_image[4 + 6])
        self.board[6][7] = Knight(self.window, True, 6, 7, self.pieces_image[3 + 6])
        self.board[1][7] = Knight(self.window, True, 1, 7, self.pieces_image[3 + 6])
        self.board[2][7] = Bishop(self.window, True, 2, 7, self.pieces_image[2 + 6])
        self.board[5][7] = Bishop(self.window, True, 5, 7, self.pieces_image[2 + 6])

        white = False
        for y in [1, 6]:
            for x in range(8):
                if y == 6:
                    white = True

                if white:
                    image = self.pieces_image[5 + 6]
                else:
                    image = self.pieces_image[5]

                self.board[x][y] = Pawn(self.window, white, x, y, image)

                if white:
                    self.white_pawns.append(self.board[x][y])
                else:
                    self.black_pawns.append(self.board[x][y])
Exemplo n.º 14
0
    def __init__(self):

        self.board = [[Empty(x='',y='',sl='.',team='')]*9 for _ in range(9)]
        self.board[0][0] = Rook(x=0,y=0,sl='r',team='black')
        self.board[0][1] = Knight(x=0,y=1,sl='n',team='black')
        self.board[0][2] = Bishop(x=0,y=2,sl='b',team='black')
        self.board[0][3] = Queen(x=0,y=3,sl='q',team='black')
        self.board[0][4] = King(x=0,y=4,sl='k',team='black')
        self.board[0][5] = Bishop(x=0,y=5,sl='b',team='black')
        self.board[0][6] = Knight(x=0,y=6,sl='n',team='black')
        self.board[0][7] = Rook(x=0,y=7,sl='r',team='black')
        self.board[1][0] = Pawn(x=1,y=0,sl='p',team='black')
        self.board[1][1] = Pawn(x=1,y=1,sl='p',team='black')
        self.board[1][2] = Pawn(x=1,y=2,sl='p',team='black')
        self.board[1][3] = Pawn(x=1,y=3,sl='p',team='black')
        self.board[1][4] = Pawn(x=1,y=4,sl='p',team='black')
        self.board[1][5] = Pawn(x=1,y=5,sl='p',team='black')
        self.board[1][6] = Pawn(x=1,y=6,sl='p',team='black')
        self.board[1][7] = Pawn(x=1,y=7,sl='p',team='black')
        self.board[7][0] = Rook(x=7,y=0,sl='R',team='white')
        self.board[7][1] = Knight(x=7,y=1,sl='N',team='white')
        self.board[7][2] = Bishop(x=7,y=2,sl='B',team='white')
        self.board[7][3] = Queen(x=7,y=3,sl='Q',team='white')
        self.board[7][4] = King(x=7,y=4,sl='K',team='white')
        self.board[7][5] = Bishop(x=7,y=5,sl='B',team='white')
        self.board[7][6] = Knight(x=7,y=6,sl='N',team='white')
        self.board[7][7] = Rook(x=7,y=7,sl='R',team='white')
        self.board[6][0] = Pawn(x=3,y=0,sl='P',team='white')
        self.board[6][1] = Pawn(x=6,y=1,sl='P',team='white')
        self.board[6][2] = Pawn(x=6,y=2,sl='P',team='white')
        self.board[6][3] = Pawn(x=6,y=3,sl='P',team='white')
        self.board[6][4] = Pawn(x=6,y=4,sl='P',team='white')
        self.board[6][5] = Pawn(x=6,y=5,sl='P',team='white')
        self.board[6][6] = Pawn(x=6,y=6,sl='P',team='white')
        self.board[6][7] = Pawn(x=6,y=7,sl='P',team='white')

        for i in range(9):
            self.board[i][8 ]= Number(sl=i)
        for j in range(9):
            self.board[8][j] = Number(sl=j)
Exemplo n.º 15
0
 def set_promoted_piece(self, piece_type, piece_position, piece_alliance):
     if piece_type == Type.QUEEN:
         from queen import Queen
         self.promoted_piece = Queen(piece_position, piece_alliance)
     elif piece_type == Type.BISHOP:
         from bishop import Bishop
         self.promoted_piece = Bishop(piece_position, piece_alliance)
     elif piece_type == Type.KNIGHT:
         from knight import Knight
         self.promoted_piece = Knight(piece_position, piece_alliance)
     elif piece_type == Type.ROOK:
         from rook import Rook
         self.promoted_piece = Rook(piece_position, piece_alliance)
Exemplo n.º 16
0
 def pawn_promotion(self, pawn, end):
     options = ("q", "r", "b", "k")
     new_piece = "None"
     while new_piece.lower()[0] not in options:
         new_piece = input("What piece would you like to promote your pawn to? Your options are:\n[Q]ueen\n[R]ook\n[B]ishop\n[K]night ")
     if new_piece.lower()[0] == "q":
         self.board[end[0]][end[1]].piece = Queen(color=pawn.color)
     if new_piece.lower()[0] == "r":
         self.board[end[0]][end[1]].piece = Rook(color=pawn.color)
     if new_piece.lower()[0] == "b":
         self.board[end[0]][end[1]].piece = Bishop(color=pawn.color)
     if new_piece.lower()[0] == "k":
         self.board[end[0]][end[1]].piece = Knight(color=pawn.color)
Exemplo n.º 17
0
    def board_setup(self):
        w = "White"
        b = "Black"

        for space in self.board[1]:
            self.board[space.position[0]][space.position[1]].piece = Pawn(color=b)
        for space in self.board[6]:
            self.board[space.position[0]][space.position[1]].piece = Pawn(color=w)
        self.board[0][0].piece = Rook(color=b)
        self.board[0][1].piece = Knight(color=b)
        self.board[0][2].piece = Bishop(color=b)
        self.board[0][3].piece = Queen(color=b)
        self.board[0][4].piece = King(color=b)
        self.board[0][5].piece = Bishop(color=b)
        self.board[0][6].piece = Knight(color=b)
        self.board[0][7].piece = Rook(color=b)
        self.board[7][0].piece = Rook(color=w)
        self.board[7][1].piece = Knight(color=w)
        self.board[7][2].piece = Bishop(color=w)
        self.board[7][3].piece = Queen(color=w)
        self.board[7][4].piece = King(color=w)
        self.board[7][5].piece = Bishop(color=w)
        self.board[7][6].piece = Knight(color=w)
        self.board[7][7].piece = Rook(color=w)
Exemplo n.º 18
0
 def create_new_piece(piece, position):
     if piece.get_piece_type() == Type.PAWN:
         from pawn import Pawn
         return Pawn(position, piece.get_piece_alliance())
     elif piece.get_piece_type() == Type.QUEEN:
         from queen import Queen
         return Queen(position, piece.get_piece_alliance())
     elif piece.get_piece_type() == Type.BISHOP:
         from bishop import Bishop
         return Bishop(position, piece.get_piece_alliance())
     elif piece.get_piece_type() == Type.KNIGHT:
         from knight import Knight
         return Knight(position, piece.get_piece_alliance())
     elif piece.get_piece_type() == Type.ROOK:
         from rook import Rook
         return Rook(position, piece.get_piece_alliance())
     elif piece.get_piece_type() == Type.KING:
         from king import King
         return King(position, piece.get_piece_alliance())
Exemplo n.º 19
0
def test_player_taken_pieces():
    game = Game()

    player = game.current_player
    game._board["a7"].piece = None
    game._board["b7"].piece = None
    game._board["c7"].piece = None
    game._board["a8"].piece = None
    game._board["b8"].piece = None
    game._board["h8"].piece = None
    game._board["c8"].piece = None

    assert player.taken_pieces == [
        Rook(Color.BLACK),
        Rook(Color.BLACK),
        Bishop(Color.BLACK),
        Knight(Color.BLACK),
        Pawn(Color.BLACK),
        Pawn(Color.BLACK),
        Pawn(Color.BLACK)
    ]
Exemplo n.º 20
0
    def new_piece(self, char="", pos=(0, 0), side=""):
        # Returns a new instance of a pieces class based on the string given to this method

        if char.lower() == 'b':
            return Bishop(char=char, pos=pos, side=side)

        if char.lower() == 'k':
            return King(char=char, pos=pos, side=side)

        if char.lower() == 'n':
            return Knight(char=char, pos=pos, side=side)

        if char.lower() == 'p':
            return Pawn(char=char, pos=pos, side=side)

        if char.lower() == 'q':
            return Queen(char=char, pos=pos, side=side)

        if char.lower() == 'r':
            return Rook(char=char, pos=pos, side=side)

        return Piece(char=char, pos=pos, side=side)
Exemplo n.º 21
0
 def _all_moves(self) -> Iterator[Move]:
     yield from Bishop._all_moves(self)
     yield from Rook._all_moves(self)
Exemplo n.º 22
0
 def bishop(self, side, coord):
     return Bishop(side, coord)
Exemplo n.º 23
0
b.place(Pawn('b7', 'Black'))
b.place(Pawn('c7', 'Black'))
b.place(Pawn('d7', 'Black'))
b.place(Pawn('e7', 'Black'))
b.place(Pawn('f7', 'Black'))
b.place(Pawn('g7', 'Black'))
b.place(Pawn('h7', 'Black'))
b.place(Rook('a1', 'White'))
b.place(Rook('h1', 'White'))
b.place(Rook('a8', 'Black'))
b.place(Rook('h8', 'Black'))
b.place(Knight('b1', 'White'))
b.place(Knight('g1', 'White'))
b.place(Knight('b8', 'Black'))
b.place(Knight('g8', 'Black'))
b.place(Bishop('c1', 'White'))
b.place(Bishop('f1', 'White'))
b.place(Bishop('c8', 'Black'))
b.place(Bishop('f8', 'Black'))
b.place(King('e1', 'White'))
b.place(Queen('d1', 'White'))
b.place(Queen('d8', 'Black'))
b.place(King('e8', 'Black'))

b.disp()
print("\n")

cnt = 0

while True:
    pos = input()
Exemplo n.º 24
0
    def __init__(self, color, boardRoot):

        if color not in ["white", "black"]:
            raise Exception("invalid color")
        self.color = color

        self.root = boardRoot

        board = self.root["board"].getBoard()  #board[","]

        if self.color == 'white':

            self.root['pieces'].append(
                King(location=board["H,1"], root=self.root, color=self.color))
            self.root['pieces'].append(
                Queen(location=board["G,0"], root=self.root, color=self.color))
            self.root['pieces'].append(
                Bishop(board["H,2"], root=self.root, color=self.color))
            self.root['pieces'].append(
                Bishop(board["F,0"], root=self.root, color=self.color))
            self.root['pieces'].append(
                Knight(board["H,3"], root=self.root, color=self.color))
            self.root['pieces'].append(
                Knight(board["E,0"], root=self.root, color=self.color))
            self.root['pieces'].append(
                Rook(board["H,4"], root=self.root, color=self.color))
            self.root['pieces'].append(
                Rook(board["D,0"], root=self.root, color=self.color))

            self.root['pieces'].append(
                Pawn(board["H,0"], root=self.root, color=self.color))
            self.root['pieces'].append(
                Pawn(board["F,1"], root=self.root, color=self.color))
            self.root['pieces'].append(
                Pawn(board["G,2"], root=self.root, color=self.color))
            self.root['pieces'].append(
                Pawn(board["E,3"], root=self.root, color=self.color))
            self.root['pieces'].append(
                Pawn(board["F,2"], root=self.root, color=self.color))
            self.root['pieces'].append(
                Pawn(board["G,3"], root=self.root, color=self.color))
            self.root['pieces'].append(
                Pawn(board["G,1"], root=self.root, color=self.color))
            self.root['pieces'].append(
                Pawn(board["E,1"], root=self.root, color=self.color))

        else:
            self.root['pieces'].append(
                King(location=board["B,7"], root=self.root, color=self.color))
            self.root['pieces'].append(
                Queen(location=board["A,6"], root=self.root, color=self.color))
            self.root['pieces'].append(
                Bishop(board["A,5"], root=self.root, color=self.color))
            self.root['pieces'].append(
                Bishop(board["C,7"], root=self.root, color=self.color))
            self.root['pieces'].append(
                Knight(board["A,4"], root=self.root, color=self.color))
            self.root['pieces'].append(
                Knight(board["D,7"], root=self.root, color=self.color))
            self.root['pieces'].append(
                Rook(board["A,3"], root=self.root, color=self.color))
            self.root['pieces'].append(
                Rook(board["E,7"], root=self.root, color=self.color))

            self.root['pieces'].append(
                Pawn(board["A,7"], root=self.root, color=self.color))
            self.root['pieces'].append(
                Pawn(board["C,6"], root=self.root, color=self.color))
            self.root['pieces'].append(
                Pawn(board["B,5"], root=self.root, color=self.color))
            self.root['pieces'].append(
                Pawn(board["B,4"], root=self.root, color=self.color))
            self.root['pieces'].append(
                Pawn(board["C,5"], root=self.root, color=self.color))
            self.root['pieces'].append(
                Pawn(board["D,4"], root=self.root, color=self.color))
            self.root['pieces'].append(
                Pawn(board["B,6"], root=self.root, color=self.color))
            self.root['pieces'].append(
                Pawn(board["D,6"], root=self.root, color=self.color))
Exemplo n.º 25
0
 def test_bishop_moves(self):
     bishop1 = Bishop(Colour.WHITE)
     pawn1 = Pawn(Colour.WHITE, (2, 2))
     self.assertEquals(set(bishop1.list_moves([pawn1])), set([(1, 1)]))
Exemplo n.º 26
0
from queen import Queen
from chess import Chess

#ped_1 = Pawn(input("metti posizione x: "), int(input("metti posizione y: ")))
#ped_1.pos_pawn()

#cav_1 = Knight(input("metti posizione x: "), int(input("metti posizione y: ")))
#cav_1.pos_knight()

#king_1 = King(input("metti posizione x: "), int(input("metti posizione y: ")))
#king_1.pos_king()

#tor_1 = Rook(input("metti posizione x: "), int(input("metti posizione y: ")))
#tor_1.pos_rook()

alfiere_1 = Bishop(input("metti posizione x: "),
                   int(input("metti posizione y: ")))
alfiere_1.possible_poss()
print(alfiere_1.possible_poss())

# input_x = input("metti posizione x: ")
# input_y = int(input("metti posizione y: "))
regina_1 = Queen('a', 3)
regina_2 = Queen('h', 8)
alfiere = Bishop('b', 3)
#pedone = Pawn('g', 7)
# questo è comodo. Può stampare a video perchè ha ereditato da ChessPiece __str__
#regina_1.pos_queen()

c = Chess()
c.set_piece(regina_1)
c.set_piece(regina_2)
Exemplo n.º 27
0
from piece import Colour
from pawn import Pawn
from king import King
from queen import Queen
from bishop import Bishop
from knight import Knight
from rook import Rook

STARTING_BOARD = (Pawn(Colour.WHITE, (0, 1)), Pawn(Colour.WHITE, (1, 1)),
                  Pawn(Colour.WHITE, (2, 1)), Pawn(Colour.WHITE, (3, 1)),
                  Pawn(Colour.WHITE, (4, 1)), Pawn(Colour.WHITE, (5, 1)),
                  Pawn(Colour.WHITE, (6, 1)), Pawn(Colour.WHITE, (7, 1)),
                  Rook(Colour.WHITE, (0, 0)), Rook(Colour.WHITE, (7, 0)),
                  Knight(Colour.WHITE, (1, 0)), Knight(Colour.WHITE, (6, 0)),
                  Bishop(Colour.WHITE, (2, 0)), Bishop(Colour.WHITE, (5, 0)),
                  Queen(Colour.WHITE, (3, 0)), King(Colour.WHITE, (4, 0)),
                  Pawn(Colour.BLACK, (0, 6)), Pawn(Colour.BLACK, (1, 6)),
                  Pawn(Colour.BLACK, (2, 6)), Pawn(Colour.BLACK, (3, 6)),
                  Pawn(Colour.BLACK, (4, 6)), Pawn(Colour.BLACK, (5, 6)),
                  Pawn(Colour.BLACK, (6, 6)), Pawn(Colour.BLACK, (7, 6)),
                  Rook(Colour.BLACK, (0, 7)), Rook(Colour.BLACK, (7, 7)),
                  Knight(Colour.BLACK, (1, 7)), Knight(Colour.BLACK, (6, 7)),
                  Bishop(Colour.BLACK, (2, 7)), Bishop(Colour.BLACK, (5, 7)),
                  Queen(Colour.BLACK, (3, 7)), King(Colour.BLACK, (4, 7)))


class GameTree(object):
    def __init__(self, pieces, colour):
        self.pieces = list(pieces)
        self.colour = colour
        self.children = []
Exemplo n.º 28
0
 def test_calls_super_in_init(self, init):
     bishop = Bishop(Board(), Square(4, 2), WHITE)
     assert init.called
Exemplo n.º 29
0
 def is_eyeing(self, pos, rank, file):
     from rook import Rook
     from bishop import Bishop
     return (Rook.is_eyeing(self, pos, rank, file)
             or Bishop.is_eyeing(self, pos, rank, file))
Exemplo n.º 30
0
    'bB', 'bK', 'bN', 'bP', 'bQ', 'bR', 'wB', 'wK', 'wN', 'wP', 'wQ', 'wR'
]
white_pawns = []
black_pawns = []

for img in gif_images:
    screen.register_shape("../Pieces/" + img + ".gif")

mychessboard = Board()
screen.tracer(100)
mychessboard.drawBoard()
mychessboard.putWhitePawns(white_pawns)
mychessboard.putBlackPawns(black_pawns)

white_rook_king = Rook(mychessboard.chess_coord["h1"], True)
white_bishop_king = Bishop(mychessboard.chess_coord["f1"], True)
white_knight_king = Knight(mychessboard.chess_coord["g1"], True)
white_rook_queen = Rook(mychessboard.chess_coord["a1"], True)
white_bishop_queen = Bishop(mychessboard.chess_coord["c1"], True)
white_knight_queen = Knight(mychessboard.chess_coord["b1"], True)
white_king = King(mychessboard.chess_coord["e1"], True)
white_queen = Queen(mychessboard.chess_coord["d1"], True)

black_rook_king = Rook(mychessboard.chess_coord["h8"], False)
black_bishop_king = Bishop(mychessboard.chess_coord["f8"], False)
black_knight_king = Knight(mychessboard.chess_coord["g8"], False)
black_rook_queen = Rook(mychessboard.chess_coord["a8"], False)
black_bishop_queen = Bishop(mychessboard.chess_coord["c8"], False)
black_knight_queen = Knight(mychessboard.chess_coord["b8"], False)
black_king = King(mychessboard.chess_coord["e8"], False)
black_queen = Queen(mychessboard.chess_coord["d8"], False)