Beispiel #1
0
 def test_search_scrambled(self):
     board = PuzzleBoard(size=3)
     board.scramble()
     problem = PuzzleProblem(board)
     graph_search = GraphSearch()
     solution = graph_search.search(problem)
     self.__assert_successful_actions(board, solution)
Beispiel #2
0
class PuzzleGame(Game):
    def __init__(self, size, player, scramble=True):
        self.board = PuzzleBoard(size)
        self.size = size

        if player == "user":
            self.player = PuzzlePlayerManual()
        else:
            self.player = PuzzlePlayerAgent()

        if scramble:
            self.board.scramble()

    def print_turn(self):
        print(str(self.board))

    def take_turn(self):
        action = self.player.get_action(self.board)
        self.board.move(action)

    def is_finished(self):
        return self.board.is_finished()
Beispiel #3
0
 def test_scramble_called_twice_when_first_is_finished(self):
     board = PuzzleBoard(size=2)
     mock_is_finished = mock.Mock(side_effect=[True, False])
     board.is_finished = mock_is_finished
     board.scramble()
     self.assertEqual(mock_is_finished.call_count, 2)
Beispiel #4
0
 def test_scramble(self):
     board = PuzzleBoard(size=2)
     board.scramble()
     self.assertFalse(board.is_finished())