예제 #1
0
def test_actions_and_results():
    wh = Warehouse()
    # read the puzzle from the multiline string
    wh.extract_locations(puzzle_t2.split(sep='\n'))
    print(wh)
    sp = SokobanPuzzle(wh)
    print(sp.actions(wh))
예제 #2
0
def test_can_go_there():
    puzzle_t1 = '#######\n#@ $. #\n#######'
    wh = Warehouse()
    wh.extract_locations(puzzle_t1.split(sep='\n'))
    # first test
    answer = can_go_there(wh, (1, 2))
    expected_answer = True
    fcn = test_can_go_there
    print('<<  First test of {} >>'.format(fcn.__name__))
    if answer == expected_answer:
        print(fcn.__name__, ' passed!  :-)\n')
    else:
        print(fcn.__name__, ' failed!  :-(\n')
        print('Expected ')
        print(expected_answer)
        print('But, received ')
        print(answer)
    # second test
    answer = can_go_there(wh, (1, 5))
    expected_answer = False
    print('<<  Second test of {} >>'.format(fcn.__name__))
    if answer == expected_answer:
        print(fcn.__name__, ' passed!  :-)\n')
    else:
        print(fcn.__name__, ' failed!  :-(\n')
        print('Expected ')
        print(expected_answer)
        print('But, received ')
        print(answer)
예제 #3
0
def test_solve_sokoban_macro():
    wh = Warehouse()
    wh.extract_locations(puzzle_t3.split(sep='\n'))
    print(wh)
    answer = solve_sokoban_macro(wh)
    assert (answer == [((2, 3), 'Right'), ((2, 4), 'Right'), ((3, 3), 'Left'),
                       ((3, 2), 'Left')])
예제 #4
0
def test_warehouse_1():
    wh = Warehouse()
    # read the puzzle from the multiline string
    wh.extract_locations(puzzle_t2.split(sep='\n'))
    print("\nPuzzle from multiline string")
    print(wh)
    print(actions(wh))
예제 #5
0
def test_solve_sokoban_elem():
    puzzle_t1 ='#######\n#@ $. #\n#######'
    wh = Warehouse()
    wh.extract_locations(puzzle_t1.split(sep='\n'))
    # first test
    answer = solve_sokoban_elem(wh)
    expected_answer = ['Right', 'Right']
    fcn = test_solve_sokoban_elem
    print('<<  First test of {} >>'.format(fcn.__name__))
    if answer==expected_answer:
        print(fcn.__name__, ' passed!  :-)\n')
    else:
        print(fcn.__name__, ' failed!  :-(\n')
        print('Expected ');print(expected_answer)
        print('But, received ');print(answer)
    #second test
    puzzle_t2 ='#######\n#@ $ #.#\n#######'
    wh = Warehouse()
    wh.extract_locations(puzzle_t2.split(sep='\n'))
    # second test
    answer = solve_sokoban_elem(wh)
    expected_answer = ['Impossible']
    print('<<  Second test of {} >>'.format(fcn.__name__))
    if answer==expected_answer:
        print(fcn.__name__, ' passed!  :-)\n')
    else:
        print(fcn.__name__, ' failed!  :-(\n')
        print('Expected ');print(expected_answer)
        print('But, received ');print(answer)
예제 #6
0
def test_macro_search():
    wh = Warehouse()
    wh.extract_locations(puzzle_t2.split(sep='\n'))
    print(str(wh))

    goal = str(wh).replace("$", " ").replace(".", "*")

    h = lambda n: 1
    node = iterative_deepening_astar(SokobanPuzzle(str(wh), goal), h, 15)
    print(str(node))
예제 #7
0
def test_check_macro_action_seq():
    wh = Warehouse()
    wh.extract_locations(puzzle_t1.split(sep='\n'))
    print(wh)
    answer = solve_sokoban_macro(wh.copy())
    print(answer)

    print("\ntesting [((2, 3), 'Right')]")
    print( check_macro_action_seq(wh.copy(),[((2, 3), 'Right')]) )
    print("\ntesting [((2, 3), 'Left')]")
    print( check_macro_action_seq(wh.copy(), [((2, 3), 'Left')]) )
