A canvas made of losanges reminding stacked cubes. To see what it looks like, type:
>>> Vmaze(** diamond() ).draw_quick()
To see what it looks like, type:
>>> Vmaze(** star() ).draw_quick()
A canvas made of losanges reminding stacked cubes. To see what it looks like, type:
>>> Vmaze(**stacked_cubes() ).draw_quick()
Generates a canvas mades of a squared grid.
Examples
>>> canvas = squares_canvas(4,4) # produces
>>> +-+-+-+
>>> | | | |
>>> +-+-+-+
>>> | | | |
>>> +-+-+-+
>>> | | | |
>>> +-+-+-+
>>> G = Vmaze_NHT(canvas, start=0, goal=15)
This function enables to draw a graph manually using Matplotlib’s interactive plotting capabilites.
In a first phase you are asked to place the nodes (left-click to place a node, right-click to remove the last node, Enter when finished). In a second phase you are asked to place the edges ( click on two nodes to select an edge, remove an edge by selecting it again, Enter when finished). To go faster in this phase you can also select an edge by clicking just one node and hitting enter, it will be assumed that the first node was the last node of the previous edge. This enables to rapidly draw “paths” of edges.
Parameters: | grid :
grid_N :
|
---|---|
Returns: | graph :
|
Examples
>>> from vmfactory.canvas import canvas_editor
>>> G = canvas_editor()
>>> vmaze = Vmaze(G, start=0, goal=1)
>>> vmaze.draw_quick() # draw with matplotlib
>>> print vmaze # print the edges, nodes positions.
>>> vmaze.to_file('mycanvas.can') # save for later use
Base Class for Viennese Mazes with the necessary methods to automatically generate mazes (initialization, optimization, drawing).
Notes that this does not implement states graph and score computation.
Refer to classes Vmaze_NHT and Vmaze_HT for directly usable classes.
For the special class of Viennese Mazes with no half-turns (meaning that you cannot pass the same light twice in a row)
Parameters: | canvas :
start :
goal :
nodes_pos :
|
---|
Examples
>>> # In this example we initialize a maze from a canvas,
>>> # optimize the colors, and generate a report.
>>> from vmfactory import Vmaze, squares_canvas
>>> canvas = squares_canvas(4,4)
>>> maze = Vmaze(canvas, start = 0, goal = 15)
>>> maze.colorize( maze.random_colors() )
>>> maze.anneal(100,20) # optimize the maze
>>> maze.make_report()
Methods
Returns the maze’s solution as a path in the state graph.
Makes the solution of Vmaze.format_solution() even more readable, as a string.
Computes a score for the maze.
This is an example of scoring function which implements a few of my favorite criteria for a good maze:
This is all very subjective and incomplete. To grow mazes according to other criteria, overwrite this function in a subclass of Vmaze.
Sets the colors of the maze’s edges.
Generates a vector of random colors for the maze.
Randomly changes some colors of the maze, each color light having a probability proba_change to be changed.
Improves the maze through random color changes.
Each traffic light has a probability proba_change of being modified to create the new maze. If the new maze has a score lower than the current maze it is dumped, otherwise it replaces the current maze.
This procedure is carried over n times.
Evolves a maze using annealing (cooldown).
For each i in 0..n-1, the method “improve()” will be called k times with a probability of mutation 1.0*(n-i)/n.
Quick drawing of the maze.
Fancy drawing of the maze.
Draws the maze with lights in a fancy way, with marks on the streets, letters instead of numbers to label the nodes (by default), etc... draw_light determines whether a circle of the corresponding color is drawn in the middle of each edge.
Draws the state graph of the maze in a fancy way.
Draws the solution of the maze in a fancy way.
Parameters: | ax :
node_size :
shift :
print_solution :
|
---|
Makes a full report of the maze (colors, graph, solution)
This is not very flexible but practical for quick scripts.
Reads a labyrinth from a file.
Saves the labyrinth to a file
Methods
Computes the states graph of the maze.
This function is useful to solve and score the maze.
Make the solution of Vmaze.solve() human-readable.
This function differs in classes Vmaze and Vmaze_NHT.
A special class of Viennese Maze in which half-turns are not allowed (you cannot go twice in a row through the same traffic light).
See Vmaze for more doc.
Methods
Computes the states maze of the graph.
Solve the maze using a recursive function.
This is slow (slower than solving using the states graph) and not very useful, but it was nice to code.