def dispatcher_click(pos): global flag, flag2, MAZE, POS_NOW, EXIT, ENTRANCE pos_x, pos_y = pos if 2 <= pos_x <= 52 and 2 <= pos_y <= 38: ### 简单 MAZE, ENTRANCE, EXIT = generate_maze(11, 11) # 生成迷宫0,1数组,出入口位置坐标 pygame.draw.rect(SCREEN, COLOR_WHITE, [0, 30, 400, 400], 0) # 屏幕涂白 POS_NOW = ENTRANCE draw_maze(MAZE, ENTRANCE) # 绘制迷宫 flag = 1 flag2 = 0 elif 62 <= pos_x <= 112 and 2 <= pos_y <= 38: ### 困难 MAZE, ENTRANCE, EXIT = generate_maze(23, 23) # 生成迷宫0,1数组,出入口位置坐标 pygame.draw.rect(SCREEN, COLOR_WHITE, [0, 30, 400, 400], 0) # 屏幕涂白 POS_NOW = ENTRANCE draw_maze(MAZE, ENTRANCE) # 绘制迷宫 flag = 1 flag2 = 0 elif 122 <= pos_x <= 172 and 2 <= pos_y <= 38: ### 答案 if flag == 1: MAZE1 = solve_maze(MAZE, POS_NOW, EXIT) draw_solve(MAZE1, POS_NOW) # 绘制路径 flag2 = 1
def random_layout(seed=None): if not seed: seed = random.randint(0, 99999999) # layout = 'layouts/random%08dCapture.lay' % seed # print 'Generating random layout in %s' % layout import maze_generator return maze_generator.generate_maze(seed)
def extract_submazes(size=3, n=100, size_source_maze=20, time_limit=1000, unique_CC=False, verbose=False): start_time = time.time() maze_dict = dict() count = 0 print("Started generating Dataset with maze size: {:.0f}, timelimit: {:.0f}".format(size, time_limit)) while len(maze_dict) < n and time.time() - start_time < time_limit: count += 1 z = generate_maze(size_source_maze + 2, size_source_maze + 2) for i in range(0, size_source_maze - size): for j in range(0, size_source_maze - size): x = z[i:i + size, j:j + size] dfs_coordinates, dfs_ids, dfs_edges = run_dfs(x, unique_CC=unique_CC) if dfs_coordinates is not None: m = to_tuple(x) if m not in maze_dict: maze_dict[m] = { "dfs_coordinates": dfs_coordinates, "dfs_ids": dfs_ids, "dfs_edges": dfs_edges, } if verbose: print("Mazes explored:", count, " | SubMazes approved:", len(maze_dict)) print("Generated Dataset with maze size: {:.0f} | # Mazes: {:.0f} | Time: {:.1f}\n".format( size, len(maze_dict), time.time() - start_time) ) return maze_dict
def refresh(): global MAZE, ENTRANCE, EXIT, SOLVE_THREAD if SOLVE_THREAD is not None and SOLVE_THREAD.is_alive(): stop_thread(SOLVE_THREAD) SOLVE_THREAD = None # 生成迷宫与入口 size = random_maze_size() MAZE, ENTRANCE, EXIT = generate_maze(size, size) SOLVE_THREAD = threading.Thread(target=solve_maze, args=(MAZE, ENTRANCE, EXIT, draw_maze)) SOLVE_THREAD.start()
def main(): '''The grid are created at the start of the program and it remains the same for the entire execution''' grid = mg.generate_maze(25,25) coordinates = [] #Maze's viable coordinates for r in range(len(grid)): for c in range(len(grid[r])): if grid[r][c] == ' ': coordinates.append((r, c)) '''creo lista di agenti''' n = int(input("enter number of agents: ")) list_of_agents = [] #start = coordinates[random.randint(1, len(coordinates))] #start = (1,1) #dest = (1,1) path = [] for i in range(n): start = coordinates[random.randint(1, len(coordinates))] dest = start new_agent = Agent(start, dest, path, grid, 100) list_of_agents.append(new_agent) print(len(list_of_agents)) '''LOOP INFINITO''' meta_queue = [] while True: prob_meta = random.randint(1,10) # 10% di probabilità di generare una nuova meta meta = () if prob_meta == 1: meta = meta_generation(coordinates) meta_queue.append(meta) print(meta_queue) print("generata:", end=" ") print(meta) '''cerco fra gli agenti uno che possa accettare la nuova meta''' list_of_agents = choose_new_meta(list_of_agents, meta_queue) print("agent's capacities:") '''faccio muovere tutti gli agenti di un passo''' list_of_positions = [] list_of_destinations = [] for i in range(len(list_of_agents)): list_of_positions.append(list_of_agents[i].next_position()) #salvo tutte le successive posizioni degli agenti list_of_destinations.append(list_of_agents[i].__dest__()) print(list_of_agents[i].__cap__()) draw_agents(grid, list_of_positions, list_of_destinations) time.sleep(0.3)
def CreateRoom(): size_room = 16 size_wall = 5 maze = generate_maze() #create floor #for z in range(0, height): # for x in range(0, width): # voxel = Voxel(position=(x,0,z)) for y in range(size_wall): for i in range(0, height): for j in range(0, width): if y == 0: voxel = Voxel(position=(i, y, j)) elif (maze[i][j] == 'u'): pass elif (maze[i][j] == 'c'): pass else: voxel = Voxel(position=(i, y, j)) """
def execute(self, context): # execute() is called by blender when running the operator. # The original script maze_generator.size = bpy.context.scene.maze_size maze_generator.generate_maze() return {'FINISHED'} # this lets blender know the operator finished successfully.
def setup_grid(self): self.grid.fill_grid(generate_maze(TILE_C)) self.grid.random_exit() self.add_items()
#Pratik Jogdand #Campus ID : AD80255 import maze_generator import math maxsize = 999999 start, goal, maze, solution = maze_generator.generate_maze(4) #def addNeighbors(): def jumpsolve_bfs(a, b, maze): startState = a goalState = b jump = maze[a[0]][a[1]] p = len(maze[0]) frontier = [] frontier.append(startState) visited = [] goalState_value = maze[goalState[0]][goalState[1]] visited.append(startState) if startState == goalState: return visited else: curr_col = a[0] curr_row = a[1] curr_state = frontier[0] frontier.pop(0) while (1): #print(curr_col-jump,"curr_col-jump") if (curr_col - jump) >= 0: if (maze[curr_row][curr_col - jump]) == 0 and (
([email protected]) and Dan Klein ([email protected]). Student side autograding was added by Brad Miller, Nick Hay, and Pieter Abbeel ([email protected]). """ import sys import random import maze_generator if __name__ == "__main__": num = 9 if len(sys.argv) > 1: # command line argument: number of maps to generate num = int(sys.argv[1]) seedsfile = '../driver/SEEDS' with open(seedsfile, 'w') as out: pass for i in range(num): seed = random.randint(0, 99999999) layout = 'layouts/random%08dCapture.lay' % seed print('Generating random layout in %s' % layout) with open(layout, 'w') as out: maze = maze_generator.generate_maze(seed) out.write(maze) print(maze) with open(seedsfile, 'a') as out: out.write("%d\n" % seed)
""" This file analyses the efficiency of the MAZE GENERATION algorithm. """ import time import matplotlib.pyplot as plt from maze_generator import generate_maze if __name__ == "__main__": sizes = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 200, 300, 400] times = [] for size in sizes: start_time = time.time() image = generate_maze(size, size) end_time = time.time() - start_time times.append(end_time) plt.xlabel('Maze Size') plt.ylabel('Time Taken (s)') plt.title('Time Taken to Generate Mazes in seconds.') plt.plot(sizes, times) plt.show()
best, value, generation, pop, logbook = genetic_alg1.solve( maze, start_point, end_point, chromosome_length, mate_rate, mutation_rate, iterations, population) print(value[0]) print_maze(best) # maze_size = int(sys.argv[1]) maze_size = 60 if os.path.exists('maze' + str(maze_size) + '.npy'): maze = np.load('maze' + str(maze_size) + '.npy') else: maze = generate_maze(maze_size, maze_size) start_point = random_start_point() end_point = random_end_point() print('start point', start_point[0], start_point[1]) print('end point', end_point[0], end_point[1]) # start = time.time() # run_chromosome1(maze) # end = time.time() # print('GA1 time:', end - start) start = time.time() run_chromosome2(maze) end = time.time() print('GA1 time:', end - start)
op_direction = 'down' elif current_direction == 'down': op_direction = 'up' # if op_direction in search_result: search_result.remove(op_direction) if current_direction in search_result: search_result.remove(current_direction) for item in search_result: stack.push((current_x, current_y, item)) if __name__ == '__main__': # Use a specific size, to generate smaller or larger maze; as in: # maze = generate_maze(4, 2).splitlines() maze = generate_maze().splitlines() # Always start from the <1, 1> coordinate current_x, current_y = 1, 1 stack = Stack() # Printing the generated maze for visualizing print('\n'.join(maze)) print('Start analyzing...') print(f'Current location: <{current_y},{current_x}>') search_and_add_to_stack(current_x, current_y) print(Fore.YELLOW + f'\nStack: {stack}\n' + Style.RESET_ALL)
for button in BUTTONS: x, y, length, height = button['x'], button['y'], button[ 'length'], button['height'] pos_x, pos_y = pos if x <= pos_x <= x + length and y <= pos_y <= y + height: button['click']() def random_maze_size(): return random.randint(5, 20) * 2 + 1 if __name__ == '__main__': # 生成迷宫与入口 size = random_maze_size() MAZE, ENTRANCE, EXIT = generate_maze(size, size) SOLVE_THREAD = threading.Thread(target=solve_maze, args=(MAZE, ENTRANCE, EXIT, draw_maze)) SOLVE_THREAD.start() while True: CLOCK.tick(FPS) for event in pygame.event.get(): # 检查是否关闭窗口 if event.type == pygame.QUIT: if SOLVE_THREAD is not None and SOLVE_THREAD.is_alive(): stop_thread(SOLVE_THREAD) SOLVE_THREAD = None exit(0) elif event.type == pygame.MOUSEBUTTONDOWN: mouse_pos = pygame.mouse.get_pos() dispatcher_click(mouse_pos)