예제 #1
0
파일: board.py 프로젝트: gurgenXD/chess
    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)
예제 #2
0
파일: board.py 프로젝트: AbelTefera/PyChess
    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
예제 #3
0
    def setup_battle_field(self):
        name = input('What name do you want for your kingdom?: ').strip()
        if not name:
            print('Name is required')
            return

        self.attacking_kingdom = self.mighty_kingdom = Kingdom({
            'name':
            name,
            'king':
            King('mighty King'),
            'soldiers':
            10,
            'wealth':
            Wealth(1_000_000)
        })

        self.recieving_kingdom = self.opponent = Kingdom({
            'name':
            'supermen',
            'king':
            King('super King'),
            'soldiers':
            10,
            'wealth':
            Wealth(1_000_000)
        })
        self.weapon = Trebuchet()
        print('')
예제 #4
0
 def test_valid_moves_border(self):
     board = Board()
     board.clean()
     king = King(board, Square(0, 0), BLACK)
     expected = [Square(0, 1), Square(1, 0), Square(1, 1)]
     result = king.valid_moves()
     self.assertEqual(expected, result)
예제 #5
0
    def processAndSend(self, char, pos):
        position = []
        if char == 'white:soldier' or char == 'black:soldier':
            sold = Soldier(char, pos)
            position = sold.getPositions()

        elif char == 'white:eleph' or char == 'black:eleph':
            elephant = Elephant(char, pos)
            position = elephant.getPositions()

        elif char == 'white:camel' or char == 'black:camel':
            cam = Camel(char, pos)
            position = cam.getPositions()

        elif char == 'white:horse' or char == 'black:horse':
            hors = Horse(char, pos)
            position = hors.getPositions()

        elif char == 'white:queen' or char == 'black:queen':
            qun = Queen(char, pos)
            position = qun.getPositions()

        elif char == 'white:king' or char == 'black:king':
            kin = King(char, pos)
            position = kin.getPositions()
        dataString = pickle.dumps(position)
        self.client.send(dataString)
예제 #6
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
예제 #7
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))
예제 #8
0
 def test_valid_moves_border(self):
     board = Board()
     board.clean()
     king = King(board, Square(0, 0), BLACK)
     expected = [Square(0, 1), Square(1, 0), Square(1, 1)]
     result = king.valid_moves()
     self.assertEqual(expected, result)
예제 #9
0
파일: test_king.py 프로젝트: zbyrne/chess
 def test_king_moves(self):
     king1 = King(Colour.WHITE, (4, 4))
     pawn1 = Pawn(Colour.WHITE, (4, 5))
     pawn2 = Pawn(Colour.WHITE, (4, 3))
     pawn3 = Pawn(Colour.WHITE, (3, 3))
     pawn4 = Pawn(Colour.WHITE, (5, 5))
     self.assertEquals(set(king1.list_moves([pawn1, pawn2, pawn3, pawn4])),
                       set([(3, 5), (5, 3), (5, 4), (3, 4)]))
예제 #10
0
 def test_attacks_north(self):
     board = Board()
     board.clean()
     board.matrix[3][2] = "P"
     king = King(board, Square(4, 2), WHITE)
     expected = [Square(3, 2)]
     result = king.attacking_moves()
     self.assertEqual(expected, result)
예제 #11
0
 def test_attacks_north(self):
     board = Board()
     board.clean() 
     board.matrix[3][2] = "P"
     king = King(board, Square(4, 2), WHITE)
     expected = [Square(3, 2)]
     result = king.attacking_moves()
     self.assertEqual(expected, result)
예제 #12
0
 def test_valid_moves_clean_board(self):
     board = Board()
     board.clean()
     king = King(board, Square(4, 4), BLACK)
     expected = [Square(3, 3), Square(3, 4), Square(3, 5),
                 Square(4, 3), Square(4, 5),
                 Square(5, 3), Square(5, 4), Square(5, 5)]
     result = king.valid_moves()
     self.assertEqual(expected, result)
예제 #13
0
파일: tests.py 프로젝트: ruohola/pychess
def test_piece_eq_and_hash():
    king1 = King(Color.WHITE)
    king2 = King(Color.WHITE)
    king3 = King(Color.BLACK)
    queen1 = Queen(Color.WHITE)
    queen2 = Queen(Color.WHITE)
    queen3 = Queen(Color.BLACK)
    assert king1 == king2 and hash(king1) == hash(king2)
    assert queen1 == queen2 and hash(queen1) == hash(queen2)
    assert king1 != king3 and hash(king1) != hash(king3)
    assert queen1 != queen3 and hash(queen1) != hash(queen3)
예제 #14
0
 def test_valid_moves_with_other_pieces(self):
     board = Board()
     board.clean()
     board.matrix[1][1] = 'P'
     board.matrix[1][2] = 'P'
     board.matrix[2][3] = 'b'
     king = King(board, Square(2, 2), WHITE)
     expected = [Square(1, 3), Square(2, 1), Square(3, 1), 
                 Square(3, 2),Square(3, 3), Square(1, 1),
                 Square(1, 2)]
     result = king.valid_moves()
     self.assertEqual(expected, result)
예제 #15
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)
예제 #16
0
파일: game.py 프로젝트: eragoh/AntiChess-AI
 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
