Exemplo n.º 1
0
 def test_search_simple(self):
     board = PuzzleBoard(size=2)
     board.move("right")
     problem = PuzzleProblem(board)
     graph_search = GraphSearch()
     solution = graph_search.search(problem)
     self.__assert_successful_actions(board, solution)
Exemplo n.º 2
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)
Exemplo n.º 3
0
    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()
Exemplo n.º 4
0
 def test_move_down_already_down(self):
     board = PuzzleBoard(size=2)
     board.move("down")
     self.assertEqual(board.get_field(0, 0), 2)
     self.assertEqual(board.get_field(0, 1), None)
     board.move("down")
     self.assertEqual(board.get_field(0, 0), 2)
     self.assertEqual(board.get_field(0, 1), None)
Exemplo n.º 5
0
 def test_up(self):
     board = PuzzleBoard(size=2)
     board.move("down")
     self.assertEqual(board.get_field(0, 0), 2)
     self.assertEqual(board.get_field(0, 1), None)
     board.move("up")
     self.assertEqual(board.get_field(0, 0), None)
     self.assertEqual(board.get_field(0, 1), 2)
Exemplo n.º 6
0
 def test_move_left(self):
     board = PuzzleBoard(size=2)
     board.move("right")
     self.assertEqual(board.get_field(0, 0), 1)
     self.assertEqual(board.get_field(1, 0), None)
     board.move("left")
     self.assertEqual(board.get_field(0, 0), None)
     self.assertEqual(board.get_field(1, 0), 1)
Exemplo n.º 7
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()
Exemplo n.º 8
0
 def test_search_already_winning(self):
     board = PuzzleBoard(size=2)
     problem = PuzzleProblem(board)
     graph_search = GraphSearch()
     solution = graph_search.search(problem)
     self.__assert_successful_actions(board, solution)
Exemplo n.º 9
0
 def test_is_finished_true(self):
     board = PuzzleBoard(size=2, state=[[None, 1], [2, 3]])
     self.assertTrue(board.is_finished())
Exemplo n.º 10
0
 def test_get_none_position_3(self):
     board = PuzzleBoard(size=2, state=[[1, None], [2, 3]])
     none_position = board.get_none_position()
     self.assertEqual(none_position, (1, 0))
Exemplo n.º 11
0
 def test_get_none_position_2(self):
     board = PuzzleBoard(size=2, state=[[1, 1], [None, 3]])
     none_position = board.get_none_position()
     self.assertEqual(none_position, (0, 1))
Exemplo n.º 12
0
 def test_board_str(self):
     board = PuzzleBoard(size=2)
     self.assertEqual(board_str, board.__str__())
Exemplo n.º 13
0
 def test_initialize(self):
     board = PuzzleBoard(size=2)
     self.assertEqual(board.get_field(0, 0), None)
     self.assertEqual(board.get_field(1, 0), 1)
     self.assertEqual(board.get_field(0, 1), 2)
     self.assertEqual(board.get_field(1, 1), 3)
Exemplo n.º 14
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)
Exemplo n.º 15
0
 def test_scramble(self):
     board = PuzzleBoard(size=2)
     board.scramble()
     self.assertFalse(board.is_finished())
Exemplo n.º 16
0
 def test_is_finished_false(self):
     board = PuzzleBoard(size=2, state=[[1, None], [2, 3]])
     self.assertFalse(board.is_finished())