예제 #8
0
def test_solve_sokoban_elem():
#    problem_file = "./warehouses/warehouse_01.txt"
    wh = Warehouse()
#    wh.read_warehouse_file(problem_file)
    wh.extract_locations(puzzle_t1.split(sep='\n'))
    print(wh)
    print('\nElementary solution')
    answer = solve_sokoban_elem(wh)
    print(answer)
    if  answer ==  ['Right', 'Right']:
        print('Test solve_sokoban_elem passed\n')
    else:
        print('** Test solve_sokoban_elem failed\n')
예제 #9
0
def test_taboo_cells():
    wh = Warehouse()
    wh.extract_locations(puzzle_t3.split(sep='\n'))
    answer = taboo_cells(wh)
    # begin debug
    print(answer)
    print(len(answer))
    print(expected_answer_3)
    print(len(expected_answer_3))
    # end debug
    if same_multi_line_strings(answer,expected_answer_3):
        print('Test taboo_cells passed\n')
    else:
        print('** Test taboo_cells failed\n')
예제 #10
0
def test_solve_sokoban_macro():
    puzzle_t2 ='#######\n#@ $. #\n#######'
    wh = Warehouse()
    wh.extract_locations(puzzle_t2.split(sep='\n'))
    # first test
    answer=solve_sokoban_macro(wh)
    expected_answer = [((1, 3), 'Right'), ((1, 4), 'Right')]
    fcn = test_solve_sokoban_macro
    print('<<  First test of {} >>'.format(fcn.__name__))
    if answer==expected_answer:
        print(fcn.__name__, ' passed!  :-)\n')
    else:
        print(fcn.__name__, ' failed!  :-(\n')
        print('Expected ');print(expected_answer)
        print('But, received ');print(answer)
예제 #11
0
def test_my_warehouse():
    wh = Warehouse()
    # read the puzzle from the multiline string
    wh.extract_locations(puzzle_t2.split(sep='\n'))
    print(wh)

    sp = SokobanPuzzle(wh)

    print("Moving Up", sp.result(wh, "Up"))
    print("Goal Reached: ", sp.goal_test(wh))
    print("Moving Down", sp.result(wh, "Down"))
    print("Goal Reached: ", sp.goal_test(wh))
    print("Moving Down", sp.result(wh, "Down"))
    print("Goal Reached: ", sp.goal_test(wh))
    print("Moving Up", sp.result(wh, "Up"))
    print("Goal Reached: ", sp.goal_test(wh))
    print("Moving Left", sp.result(wh, "Left"))
    print("Goal Reached: ", sp.goal_test(wh))
    print("Moving Right", sp.result(wh, "Right"))
    print("Goal Reached: ", sp.goal_test(wh))
    print("Moving Right", sp.result(wh, "Right"))
    print("Goal Reached: ", sp.goal_test(wh))
예제 #12
0
def test_taboo_cells():
    wh = Warehouse()
    wh.extract_locations(puzzle_t3.split(sep='\n'))
    answer = taboo_cells(wh)
    assert (answer == expected_answer_3)
예제 #13
0
def test_taboo():
    wh = Warehouse()
    # read the puzzle from the multiline string
    wh.extract_locations(puzzle_t2.split(sep='\n'))
    print(wh)
    print(taboo_cells(wh))
예제 #14
0
def test_solve_sokoban_macro():
    wh = Warehouse()
    wh.extract_locations(puzzle_t3.split(sep='\n'))
    print(wh)
    answer = solve_sokoban_macro(wh)
    print(answer)
