Ejemplo n.º 1
0
    def test_capture_piece(self):
        board = Board(tk.Toplevel())
        p1 = Pawn('white', 'white_pawn_xxx')
        p2 = Pawn('black', 'black_pawn_xxx')
        board.squares[(2, 2)]['piece'] = p1
        board.squares[(1, 1)]['piece'] = p2

        if (1, 1) in p2.get_possible_moves((2, 2), board.squares):
            board.capture_piece((1, 1))  # p2 captura p1

        self.assertEqual((), board.canvas.find_withtag(p2.name))
Ejemplo n.º 2
0
    def test_pawn_get_possible_moves(self):
        matrix = PieceTest.initialize_empty_grid()
        pawn = Pawn('black', 'black_pawn_1')
        positions = [(1, 0), (1, 7), (6, 0), (6, 7)]
        expectations = {
            (1, 0): [(2, 0, 'mov'), (3, 0, 'mov')],
            (1, 7): [(2, 7, 'mov'), (3, 7, 'mov')],
            (6, 0): [(7, 0, 'mov')],
            (6, 7): [(7, 7, 'mov')]
        }

        for pos in positions:
            possible_moves = pawn.get_possible_moves(pos, matrix)
            self.assertCountEqual(list(set(possible_moves)), expectations[pos])