Building#
You can use variables to write programs that build
mazes!
You can draw the map and play with your own mazes.
The symbols (to be separated by spaces):
o un mur
. une case vide
↑ → ↓ ← la fourmi
x la porte
r un caillou
R un caillou aléatoire
w une toile
W une toile aléatoire
from laby.global_fr import *
carte ="""
o o o o o o o o
o . . . r o w x
o . o o . o . o
o ↑ . . . . . o
o o o o o o o o
"""
Laby(carte = carte)
debut()
A maze can be created from a character string.
In Python, strings can be stored in variables, added, multiplied…
c = ". "
print(c)
.
deux_c = c + c
print(deux_c)
. .
ligne = c * 10
print(ligne)
. . . . . . . . . .
To put two lines in a row, you have to separate them by the carriage return
character \n
deux_lignes = ligne + "\n" + ligne
print(deux_lignes)
. . . . . . . . . .
. . . . . . . . . .
What does the following program do?
murs = "o " * 12 + "\n"
ligne = "o " + ". " * 10 + "o \n"
carte = murs + ligne * 10 + murs
print(carte)
o o o o o o o o o o o o
o . . . . . . . . . . o
o . . . . . . . . . . o
o . . . . . . . . . . o
o . . . . . . . . . . o
o . . . . . . . . . . o
o . . . . . . . . . . o
o . . . . . . . . . . o
o . . . . . . . . . . o
o . . . . . . . . . . o
o . . . . . . . . . . o
o o o o o o o o o o o o
This map is incorrect because it does not contain an ant or a door.
Copy the program and modify it to add the ant and the door. Then launch the
“real” maze with the command Laby(carte = carte)
You can use all the previous concepts (loops, if statements, variables, functions,
etc.) to build mazes and not just solve them.
Can you make a zigzag?
A spiral?
A checkerboard?
A shape of your choice?