예제 #15
0
def test_solve_sokoban_elem():
    puzzle_t1 = '#######\n#@ $. #\n#######'
    wh = Warehouse()
    wh.extract_locations(puzzle_t1.split(sep='\n'))
    # first test
    answer = solve_sokoban_elem(wh)
    expected_answer = ['Right', 'Right']
    fcn = test_solve_sokoban_elem
    print('<<  First test of {} >>'.format(fcn.__name__))
    if answer == expected_answer:
        print(fcn.__name__, ' passed!  :-)\n')
    else:
        print(fcn.__name__, ' failed!  :-(\n')
        print('Expected ')
        print(expected_answer)
        print('But, received ')
        print(answer)
    # second test
    puzzle_t2 = '#######\n#@ $ #.#\n#######'
    wh = Warehouse()
    wh.extract_locations(puzzle_t2.split(sep='\n'))
    answer = solve_sokoban_elem(wh)
    expected_answer = ['Impossible']
    print('<<  Second test of {} >>'.format(fcn.__name__))
    if answer == expected_answer:
        print(fcn.__name__, ' passed!  :-)\n')
    else:
        print(fcn.__name__, ' failed!  :-(\n')
        print('Expected ')
        print(expected_answer)
        print('But, received ')
        print(answer)
#     third test
    wh = Warehouse()
    wh.load_warehouse("./warehouses/warehouse_01.txt")
    answer = solve_sokoban_elem(wh)
    expected_answer = [
        'Down', 'Left', 'Up', 'Right', 'Right', 'Right', 'Down', 'Left', 'Up',
        'Left', 'Left', 'Down', 'Down', 'Right', 'Up', 'Left', 'Up', 'Right',
        'Up', 'Up', 'Left', 'Down', 'Right', 'Down', 'Down', 'Right', 'Right',
        'Up', 'Left', 'Down', 'Left', 'Up', 'Up'
    ]

    fcn = test_solve_sokoban_elem
    print('<<  First test of {} >>'.format(fcn.__name__))
    if answer == expected_answer:
        print(fcn.__name__, ' passed!  :-)\n')
    else:
        print(fcn.__name__, ' failed!  :-(\n')
        print('Expected ')
        print(expected_answer)
        print('But, received ')
        print(answer)


