Example #1
0
def main():
    print("Пример 1", '\n')
    board = Board()
    board.field = [([None] * 8) for i in range(8)]
    board.field[0][3] = Queen(WHITE)
    queen = board.get_piece(0, 3)
    for row in range(7, -1, -1):
        for col in range(8):
            if queen.can_move(board, 0, 3, row, col):
                print('x', end=' ')
            else:
                cell = board.cell(row, col)[1]
                cell = cell if cell != ' ' else '-'
                print(cell, end=' ')
        print()
    print("Пример 2", '\n')
    row0 = 4
    col0 = 5

    board = Board()
    board.field = [([None] * 8) for i in range(8)]
    board.field[row0][col0] = Bishop(BLACK)
    bishop = board.get_piece(row0, col0)

    for row in range(7, -1, -1):
        for col in range(8):
            if bishop.can_move(board, row0, col0, row, col):
                print('x', end=' ')
            else:
                cell = board.cell(row, col)[1]
                cell = cell if cell != ' ' else '-'
                print(cell, end=' ')
        print()
    print("Пример 3", '\n')
    row0 = 2
    col0 = 2
    knight = Knight(WHITE)
    board = Board()
    for row in range(7, -1, -1):
        for col in range(8):
            if row == row0 and col == col0:
                print(knight.char(), end=' ')
            elif knight.can_move(board, row0, col0, row, col):
                print('x', end=' ')
            else:
                print('-', end=' ')
        print()
Example #2
0
 def __init__(self):
     self.board = Board.Board()
     #self.player1 = Player.Player('black')
     #self.player2 = Player.Player('white')
     self.turn = 'black'
     self.player_moving = False
     self.status = True
     self.winner = None
Example #3
0
    def test_possible_moves(self):
        self.board = Board([[None for _ in range(8)] for _ in range(8)])
        my_king = King(color.white, Location.from_string("f3"))
        self.board.place_piece_at_square(my_king, Location.from_string("f3"))
        moves = ['f3f4', 'f3g3', 'f3f2', 'f3e3', 'f3g4', 'f3e4', 'f3g2', 'f3e2']

        for i, move in enumerate(my_king.possible_moves(self.board)):
            self.assertEqual(move, converter.long_alg(moves[i], self.board))
Example #4
0
    def test_init_default(self):
        white = color.white
        black = color.black
        test = Board([

            # First rank
            [
                Rook(white, Location(0, 0)),
                Knight(white, Location(0, 1)),
                Bishop(white, Location(0, 2)),
                Queen(white, Location(0, 3)),
                King(white, Location(0, 4)),
                Bishop(white, Location(0, 5)),
                Knight(white, Location(0, 6)),
                Rook(white, Location(0, 7))
            ],

            # Second rank
            [Pawn(white, Location(1, file)) for file in range(8)],

            # Third rank
            [None for _ in range(8)],

            # Fourth rank
            [None for _ in range(8)],

            # Fifth rank
            [None for _ in range(8)],

            # Sixth rank
            [None for _ in range(8)],

            # Seventh rank
            [Pawn(black, Location(6, file)) for file in range(8)],

            # Eighth rank
            [
                Rook(black, Location(7, 0)),
                Knight(black, Location(7, 1)),
                Bishop(black, Location(7, 2)),
                Queen(black, Location(7, 3)),
                King(black, Location(7, 4)),
                Bishop(black, Location(7, 5)),
                Knight(black, Location(7, 6)),
                Rook(black, Location(7, 7))
            ]
        ])

        self.assertEqual(self.board, test)
Example #5
0
    def test_in_check(self):
        self.board = Board([[None for _ in range(8)] for _ in range(8)])
        my_king = King(color.white, Location.from_string("f3"))
        self.board.place_piece_at_square(my_king, Location.from_string("f3"))
        self.board.place_piece_at_square(Rook(color.black, Location.from_string("f1")), Location.from_string("f1"))

        print(self.board.piece_at_square(Location.from_string("f1")).color)

        print(self.board)
        print(my_king.color)
        print(color.white == color.black)
        self.assertTrue(my_king.in_check(self.board))

        self.board = Board.init_default()
        self.board.update(converter.long_alg("f2f3", self.board))
        self.board.move_piece(Location.from_string("d8"), Location.from_string("g3"))

        self.assertTrue(self.board.get_king(color.white).in_check(self.board))
Example #6
0
 def setUp(self):
     self.empty_pos = Board([[None for _ in range(8)] for _ in range(8)])