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)
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)
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)
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)
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()