#     4 test
    wh = Warehouse()
    wh.load_warehouse("./warehouses/warehouse_03.txt")
    answer = solve_sokoban_elem(wh)
    expected_answer = ['Right', 'Up', 'Up', 'Left', 'Left', 'Left', 'Up', \
                       'Left', 'Down', 'Right', 'Right', 'Right', 'Right', \
                       'Down', 'Down', 'Left', 'Up', 'Right', 'Up', 'Left', \
                       'Left', 'Left', 'Down', 'Down', 'Left', 'Left', 'Left', \
                       'Up', 'Up', 'Right', 'Right', 'Down', 'Right', 'Down', \
                       'Left', 'Up', 'Up', 'Up', 'Right', 'Down', 'Down']

    fcn = test_solve_sokoban_elem
    print('<<  First test of {} >>'.format(fcn.__name__))
    if answer == expected_answer:
        print(fcn.__name__, ' passed!  :-)\n')
        print('Number of moves: ', len(expected_answer))
    else:
        print(fcn.__name__, ' failed!  :-(\n')
        print('Expected (' + str(len(expected_answer)) + ' moves)')
        print(expected_answer)
        print('But, received  (' + str(len(answer)) + ' moves)')
        print(answer)

    wh = Warehouse()
    wh.load_warehouse("./warehouses/warehouse_47.txt")
    answer = solve_sokoban_elem(wh)
    expected_answer = ['Right', 'Right', 'Right', 'Up', 'Up', 'Up', 'Left', \
                       'Left', 'Down', 'Right', 'Right', 'Down', 'Down', 'Left', \
                       'Left', 'Left', 'Left', 'Up', 'Up', 'Right', 'Right', \
                       'Right', 'Up', 'Right', 'Down', 'Down', 'Up', 'Left', \
                       'Left', 'Left', 'Left', 'Down', 'Down', 'Right', 'Right', \
                       'Right', 'Right', 'Right', 'Right', 'Down', 'Right', \
                       'Right', 'Up', 'Left', 'Left', 'Left', 'Left', 'Left', \
                       'Left', 'Right', 'Right', 'Up', 'Up', 'Up', 'Right', \
                       'Right', 'Down', 'Left', 'Up', 'Left', 'Down', 'Down', \
                       'Up', 'Left', 'Left', 'Left', 'Left', 'Down', 'Down', \
                       'Down', 'Right', 'Right', 'Up', 'Right', 'Right', 'Left', \
                       'Left', 'Down', 'Left', 'Left', 'Up', 'Right', 'Right']

    fcn = test_solve_sokoban_elem
    print('<<  First test of {} >>'.format(fcn.__name__))
    if answer == expected_answer:
        print(fcn.__name__, ' passed!  :-)\n')
        print('Number of moves: ', len(expected_answer))
    else:
        print(fcn.__name__, ' failed!  :-(\n')
        print('Expected (' + str(len(expected_answer)) + ' moves)')
        print(expected_answer)
        print('But, received  (' + str(len(answer)) + ' moves)')
        print(answer)

    wh = Warehouse()
    wh.load_warehouse("./warehouses/warehouse_147.txt")
    answer = solve_sokoban_elem(wh)
    expected_answer = ['Left', 'Left', 'Left', 'Left', 'Left', 'Left', 'Down', \
                       'Down', 'Down', 'Right', 'Right', 'Up', 'Left', 'Down', \
                       'Left', 'Up', 'Up', 'Left', 'Up', 'Right', 'Right', \
                       'Right', 'Right', 'Right', 'Right', 'Down', 'Right', 'Right', \
                       'Right', 'Up', 'Up', 'Left', 'Left', 'Down', 'Left', \
                       'Left', 'Left', 'Left', 'Left', 'Left', 'Down', 'Down', \
                       'Right', 'Right', 'Right', 'Down', 'Right', 'Down', 'Down', \
                       'Left', 'Up', 'Right', 'Up', 'Left', 'Left', 'Left', 'Right', \
                       'Right', 'Down', 'Down', 'Down', 'Left', 'Left', 'Up', \
                       'Up', 'Left', 'Up', 'Up', 'Up', 'Left', 'Up', 'Right', \
                       'Right', 'Right', 'Right', 'Right', 'Right', 'Left', 'Left', \
                       'Left', 'Left', 'Left', 'Down', 'Down', 'Right', 'Right', \
                       'Down', 'Left', 'Down', 'Left', 'Up', 'Up', 'Up', 'Left', \
                       'Up', 'Right', 'Right', 'Right', 'Right', 'Right', 'Down', \
                       'Right', 'Down', 'Right', 'Right', 'Up', 'Left', 'Right', \
                       'Right', 'Up', 'Up', 'Left', 'Left', 'Down', 'Left', 'Left', \
                       'Left', 'Left', 'Left', 'Left', 'Right', 'Right', 'Right', \
                       'Right', 'Right', 'Right', 'Up', 'Right', 'Right', 'Down', \
                       'Down', 'Left', 'Down', 'Left', 'Left', 'Up', 'Right', 'Up', \
                       'Left', 'Left', 'Down', 'Right', 'Right', 'Right', 'Down',\
                       'Right', 'Up']

    fcn = test_solve_sokoban_elem
    print('<<  First test of {} >>'.format(fcn.__name__))
    if answer == expected_answer:
        print(fcn.__name__, ' passed!  :-)\n')
        print('Number of moves: ', len(expected_answer))
    else:
        print(fcn.__name__, ' failed!  :-(\n')
        print('Expected (' + str(len(expected_answer)) + ' moves)')
        print(expected_answer)
        print('But, received  (' + str(len(answer)) + ' moves)')
        print(answer)