Exemplo n.º 1
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)
Exemplo n.º 2
0
    def test_possible_moves(self):
        self.empty_pos.place_piece_at_square(
            Knight(color.white, Location.from_string("e4")),
            Location.from_string("e4"))
        knight = self.empty_pos.piece_at_square(Location.from_string("e4"))

        moves = knight.possible_moves(self.empty_pos)
        self.assertEqual(len(list(moves)), 8)
Exemplo n.º 3
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)))
Exemplo n.º 4
0
 def test_incomplete_alg_piece_movement_with_file_specified_alt(self):
     self.assertEqual(
         converter.incomplete_alg("Ngf3", color.white, self.test_board),
         Move(
             end_loc=Location.from_string("f3"),
             piece=Knight(color.white, Location.from_string("g1")),
             status=notation_const.MOVEMENT,
             start_loc=Location.from_string("g1")
         )
     )
Exemplo n.º 5
0
 def test_incomplete_alg_piece_capture(self):
     self.test_board.update(converter.short_alg("Nf3", color.white, self.test_board))
     self.test_board.update(converter.short_alg("e5", color.black, self.test_board))
     self.assertEqual(
         converter.incomplete_alg("Nxe5", color.white, self.test_board),
         Move(
             end_loc=Location.from_string("e5"),
             piece=Knight(color.white, Location.from_string("f3")),
             status=notation_const.CAPTURE,
             start_loc=Location.from_string("f3")
         )
     )
Exemplo n.º 6
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"))