Example #1
0
    def __init__(self) -> None:
        self.field = []
        self.current_color = Color.WHITE
        for i in range(self.FIELD_SIZE):
            self.field.append([None] * self.FIELD_SIZE)

        logging.debug(
            f'Создана шахматная доска с размерами: {self.FIELD_SIZE}x{self.FIELD_SIZE}'
        )

        # стандартная расстановка
        self.field[0] = [
            Rook(0, 0, Color.WHITE, self),
            Knight(0, 1, Color.WHITE, self),
            Bishop(0, 2, Color.WHITE, self),
            Queen(0, 3, Color.WHITE, self),
            King(0, 4, Color.WHITE, self),
            Bishop(0, 5, Color.WHITE, self),
            Knight(0, 6, Color.WHITE, self),
            Rook(0, 7, Color.WHITE, self),
        ]

        self.field[1] = [
            Pawn(1, 0, Color.WHITE, self),
            Pawn(1, 1, Color.WHITE, self),
            Pawn(1, 2, Color.WHITE, self),
            Pawn(1, 3, Color.WHITE, self),
            Pawn(1, 4, Color.WHITE, self),
            Pawn(1, 5, Color.WHITE, self),
            Pawn(1, 6, Color.WHITE, self),
            Pawn(1, 7, Color.WHITE, self),
        ]

        self.field[6] = [
            Pawn(6, 0, Color.BLACK, self),
            Pawn(6, 1, Color.BLACK, self),
            Pawn(6, 2, Color.BLACK, self),
            Pawn(6, 3, Color.BLACK, self),
            Pawn(6, 4, Color.BLACK, self),
            Pawn(6, 5, Color.BLACK, self),
            Pawn(6, 6, Color.BLACK, self),
            Pawn(6, 7, Color.BLACK, self),
        ]

        self.field[7] = [
            Rook(7, 0, Color.BLACK, self),
            Knight(7, 1, Color.BLACK, self),
            Bishop(7, 2, Color.BLACK, self),
            Queen(7, 3, Color.BLACK, self),
            King(7, 4, Color.BLACK, self),
            Bishop(7, 5, Color.BLACK, self),
            Knight(7, 6, Color.BLACK, self),
            Rook(7, 7, Color.BLACK, self),
        ]

        logging.debug('Расстановка фигур завершена')
Example #2
0
    def __init__(self) -> None:
        self.field = []
        self.current_color = Color.WHITE
        for i in range(self.FIELD_SIZE):
            self.field.append([None] * self.FIELD_SIZE)

        # стандартная расстановка
        self.field[0] = [
            Rook(0, 0, Color.WHITE, self),
            Knight(0, 1, Color.WHITE, self),
            Bishop(0, 2, Color.WHITE, self),
            Queen(0, 3, Color.WHITE, self),
            King(0, 4, Color.WHITE, self),
            Bishop(0, 5, Color.WHITE, self),
            Knight(0, 6, Color.WHITE, self),
            Rook(0, 7, Color.WHITE, self),
        ]

        self.field[1] = [
            Pawn(1, 0, Color.WHITE, self),
            Pawn(1, 1, Color.WHITE, self),
            Pawn(1, 2, Color.WHITE, self),
            Pawn(1, 3, Color.WHITE, self),
            Pawn(1, 4, Color.WHITE, self),
            Pawn(1, 5, Color.WHITE, self),
            Pawn(1, 6, Color.WHITE, self),
            Pawn(1, 7, Color.WHITE, self),
        ]

        self.field[6] = [
            Pawn(6, 0, Color.BLACK, self),
            Pawn(6, 1, Color.BLACK, self),
            Pawn(6, 2, Color.BLACK, self),
            Pawn(6, 3, Color.BLACK, self),
            Pawn(6, 4, Color.BLACK, self),
            Pawn(6, 5, Color.BLACK, self),
            Pawn(6, 6, Color.BLACK, self),
            Pawn(6, 7, Color.BLACK, self),
        ]

        self.field[7] = [
            Rook(7, 0, Color.BLACK, self),
            Knight(7, 1, Color.BLACK, self),
            Bishop(7, 2, Color.BLACK, self),
            Queen(7, 3, Color.BLACK, self),
            King(7, 4, Color.BLACK, self),
            Bishop(7, 5, Color.BLACK, self),
            Knight(7, 6, Color.BLACK, self),
            Rook(7, 7, Color.BLACK, self),
        ]
