Esempio n. 1
0
 def get_sokoban_moves(layer, player_position, current_node, positions_map):
     sokoban_key_position, sokoban_lock_position = Solver.get_sokoban_key_and_lock(
         layer, current_node, positions_map)
     if sokoban_key_position is not None:
         sokoban_moves = SokobanSolver.is_sokoban_solvable(
             layer,
             player_position,
             sokoban_key_position,
             sokoban_lock_position,
             return_type="moves")
         return True, sokoban_moves
     else:
         return False, None
    def test_sokoban_solver_cant_reach_push(self):
        layer = np.array([[w, w, w, w, w, w, w, w], [w, g, s, e, b, e, e, w],
                          [w, w, w, w, w, w, w, w]],
                         dtype=object)

        player_position = np.array([1, 2])
        sokoban_key = np.array([1, 4])
        sokoban_lock = np.array([1, 1])
        is_solvable = SokobanSolver.is_sokoban_solvable(layer,
                                                        player_position,
                                                        sokoban_key,
                                                        sokoban_lock,
                                                        return_type="moves")
        self.assertFalse(is_solvable)
    def test_sokoban_player_on_goal(self):
        layer = np.array([[w, w, w, w, w, w, w], [w, e, e, e, e, e, w],
                          [w, e, b, s, e, w, w], [w, e, e, e, e, e, w],
                          [w, w, w, w, w, w, w]],
                         dtype=object)

        player_position = np.array([2, 3])
        sokoban_key = np.array([2, 2])
        sokoban_lock = np.array([2, 3])
        is_solvable = SokobanSolver.is_sokoban_solvable(layer,
                                                        player_position,
                                                        sokoban_key,
                                                        sokoban_lock,
                                                        return_type="moves")
        self.assertTrue(is_solvable)
    def test_sokoban_solver_no_space(self):
        layer = np.array([[w, w, w, w, w, w, w, w], [w, e, e, e, e, e, g, w],
                          [w, e, s, e, b, e, e, w], [w, w, e, w, w, w, w, w],
                          [w, w, w, w, w, w, w, w]],
                         dtype=object)

        player_position = np.array([2, 2])
        sokoban_key = np.array([2, 4])
        sokoban_lock = np.array([1, 6])
        is_solvable = SokobanSolver.is_sokoban_solvable(layer,
                                                        player_position,
                                                        sokoban_key,
                                                        sokoban_lock,
                                                        return_type="moves")
        self.assertFalse(is_solvable)