Beispiel #1
0
# This is a simple script to automatically design a maze:
    
from vmfactory import Vmaze_NHT
from vmfactory.canvas import squares_grid

canvas = squares_grid(4,4) # nodes will be numbered 0..15
# NHT means no half-turns (can't pass a light twice in a row) 
maze = Vmaze_NHT(canvas, start = 0, goal = 15)
maze.colorize( maze.random_colors() )
maze.anneal(400,20) # optimize the maze
# maze.make_report().savefig('myreport.png')
maze.to_file('my_nice_maze.vm')
# The next script shows how to make an animation of a
# maze being optimized (requires a recent Matplotlib
# and ImageMagick): ::

import os
import networkx as nx
from matplotlib import animation
import matplotlib.pyplot as plt
from vmfactory import Vmaze_NHT
from vmfactory.canvas import stacked_cubes

input_name_format = "_tmp_evograph_%03d.vm"

G = Vmaze_NHT(**stacked_cubes())
G.start, G.goal = 0, max(G.nodes())
G.colorize(G.random_colors())

counter = 0
score = G.score
for i in range(100):
    G.improve(100, max(.1, 0.3 * (1 - 1.0 * i / 400.0)))
    if G.score != score:
        score = G.score
        G.to_file(input_name_format % counter)
        counter += 1

fig, axes = plt.subplots(1, 3, figsize=(10, 3))


def animate(nframe):
    G = Vmaze_NHT.from_file(input_name_format % nframe)
Beispiel #3
0
# This is a simple script to automatically design a maze:

from vmfactory import Vmaze_NHT
from vmfactory.canvas import squares_grid

canvas = squares_grid(4, 4)  # nodes will be numbered 0..15
# NHT means no half-turns (can't pass a light twice in a row)
maze = Vmaze_NHT(canvas, start=0, goal=15)
maze.colorize(maze.random_colors())
maze.anneal(400, 20)  # optimize the maze
# maze.make_report().savefig('myreport.png')
maze.to_file('my_nice_maze.vm')
Beispiel #4
0
# maze being optimized (requires a recent Matplotlib
# and ImageMagick): ::

import os
import networkx as nx
from matplotlib import animation
import matplotlib.pyplot as plt
from vmfactory import Vmaze_NHT
from vmfactory.canvas import stacked_cubes


input_name_format = "_tmp_evograph_%03d.vm"
 
G = Vmaze_NHT(** stacked_cubes())
G.start, G.goal = 0, max(G.nodes())
G.colorize( G.random_colors() )

counter = 0
score = G.score
for i in range(100):
    G.improve(100,max(.1,0.3*(1-1.0*i/400.0)))
    if G.score != score:
        score = G.score
        G.to_file(input_name_format%counter)
        counter += 1


fig, axes = plt.subplots(1,3, figsize=(10,3))

def animate(nframe):
    G = Vmaze_NHT.from_file(input_name_format % nframe)