Пример #1
0
 def test_many_obstacles(self):
     path = find_shortest_path(
         5, ['-----', '-xxx-', 'mxxxp', '-xxx-', '-----'])
     self.assertEqual(
         [('UP', 'UP', 'RIGHT', 'RIGHT', 'RIGHT', 'RIGHT', 'DOWN', 'DOWN'),
          ('DOWN', 'DOWN', 'RIGHT', 'RIGHT', 'RIGHT', 'RIGHT', 'UP', 'UP')],
         path)
Пример #2
0
 def test_many_equal_distance_case(self):
     path = find_shortest_path(3, ['m--', '---', '--p'])
     self.assertEqual([('DOWN', 'DOWN', 'RIGHT', 'RIGHT'),
                       ('DOWN', 'RIGHT', 'DOWN', 'RIGHT'),
                       ('DOWN', 'RIGHT', 'RIGHT', 'DOWN'),
                       ('RIGHT', 'DOWN', 'DOWN', 'RIGHT'),
                       ('RIGHT', 'DOWN', 'RIGHT', 'DOWN'),
                       ('RIGHT', 'RIGHT', 'DOWN', 'DOWN')], path)
Пример #3
0
def mario(n, grid):
    # Find shortest paths, create mario instance from paths and save to database
    try:
        pp = find_shortest_path(n, grid)
        new_mario = MarioModel(n, grid, pp)
        new_mario.save_to_db()
        return jsonify(pp)
    except Exception as e:
        print(e)
        return "Oops! That was not a valid grid. Try again"
Пример #4
0
def pathToPrincess_gui(glen, grid):
    grid = list([x for x in grid.split(',')])
    try:
        path = find_shortest_path(glen, grid)
        record = mario_princess_model(datetime.utcnow(), glen, str(grid),
                                      str(path))
        record.saveToDB()
    except Exception as e:
        print(e)
        return "Invalid Grid!!! Please Try again."
    return render_template('show_path.html', path=path, grid=grid, glen=glen)
Пример #5
0
def pathToPrincess(glen, grid):
    grid = list([x for x in grid.split(',')])
    try:
        path = find_shortest_path(glen, grid)
        record = mario_princess_model(datetime.utcnow(), glen, str(grid),
                                      str(path))
        record.saveToDB()
    except Exception as e:
        print(e)
        return "Invalid Grid!!! Please Try again."
    return jsonify(path)
Пример #6
0
import argparse
from app import find_shortest_path

CLI = argparse.ArgumentParser()

CLI.add_argument(
    "--glen",  # name on the CLI - drop the `--` for positional/required parameters
    nargs=1,  # 0 or more values expected => creates a list
    type=int,
    default=[3],  # default if nothing is provided
)
CLI.add_argument(
    "--grid",
    nargs='*',
    type=str,  # any type/callable can be used here
    default=['--m', '-x-', '-p-'],
)

# parse the command line
args = CLI.parse_args()
# access CLI options
map = []
for i in range(len(args.grid)):
    map.append(args.grid[i].strip("'"))

try:
    print(find_shortest_path(args.glen[0], map))
except Exception as e:
    print(e)
    print("Invalid Grid!!! Please Try again.")
Пример #7
0
 def test_basic_with_uppercase(self):
     path = find_shortest_path(3, ['--M', '-X-', '-P-'])
     self.assertEqual([('DOWN', 'DOWN', 'LEFT')], path)
Пример #8
0
 def test_basic_case(self):
     path = find_shortest_path(3, ['--m', '-x-', '-p-'])
     self.assertEqual([('DOWN', 'DOWN', 'LEFT')], path)