Ejemplo n.º 1
0
    def testStr(self):
        self.assertEqual(str(self.start_specified), "f4a3")

        self.white_pawn_move = Move(Location(7, 0),
                                    piece=self.white_pawn,
                                    status=notation_const.MOVEMENT,
                                    start_loc=Location(6, 0),
                                    promoted_to_piece=Queen(color.white,
                                                            Location(7, 0)))
Ejemplo n.º 2
0
    def test_piece_at_square(self):
        self.assertEqual(self.board.piece_at_square(Location(0, 0)),
                         Rook(color.white, Location(0, 0)))

        self.assertEqual(self.board.piece_at_square(Location(1, 0)),
                         Pawn(color.white, Location(1, 0)))

        self.assertEqual(self.board.piece_at_square(Location(0, 1)),
                         Knight(color.white, Location(0, 1)))
Ejemplo n.º 3
0
    def test_find_piece(self):
        self.assertEqual(
            self.board.find_piece(Rook(color.white, Location(0, 0))),
            Location(0, 0))

        self.assertEqual(
            self.board.find_piece(Rook(color.black, Location(7, 0))),
            Location(7, 0))

        self.assertNotEqual(
            self.board.find_piece(Rook(color.black, Location(7, 0))),
            Location(3, 0))

        self.assertEqual(
            self.board.find_piece(Pawn(color.white, Location(0, 0))),
            Location.from_string("a2"))

        self.assertEqual(
            self.board.find_piece(Knight(color.white, Location(0, 0))),
            Location.from_string("b1"))
Ejemplo n.º 4
0
    def setUp(self):
        self.white_pawn = Pawn(color.white, Location(1, 0))
        self.black_pawn = Pawn(color.black, Location(1, 0))

        self.white_pawn_move = Move(Location(2, 0),
                                    piece=self.white_pawn,
                                    status=notation_const.MOVEMENT,
                                    start_loc=Location(1, 0))

        self.start_specified = Move(Location(2, 0),
                                    piece=self.white_pawn,
                                    status=notation_const.MOVEMENT,
                                    start_loc=Location(3, 5))
Ejemplo n.º 5
0
 def testShiftUpRight(self):
     self.assertEqual(Location(3, 4).shift_up_right(), Location(4, 5))
Ejemplo n.º 6
0
 def testShiftLeft(self):
     self.assertEqual(Location(3, 4).shift_left(), Location(3, 3))
     self.assertEqual(Location(0, 2).shift_left(), Location(0, 1))
Ejemplo n.º 7
0
 def testShiftRight(self):
     self.assertEqual(Location(3, 4).shift_right(), Location(3, 5))
     self.assertEqual(Location(0, 2).shift_right(), Location(0, 3))
Ejemplo n.º 8
0
 def testShiftDown(self):
     self.assertEqual(Location(3, 4).shift_down(), Location(2, 4))
     self.assertEqual(Location(1, 2).shift_down(), Location(0, 2))
Ejemplo n.º 9
0
 def testShiftUp(self):
     self.assertEqual(Location(3, 4).shift_up(), Location(4, 4))
     self.assertEqual(Location(0, 2).shift_up(), Location(1, 2))
Ejemplo n.º 10
0
 def testEquals(self):
     self.assertEqual(self.white_pawn_move, Move(end_loc=Location(2, 0),
                                                 piece=self.white_pawn,
                                                 status=notation_const.MOVEMENT,
                                                 start_loc=Location(1, 0)))
Ejemplo n.º 11
0
 def testShiftDownLeft(self):
     self.assertEqual(Location(1, 1).shift_down_left(), Location(0, 0))
Ejemplo n.º 12
0
 def test_remove_piece_at_square(self):
     test_board = Board.init_default()
     test_board.position[0][0] = None
     self.board.remove_piece_at_square(Location(0, 0))
     self.assertEqual(self.board, test_board)
Ejemplo n.º 13
0
    def test_get_king(self):
        self.assertEqual(self.board.get_king(color.white),
                         King(color.white, Location(0, 4)))

        self.assertEqual(self.board.get_king(color.black),
                         King(color.black, Location(7, 4)))
Ejemplo n.º 14
0
    def test_find_king(self):
        self.assertEqual(self.board.find_king(color.white), Location(0, 4))

        self.assertEqual(self.board.find_king(color.black), Location(7, 4))
Ejemplo n.º 15
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)
Ejemplo n.º 16
0
 def testShiftUpLeft(self):
     self.assertEqual(Location(1, 2).shift_up_left(), Location(2, 1))
Ejemplo n.º 17
0
 def testShiftDownRight(self):
     self.assertEqual(Location(5, 3).shift_down_right(), Location(4, 4))
Ejemplo n.º 18
0
 def test_is_square_empty(self):
     self.assertTrue(self.board.is_square_empty(Location(2, 0)))
     self.assertFalse(self.board.is_square_empty(Location(0, 3)))
Ejemplo n.º 19
0
 def testEquals(self):
     self.assertEqual(Location(2, 3), Location(2, 3))
     self.assertEqual(Location(7, 6), Location(7, 6))
     self.assertNotEqual(Location(4, 5), Location(5, 4))
Ejemplo n.º 20
0
 def testStr(self):
     self.assertEqual(str(Location(3, 4)), "e4")
     self.assertEqual(str(Location(0, 0)), "a1")
     self.assertEqual(str(Location(7, 7)), "h8")