Exemplo n.º 1
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))
Exemplo n.º 2
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.º 3
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))
Exemplo n.º 4
0
 def setUp(self):
     self.empty_pos = Board([[None for _ in range(8)] for _ in range(8)])