# finishing point elif grid[row][column] == 3: color = BLUE # what is this? elif grid[row][column] == 4: color = YELLOW else: # set default color color = WHITE pygame.draw.rect(screen, color, [ margin + cell_width * column, margin + cell_height * row, cell_width, cell_height ]) maze = mazegen.generate_maze(HEIGHT, WIDTH) # initialize pygame pygame.init() window_size = init_window_size(maze, MARGIN, CELL_WIDTH, CELL_HEIGHT) screen = pygame.display.set_mode(window_size) # Set title of screen pygame.display.set_caption("Monkey in the Maze") done = False # close button clock = pygame.time.Clock() # how fast the screen takes to update # -------- Main Program Loop -----------
# Render a bitmap in Desmos using parallel list of colored coordinates technique # Maze prototype: https://www.desmos.com/calculator/jjj3l82fg7 import mazegen M = mazegen.M def render_bitmap(bitmap: M, filled: bool): height = len(bitmap) width = len(bitmap[0]) xlist = [] ylist = [] megalist = [] for y in range(height): desmos_y = height - 1 - y megalist.extend(map(int, bitmap[y])) for x in range(width): if bitmap[y][x] == filled: xlist.append(x) ylist.append(desmos_y) # return xlist, ylist print('u={}'.format(xlist)) print('v={}'.format(ylist)) print('m={}'.format(megalist)) render_bitmap(mazegen.generate_maze(21, 21, 3157464641), mazegen.WALL) # render_bitmap(mazegen.generate_maze(7, 7, 1337), mazegen.WALL)
nx = square_x + dx if 0 <= ny < height and 0 <= nx < width and maze[ny][ nx] != WALL and not node_visited[ny][nx]: node[ny][nx] = Node(direction, node[square_y][square_x]) visit(ny, nx) visit(*convert_to_array_coord(height, start)) steps = [] ey, ex = convert_to_array_coord(height, end) current_node = node[ey][ex] if current_node == None: print('No path :(') else: while current_node != None: steps.append(current_node.direction) current_node = current_node.prev dir_list = list(reversed(steps)) print(dir_list) l = len(steps) print('l = {}'.format(l)) # The modulo exponentiation table allows Desmos to compute the hash print('T = {}'.format(modexp_table(l))) print('T_mod = {}'.format(MODULO)) print('Flag: sdctf{{{}}}'.format(flag_hash(dir_list))) # solve(mazegen.generate_maze(21, 21, 3157464641), (0, 20), (6, 20)) # solve(mazegen.generate_maze(21, 21, 3157464641), (0, 20), (12, 20)) solve(mazegen.generate_maze(21, 21, 3157464641), (0, 20), (10, 10))
# Command line interface to generate mazes import mazegen import sys width = 12 height = 10 if len(sys.argv) >= 3: if int(sys.argv[1]) >= 3: width = int(sys.argv[1]) if int(sys.argv[2]) >= 3: height = int(sys.argv[2]) maze = mazegen.generate_maze(height, width) for row in maze: for cell in row: sys.stdout.write(2*('#' if cell.is_wall else ' ')) sys.stdout.write('\n')
def start_game(height, width, mode): global global_mode global_mode = mode solvable_maze = False while not solvable_maze: maze = mazegen.generate_maze(height, width) try: mazedoer.solve_maze(maze) solvable_maze = True except (KeyError, TypeError): pass gamemap = Map(len(maze), len(maze[0])) for i in range(len(maze)): for j in range(len(maze[i])): if maze[i][j] == 1: gamemap.createWall(i, j) if maze[i][j] == 2: player = Player(i, j, gamemap) gamemap.matrix[i][j].isPlayer = True player2 = Player(i, j, gamemap) playercomp = Player(i, j, gamemap) if maze[i][j] == 3: gamemap.createExit(i, j) if maze[i][j] == 4: gamemap.createCoin(i, j) # initialize pygame pygame.init() # init screen window_size = init_window_size(maze, margin, cell_width, cell_height) screen = pygame.display.set_mode(window_size) # Set title of screen pygame.display.set_caption("Monkey in the Maze") # not sure what's this far - not used later # TODO: remove? clock = pygame.time.Clock() # how fast the screen takes to update draw_maze(get_maze(gamemap, player, player2, playercomp), screen, cell_height, cell_width, margin) pygame.display.update() done = False move2 = -1 solution = mazedoer.ai_solve(maze) while not done: if global_mode == 8: if move2 >= 0: direction = solution[move2] if direction == "right": playercomp.move_right(gamemap) elif direction == "down": playercomp.move_down(gamemap) elif direction == "up": playercomp.move_up(gamemap) elif direction == "left": playercomp.move_left(gamemap) draw_maze(get_maze(gamemap, player, player2, playercomp), screen, cell_height, cell_width, margin) pygame.display.update() if move2 < len(solution) - 1: move2 += 1 pygame.time.wait(20) if gamemap.matrix[-2][-2].isPlayer == True: # if user gets to end done = True for event in pygame.event.get(): # User did something if event.type == pygame.QUIT: # If user clicked close done = True # Flag that we are done so we exit this loop if event.type == pygame.KEYUP: if event.key == pygame.K_ESCAPE: done = True if event.key == pygame.K_LEFT: player.move_left(gamemap) if event.key == pygame.K_RIGHT: player.move_right(gamemap) if event.key == pygame.K_UP: player.move_up(gamemap) if event.key == pygame.K_DOWN: player.move_down(gamemap) if global_mode == 2: if event.key == pygame.K_w: player2.move_up(gamemap) if event.key == pygame.K_a: player2.move_left(gamemap) if event.key == pygame.K_s: player2.move_down(gamemap) if event.key == pygame.K_d: player2.move_right(gamemap) if gamemap.matrix[-2][ -2].isPlayer == True: # if user gets to end done = True # Set the screen background draw_maze(get_maze(gamemap, player, player2, playercomp), screen, cell_height, cell_width, margin) pygame.display.update() pygame.quit()