grid.add_car(Car('vert', 3, 10, 9)) grid.add_car(Car('vert', 2, 11, 1)) grid.add_car(Car('vert', 2, 11, 8)) grid.add_car(Car('vert', 2, 11, 10)) grid.add_car(Car('hor', 3, 7, 0)) grid.add_car(Car('hor', 2, 10, 0)) grid.add_car(Car('hor', 3, 0, 2)) grid.add_car(Car('hor', 2, 3, 2)) grid.add_car(Car('hor', 2, 7, 2)) grid.add_car(Car('hor', 2, 7, 3)) grid.add_car(Car('hor', 2, 9, 3)) grid.add_car(Car('hor', 3, 2, 4)) grid.add_car(Car('hor', 3, 7, 4)) grid.add_car(Car('hor', 3, 0, 6)) grid.add_car(Car('hor', 2, 10, 6)) grid.add_car(Car('hor', 3, 0, 7)) grid.add_car(Car('hor', 2, 4, 7)) grid.add_car(Car('hor', 2, 10, 7)) grid.add_car(Car('hor', 2, 0, 8)) grid.add_car(Car('hor', 3, 3, 8)) grid.add_car(Car('hor', 3, 7, 8)) grid.add_car(Car('hor', 3, 3, 9)) grid.add_car(Car('hor', 2, 8, 9)) grid.add_car(Car('hor', 2, 1, 11)) grid.add_car(Car('hor', 3, 3, 11)) grid.add_car(Car('hor', 2, 7, 11)) print grid.grid draw_solution([grid.grid])
# Choose if a visualisation should be made parse.add_argument('--visual', dest='visual', action='store_true') parse.set_defaults(visual=False) args = parse.parse_args(sys.argv[1:]) # Load selected config and construct grid execfile(os.getcwd() + '/configsAlt/' + str(args.config) + '.py') # Run algorithm and store return values temp = bfs(grid.grid, grid.car_list) # Construct statelist (shortest path) state_list = [] state_list.append(temp[0].grid) current_grid = temp[0].grid print len(temp[1]) while current_grid != grid.grid: temper = temp[1][str(current_grid)] state_list.append(temper) current_grid = temper # If print is passed as argument, print number of moves if args.printer: print(len(state_list) - 1) # If visual is passed as argument, draw visualisation if args.visual: draw_solution(state_list)
parse.add_argument('--config', help='config to load', default=1, type=int) parse.add_argument('--print', dest='printer', action='store_true') parse.set_defaults(printer=False) parse.add_argument('--vis', dest='visual', action='store_true') parse.set_defaults(visual=False) args = parse.parse_args(sys.argv[1:]) execfile(os.getcwd() + '/configs/' + str(args.config) + '.py') temp = bfsIter(grid) if args.printer: print(temp[0].grid) finalGrid = temp[0] mothersGrids = temp[1] stateList = [] stateList.append(finalGrid.grid) currentGrid = finalGrid while currentGrid.grid != grid.grid: stateList.append(mothersGrids[currentGrid].grid) currentGrid = mothersGrids[currentGrid] print(len(stateList)) if args.visual: draw_solution(stateList)