Example #1
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()
Example #2
0
 def test_is_finished_true(self):
     board = PuzzleBoard(size=2, state=[[None, 1], [2, 3]])
     self.assertTrue(board.is_finished())
Example #3
0
 def test_scramble(self):
     board = PuzzleBoard(size=2)
     board.scramble()
     self.assertFalse(board.is_finished())
Example #4
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)
Example #5
0
 def test_is_finished_false(self):
     board = PuzzleBoard(size=2, state=[[1, None], [2, 3]])
     self.assertFalse(board.is_finished())