Example #3
0
def test_icon():
    board = Board()

    rook = Rook(0, 0, Color.WHITE, board)
    assert rook.char() == '♖'

    rook = Rook(0, 0, Color.BLACK, board)
    assert rook.char() == '♜'
Example #4
0
class TestRookBlocked(unittest.TestCase):
    def setUp(self):
        self.board = Board()
        self.rook = Rook(self.board, 'b', '2', 'white')
        self.pawn = Pawn(self.board, 'b', '5', 'white')

    def test_blocked_moves(self):
        result = self.rook.get_possible_moves()
        self.assertEqual(len(result), 10)
        self.assertIn((1,0), self.rook.__moves__)
        self.assertIn((1,2), self.rook.__moves__)
        self.assertIn((1,3), self.rook.__moves__)
        self.assertIn((0,1), self.rook.__moves__)
        self.assertIn((2,1), self.rook.__moves__)
        self.assertIn((3,1), self.rook.__moves__)
        self.assertIn((4,1), self.rook.__moves__)
        self.assertIn((5,1), self.rook.__moves__)
        self.assertIn((6,1), self.rook.__moves__)
        self.assertIn((7,1), self.rook.__moves__)
Example #5
0
class TestRookBase(unittest.TestCase):
    def setUp(self):
        self.board = Board()
        self.rook = Rook(self.board, 'b', '2', 'white')

    def test_base_moves(self):
        result = self.rook.get_possible_moves()
        self.assertEqual(len(result), 14)
        self.assertIn((1,0), self.rook.__moves__)
        self.assertIn((1,2), self.rook.__moves__)
        self.assertIn((1,3), self.rook.__moves__)
        self.assertIn((1,4), self.rook.__moves__)
        self.assertIn((1,5), self.rook.__moves__)
        self.assertIn((1,6), self.rook.__moves__)
        self.assertIn((1,7), self.rook.__moves__)
        self.assertIn((0,1), self.rook.__moves__)
        self.assertIn((2,1), self.rook.__moves__)
        self.assertIn((3,1), self.rook.__moves__)
        self.assertIn((4,1), self.rook.__moves__)
        self.assertIn((5,1), self.rook.__moves__)
        self.assertIn((6,1), self.rook.__moves__)
        self.assertIn((7,1), self.rook.__moves__)
Example #6
0
 def create(self):
     for i in range(8):
         for j in range(8):
             if i == 0 or i == 1:
                 color = 'black'
             if i == 6 or i == 7:
                 color = 'white'
             if i == 0 or i == 7:
                 if j == 0 or j == 7:
                     self.figures.append(
                         Rook(j, i, color,
                              figures_images[color + 'Rook']['Image'],
                              self.board))
                 if j == 1 or j == 6:
                     self.figures.append(
                         Knight(j, i, color,
                                figures_images[color + 'Knight']['Image'],
                                self.board))
                 if j == 2 or j == 5:
                     self.figures.append(
                         Bishop(j, i, color,
                                figures_images[color + 'Bishop']['Image'],
                                self.board))
                 if j == 3:
                     self.figures.append(
                         King(j, i, color,
                              figures_images[color + 'King']['Image'],
                              self.board))
                 if j == 4:
                     self.figures.append(
                         Queen(j, i, color,
                               figures_images[color + 'Queen']['Image'],
                               self.board))
             if i == 1 or i == 6:
                 self.figures.append(
                     Pawn(j, i, color,
                          figures_images[color + 'Pawn']['Image'],
                          self.board))
Example #7
0
def test_legal_move():
    # this is a dummy test for the dummy implementation
    cb = Chessboard(Game.WHITE_PIECES, Game.BLACK_PIECES)
    p = Rook(0, 0, "W", "WR1")
    assert p.is_legal_move([1, 1], cb.status()) == True
Example #8
0
 def setUp(self):
     self.board = Board()
     self.rook = Rook(self.board, 'b', '2', 'white')
Example #9
0
 def setUp(self):
     self.board = Board()
     self.rook = Rook(self.board, 'b', '2', 'white')
     self.pawn = Pawn(self.board, 'b', '5', 'black')
Example #10
0
def test_can_move():
    board = Board()
    rook = Rook(4, 4, Color.WHITE, board)
    assert rook.can_move(4, 6)
Example #11
0
def test_cant_move_with_obstacles():
    board = Board()
    rook = Rook(7, 0, Color.BLACK, board)
    assert not rook.can_move(4, 0)
Example #12
0
def test_cant_move_diagonal():
    board = Board()
    rook = Rook(0, 0, Color.WHITE, board)
    assert not rook.can_move(1, 1)