Exemple #1
0
    def test_move_hint_2(self):
        b = Board()

        b.move(Square('e2'), Square('e4'))
        b.move(Square('d7'), Square('d5'))

        expected_hints = {
            Square('d1'): [
                (Square('e2'), None),
                (Square('f3'), None),
                (Square('g4'), None),
                (Square('h5'), None),
            ],
            Square('e4'): [
                (
                    Square('d5'),
                    Piece(c.PieceType.pawn, c.Color.black, 3),
                ),
                (Square('e5'), None),
            ],
            Square('c8'): [
                (Square('d7'), None),
                (Square('e6'), None),
                (Square('f5'), None),
                (Square('g4'), None),
                (Square('h3'), None),
            ],
        }

        for s, hints in expected_hints.items():
            self.assertEqual(b.move_hint(s), hints)
Exemple #2
0
    def test_set_data(self):
        b = Board()
        data_copy = copy.deepcopy(b.data)
        b.move(Square('e2'), Square('e4'))
        self.assertNotEqual(b.data, data_copy)

        b.data = data_copy
        self.assertEqual(b.data, data_copy)
Exemple #3
0
    def test_set_reverse(self):
        b = Board()
        reverse_copy = copy.deepcopy(b.reverse)
        b.move(Square('e2'), Square('e4'))
        self.assertNotEqual(b.reverse, reverse_copy)

        b.reverse = reverse_copy
        self.assertEqual(b.reverse, reverse_copy)
Exemple #4
0
    def test_reset(self):
        b = Board()

        # First move some pieces around
        b.move(Square('e2'), Square('e4'))
        b.move(Square('e7'), Square('e5'))

        expected_piece = Piece(
            c.PieceType.pawn,
            c.Color.white,
            order=4,
        )
        self.assertEqual(
            b.get_piece(Square('e4')),
            expected_piece,
        )

        expected_piece = Piece(
            c.PieceType.pawn,
            c.Color.black,
            order=4,
        )
        self.assertEqual(
            b.get_piece(Square('e5')),
            expected_piece,
        )

        # Now let's reset the board
        b.reset()

        for square, piece in b.data.items():
            if b.is_empty(square):
                continue
            expected_piece = self.data[square]

            self.assertEqual(piece, expected_piece)