예제 #17
0
 def stringToTablero(self, chain):
     mesa = [[0 for x in range(8)] for _ in range(8)]  #Mesa
     piezas = ""
     equipo = ""
     tipo = 0
     for i in range(len(chain)):
         if i < 64:
             piezas = piezas + chain[i]
         else:
             equipo = equipo + chain[i]
     for i in range(len(mesa)):
         for j in range(len(mesa[i])):
             if piezas[tipo] == "P":
                 mesa[i][j] = Peon(i, j, equipo[tipo])
             elif piezas[tipo] == "A":
                 mesa[i][j] = Alfil(i, j, equipo[tipo])
             elif piezas[tipo] == "C":
                 mesa[i][j] = Caballo(i, j, equipo[tipo])
             elif piezas[tipo] == "T":
                 mesa[i][j] = Torre(i, j, equipo[tipo])
             elif piezas[tipo] == "K":
                 mesa[i][j] = King(i, j, equipo[tipo])
             elif piezas[tipo] == "Q":
                 mesa[i][j] = Queen(i, j, equipo[tipo])
             else:
                 mesa[i][j] = 0
             tipo = tipo + 1
     return mesa
예제 #18
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})
예제 #19
0
 def test_valid_moves_clean_board(self):
     board = Board()
     board.clean()
     king = King(board, Square(4, 4), BLACK)
     expected = [
         Square(3, 3),
         Square(3, 4),
         Square(3, 5),
         Square(4, 3),
         Square(4, 5),
         Square(5, 3),
         Square(5, 4),
         Square(5, 5)
     ]
     result = king.valid_moves()
     self.assertEqual(expected, result)
예제 #20
0
 def test_valid_moves_with_other_pieces(self):
     board = Board()
     board.clean()
     board.matrix[1][1] = 'P'
     board.matrix[1][2] = 'P'
     board.matrix[2][3] = 'b'
     king = King(board, Square(2, 2), WHITE)
     expected = [
         Square(1, 3),
         Square(2, 1),
         Square(3, 1),
         Square(3, 2),
         Square(3, 3),
         Square(1, 1),
         Square(1, 2)
     ]
     result = king.valid_moves()
     self.assertEqual(expected, result)
예제 #21
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)
예제 #22
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)
예제 #23
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])
예제 #24
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)
예제 #25
0
    def __init__(self):
        self.M = [[0 for x in range(8)] for _ in range(8)]  #Mesa
        self.jugando = True
        self.jugador = 1  #Jugador 1 azules, jugador 0 rojas

        self.M[0][0] = Torre(0, 0, "R")
        self.M[0][1] = Caballo(0, 1, "R")
        self.M[0][2] = Alfil(0, 2, "R")
        self.M[0][3] = Queen(0, 3, "R")
        self.M[0][4] = King(0, 4, "R")
        self.M[0][5] = Alfil(0, 5, "R")
        self.M[0][6] = Caballo(0, 6, "R")
        self.M[0][7] = Torre(0, 7, "R")

        self.M[1][0] = Peon(1, 0, "R")
        self.M[1][1] = Peon(1, 1, "R")
        self.M[1][2] = Peon(1, 2, "R")
        self.M[1][3] = Peon(1, 3, "R")
        self.M[1][4] = Peon(1, 4, "R")
        self.M[1][5] = Peon(1, 5, "R")
        self.M[1][6] = Peon(1, 6, "R")
        self.M[1][7] = Peon(1, 7, "R")

        self.M[6][0] = Peon(6, 0, "A")
        self.M[6][1] = Peon(6, 1, "A")
        self.M[6][2] = Peon(6, 2, "A")
        self.M[6][3] = Peon(6, 3, "A")
        self.M[6][4] = Peon(6, 4, "A")
        self.M[6][5] = Peon(6, 5, "A")
        self.M[6][6] = Peon(6, 6, "A")
        self.M[6][7] = Peon(6, 7, "A")

        self.M[7][0] = Torre(7, 0, "A")
        self.M[7][1] = Caballo(7, 1, "A")
        self.M[7][2] = Alfil(7, 2, "A")
        self.M[7][3] = Queen(7, 3, "A")
        self.M[7][4] = King(7, 4, "A")
        self.M[7][5] = Alfil(7, 5, "A")
        self.M[7][6] = Caballo(7, 6, "A")
        self.M[7][7] = Torre(7, 7, "A")
예제 #26
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)
예제 #27
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())
예제 #28
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)
예제 #29
0
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()
    pos = pos.split(" ")
    initial = pos[0]
    final = pos[1]
예제 #30
0
 def test_valid_moves_initial_position(self):
     king = King(Board(), Square(7, 4), WHITE)
     expected = []
     result = king.valid_moves()
     self.assertEqual(expected, result)
예제 #31
0
 def test_calls_super_in_init(self, init):
     king = King(Board(), Square(4, 2), WHITE)
     assert init.called
예제 #32
0
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)

mychessboard.putwhitePieces(rookq=white_rook_queen,
                            knightq=white_knight_queen,
                            bishopq=white_bishop_queen,
                            queen=white_queen,
예제 #33
0
파일: gameTree.py 프로젝트: zbyrne/chess
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 = []
예제 #34
0
 def king(self, side, coord):
     return King(side, coord)
예제 #35
0
 def test_valid_moves_initial_position(self):
     king = King(Board(), Square(7, 4), WHITE)
     expected = []
     result = king.valid_moves()
     self.assertEqual(expected, result)