SlideShare a Scribd company logo
1) Introduction:
This practical work consists of developing a set of definitions
of functions which make it
possible to generate mazes and draw them using the turtle.
In this work, you have to imagine that you are the programmer
of a library that allows
you to generate labyrinths. You must write functions that will
be used by other
programmers to make specific drawings. (create a labyrinth of a
certain size).
The algorithm for generating mazes is imposed on you and is
described in the next
section. Your task is to code this algorithm, and the necessary
helper functions, in
Python using Turtle.
2) Labyrinths
The mazes you need to generate are based on a rectangular grid
like this:
This grid is made up of square cells. In this example there are 8
columns and 4 rows of
cells. For a given cell there are 4 walls that we will call the
North, East, South, and West
walls (to simplify  N ",  E",  S ",  O") of the cell. A labyrinth
has a certain width in
number of cells (NX), a certain height in number of cells (NY),
and a certain “step”(the
width and height of each square cell, in number of pixels). The
labyrinth is therefore
created by eliminating certain walls from the grid. The outer
wall of the grid is drilled at
the top left (the entrance to the labyrinth) and lower right (the
exit from the labyrinth).
The creation of a labyrinth consists of determining which walls
in each cell need to be
removed. For each cell it is necessary to eliminate at least one
of its 4 walls, and
possibly all 4. Here is a labyrinth using the previous grid (i.e.
with NX = 8, NY = 4, step =
40):
The choice of the walls to eliminate cannot be done completely
randomly because this
could generate a drawing. which is not a labyrinth, that is to say
a drawing which does
not follow a path from the entrance to the exit. The algorithm
you should use uses
random numbers to create the maze but ensures that there
always is exactly one path
between entering and exiting the maze. In fact, the algorithm
guarantees that there is
always exactly one path between any cell and any other cell
(what is formally called
an underlying tree). Before explaining the algorithm we must
first number each
horizontal wall and each vertical wall and give a coordinate (x,
y) to each cell as follows:
It should be noted that the coordinate system (x, y) of the cells
places (0,0) at the top
left (x grows towards the right, and grows down there). Also
notice that there are NX
(NY + 1) horizontal walls and (NX + 1) NY vertical walls. So
the horizontal walls are
numbered from 0 to (NX (NY + 1)) 1 and the vertical walls
from 0 to ((NX + 1) NY) 1.
The relation between the (x, y) coordinate of a cell and the
numbers of its walls N, E, S,
O is the next one :
N = x + y x NX
E = 1 + x + y  x (NX + 1)
S = x + (y + 1)  x NX
O = x + y  x (NX + 1)
Note that the wall number N can be used to uniquely identify a
cell with
only one number. For example in the grid above the cell in
position (5,2) has the number
21, that is to say 5 + 2 NX.
The algorithm uses sets of numbers (in the mathematical sense
of a set, i.e. a collection
of numbers without duplication). We can define wallsH as the
set of horizontal walls
(and respectively wallsv as the set of vertical walls) which have
not been removed by
the maze creation algorithm. The information contained in these
sets can be combined
with the values of NX and NY to draw a labyrinth by tracing a
horizontal line for each
horizontal wall whose number is always in wallsH and a vertical
line for each vertical
wall whose number is always in wallsv.
The algorithm considers that the grid is an initially full space
except for a randomly
chosen cell, which is empty (this is the initial cavity). At each
iteration of the algorithm a
new cell will be chosen randomly among all the cells
neighboring the cavity (but not
forming part of the cavity) and one of the walls (i.e. horizontal
or vertical) which
separates it from the cavity will be removed randomly to form a
larger cavity (i.e. from
the whole wallsH if it is a horizontal wall or of the wallsv
assembly if it is a vertical wall).
This process is repeated until all the cells of the grid are part of
the cavity.
The choice of the next cell to add to the cavity can be done
simply by keeping at all
times two other sets of numbers: cellar and front. These are sets
that contain cell
numbers. The cellar set is the set of cells that have been put into
the cavity by the
algorithm. The forehead set is the set of cells that are
neighboring cells in the cavity (but
not in the cavity). We can maintain and update these sets as new
cells that are selected
to add to the cavity. Indeed if we have add to the cavity the
cells with coordinates (x, y)
contained in the front set, we must add the neighboring cells
with coordinates (x, y)
horizontally and vertically (but not in the cellar assembly) a the
front assembly and
remove the cell (x, y) of the front set and add the cell (x, y) to
the cellar set. Note that
we must remove or add from these sets the number of cells.
The coding of this algorithm will be greatly simplified by the
writing of set manipulation
functions. These functions are described in the next section. Use
them judiciously to
code the algorithm labyrinth creation. We will use lists of
numbers to represent sets. For
example the table [9,2,5] represents the set which contains the
three elements 2, 5 and
9.
3) Specifications:
Function Iota (n):
This function takes a non-negative integer n as parameter and
returns an array of length
n containing in order the integer values from 0 to n 1
inclusive. For example :
iota(5) = [0,1,2,3,4]
Function contain(tab,x):
This function takes as parameters an array of numbers (tab) and
a number x and
returns a boolean indicating if x is contained in the array by
traversing this array with a
loop (not the right to use the keyword in).
For example :
contain([9,2,5], 2) = True
contain([9,2,5], 7) = False
Function add(tab,x):
This function takes an array of numbers (tab) and a number x as
parameters and
returns a new array with the same content as tab except that x is
appended to the end if
it is not already contained in tab. For example :
add([9,2,5], 2) = [9,2,5]
add([9,2,5], 7) = [9,2,5,7]
Function remove(tab,x):
This function takes an array of numbers (tab) and a number x as
parameters and
returns a new array with the same contents as tab except that x
is removed from the
array. For example :
remove([9,2,5], 2) = [9,5]
remove([9,2,5], 7) = [9,2,5]
Function neighbors(x,y,nx,ny):
This function takes the coordinate (x, y) of a cell and the size of
a grid (width = nx and
height = ny) and returns an array containing the number of
neighboring cells. For
example :
neighbors(7, 2, 8, 4) = [15,22,31]
Function laby(nx,ny, step):
This procedure creates a random maze (width = nx and height =
ny) and draws this
maze in the center of the drawing window using a grid with
cells of pixel pitch width and
height. For example, here are two laby calls and the drawings
obtained in each case:
20% bonus points for the implementation of the labySol
procedure (nx, ny, pas) which
draws a labyrinth exactly like the laby procedure but which in
addition draws in the
labyrinth, in red, the path
traversed by Pledge's algorithm to exit the labyrinth from the
top left entrance.

More Related Content

Similar to 1) IntroductionThis practical work consists of developing

Final
FinalFinal
MATLABgraphPlotting.pptx
MATLABgraphPlotting.pptxMATLABgraphPlotting.pptx
MATLABgraphPlotting.pptx
PrabhakarSingh646829
 
Find the shortest route through a maze using linking and linked list.pdf
Find the shortest route through a maze using linking and linked list.pdfFind the shortest route through a maze using linking and linked list.pdf
Find the shortest route through a maze using linking and linked list.pdf
sanuoptical
 
Data transformation-cheatsheet
Data transformation-cheatsheetData transformation-cheatsheet
Data transformation-cheatsheet
Dieudonne Nahigombeye
 
Javascript Array map method
Javascript Array map methodJavascript Array map method
Javascript Array map method
tanerochris
 
Scala collection
Scala collectionScala collection
Scala collection
Knoldus Inc.
 
21EC33 BSP Module 1.pdf
21EC33 BSP Module 1.pdf21EC33 BSP Module 1.pdf
21EC33 BSP Module 1.pdf
Ravikiran A
 
Lesson 4
Lesson 4Lesson 4
Lesson 4
Vinnu Vinay
 
Introduction to Matlab - Basic Functions
Introduction to Matlab - Basic FunctionsIntroduction to Matlab - Basic Functions
Introduction to Matlab - Basic Functions
joellivz
 
Dancing Links: an educational pearl
Dancing Links: an educational pearlDancing Links: an educational pearl
Dancing Links: an educational pearl
ESUG
 
WEEK-1.pdf
WEEK-1.pdfWEEK-1.pdf
WEEK-1.pdf
YASHWANTHMK4
 
introduction_dst.pptx
introduction_dst.pptxintroduction_dst.pptx
introduction_dst.pptx
HammadTariq51
 
Introducing scala
Introducing scalaIntroducing scala
Introducing scala
Meetu Maltiar
 
14078956.ppt
14078956.ppt14078956.ppt
14078956.ppt
Sivam Chinna
 
Sparse autoencoder
Sparse autoencoderSparse autoencoder
Sparse autoencoder
Devashish Patel
 
Scala Bootcamp 1
Scala Bootcamp 1Scala Bootcamp 1
Scala Bootcamp 1
Knoldus Inc.
 
Svm Presentation
Svm PresentationSvm Presentation
Svm Presentation
shahparin
 
Scilab for real dummies j.heikell - part 2
Scilab for real dummies j.heikell - part 2Scilab for real dummies j.heikell - part 2
Scilab for real dummies j.heikell - part 2
Scilab
 
Array Presentation
Array PresentationArray Presentation
Array Presentation
Deep Prajapati Microplacer
 
8 neural network representation
8 neural network representation8 neural network representation
8 neural network representation
TanmayVijay1
 

Similar to 1) IntroductionThis practical work consists of developing (20)

Final
FinalFinal
Final
 
MATLABgraphPlotting.pptx
MATLABgraphPlotting.pptxMATLABgraphPlotting.pptx
MATLABgraphPlotting.pptx
 
Find the shortest route through a maze using linking and linked list.pdf
Find the shortest route through a maze using linking and linked list.pdfFind the shortest route through a maze using linking and linked list.pdf
Find the shortest route through a maze using linking and linked list.pdf
 
Data transformation-cheatsheet
Data transformation-cheatsheetData transformation-cheatsheet
Data transformation-cheatsheet
 
Javascript Array map method
Javascript Array map methodJavascript Array map method
Javascript Array map method
 
Scala collection
Scala collectionScala collection
Scala collection
 
21EC33 BSP Module 1.pdf
21EC33 BSP Module 1.pdf21EC33 BSP Module 1.pdf
21EC33 BSP Module 1.pdf
 
Lesson 4
Lesson 4Lesson 4
Lesson 4
 
Introduction to Matlab - Basic Functions
Introduction to Matlab - Basic FunctionsIntroduction to Matlab - Basic Functions
Introduction to Matlab - Basic Functions
 
Dancing Links: an educational pearl
Dancing Links: an educational pearlDancing Links: an educational pearl
Dancing Links: an educational pearl
 
WEEK-1.pdf
WEEK-1.pdfWEEK-1.pdf
WEEK-1.pdf
 
introduction_dst.pptx
introduction_dst.pptxintroduction_dst.pptx
introduction_dst.pptx
 
Introducing scala
Introducing scalaIntroducing scala
Introducing scala
 
14078956.ppt
14078956.ppt14078956.ppt
14078956.ppt
 
Sparse autoencoder
Sparse autoencoderSparse autoencoder
Sparse autoencoder
 
Scala Bootcamp 1
Scala Bootcamp 1Scala Bootcamp 1
Scala Bootcamp 1
 
Svm Presentation
Svm PresentationSvm Presentation
Svm Presentation
 
Scilab for real dummies j.heikell - part 2
Scilab for real dummies j.heikell - part 2Scilab for real dummies j.heikell - part 2
Scilab for real dummies j.heikell - part 2
 
Array Presentation
Array PresentationArray Presentation
Array Presentation
 
8 neural network representation
8 neural network representation8 neural network representation
8 neural network representation
 

More from AbbyWhyte974

1. Use Postman” to test API at  httpspostman-echo.coma. Use
1. Use Postman” to test API at  httpspostman-echo.coma. Use1. Use Postman” to test API at  httpspostman-echo.coma. Use
1. Use Postman” to test API at  httpspostman-echo.coma. Use
AbbyWhyte974
 
1. Use the rubric to complete the assignment and pay attention t
1. Use the rubric to complete the assignment and pay attention t1. Use the rubric to complete the assignment and pay attention t
1. Use the rubric to complete the assignment and pay attention t
AbbyWhyte974
 
1. True or false. Unlike a merchandising business, a manufacturing
1. True or false. Unlike a merchandising business, a manufacturing1. True or false. Unlike a merchandising business, a manufacturing
1. True or false. Unlike a merchandising business, a manufacturing
AbbyWhyte974
 
1. Top hedge fund manager Sally Buffit believes that a stock with
1. Top hedge fund manager Sally Buffit believes that a stock with 1. Top hedge fund manager Sally Buffit believes that a stock with
1. Top hedge fund manager Sally Buffit believes that a stock with
AbbyWhyte974
 
1. This question is on the application of the Binomial option
1. This question is on the application of the Binomial option1. This question is on the application of the Binomial option
1. This question is on the application of the Binomial option
AbbyWhyte974
 
1. Tiktaalik httpswww.palaeocast.comtiktaalikW
1. Tiktaalik        httpswww.palaeocast.comtiktaalikW1. Tiktaalik        httpswww.palaeocast.comtiktaalikW
1. Tiktaalik httpswww.palaeocast.comtiktaalikW
AbbyWhyte974
 
1. This week, we learned about the balanced scorecard and dashboar
1. This week, we learned about the balanced scorecard and dashboar1. This week, we learned about the balanced scorecard and dashboar
1. This week, we learned about the balanced scorecard and dashboar
AbbyWhyte974
 
1. The company I chose was Amazon2.3.4.1) Keep i
1. The company I chose was Amazon2.3.4.1) Keep i1. The company I chose was Amazon2.3.4.1) Keep i
1. The company I chose was Amazon2.3.4.1) Keep i
AbbyWhyte974
 
1. Think about a persuasive speech that you would like to present
1. Think about a persuasive speech that you would like to present 1. Think about a persuasive speech that you would like to present
1. Think about a persuasive speech that you would like to present
AbbyWhyte974
 
1. The two properties about a set of measurements of a dependent v
1. The two properties about a set of measurements of a dependent v1. The two properties about a set of measurements of a dependent v
1. The two properties about a set of measurements of a dependent v
AbbyWhyte974
 
1. The Danube River flows through 10 countries. Name them in the s
1. The Danube River flows through 10 countries. Name them in the s1. The Danube River flows through 10 countries. Name them in the s
1. The Danube River flows through 10 countries. Name them in the s
AbbyWhyte974
 
1. The 3 genes that you will compare at listed below. Take a look.
1. The 3 genes that you will compare at listed below. Take a look.1. The 3 genes that you will compare at listed below. Take a look.
1. The 3 genes that you will compare at listed below. Take a look.
AbbyWhyte974
 
1. Student and trainer detailsStudent details Full nameStu
1. Student and trainer detailsStudent details  Full nameStu1. Student and trainer detailsStudent details  Full nameStu
1. Student and trainer detailsStudent details Full nameStu
AbbyWhyte974
 
1. Student uses MS Excel to calculate income tax expense or refund
1. Student uses MS Excel to calculate income tax expense or refund1. Student uses MS Excel to calculate income tax expense or refund
1. Student uses MS Excel to calculate income tax expense or refund
AbbyWhyte974
 
1. Socrates - In your view, what was it about Socrates’ teachings
1. Socrates - In your view, what was it about Socrates’ teachings 1. Socrates - In your view, what was it about Socrates’ teachings
1. Socrates - In your view, what was it about Socrates’ teachings
AbbyWhyte974
 
1. Select a patient” (friend or family member) on whom to perform
1. Select a patient” (friend or family member) on whom to perform1. Select a patient” (friend or family member) on whom to perform
1. Select a patient” (friend or family member) on whom to perform
AbbyWhyte974
 
1. Respond to your classmates’ question and post. Submission to y
1. Respond to your classmates’ question and post.  Submission to y1. Respond to your classmates’ question and post.  Submission to y
1. Respond to your classmates’ question and post. Submission to y
AbbyWhyte974
 
1. Review the HCAPHS survey document, by clicking on the hyperlink
1. Review the HCAPHS survey document, by clicking on the hyperlink1. Review the HCAPHS survey document, by clicking on the hyperlink
1. Review the HCAPHS survey document, by clicking on the hyperlink
AbbyWhyte974
 
1. Saint Leo Portal loginUser ID[email protected]
1. Saint Leo Portal loginUser ID[email protected]          1. Saint Leo Portal loginUser ID[email protected]
1. Saint Leo Portal loginUser ID[email protected]
AbbyWhyte974
 
1. Reference is ch. 5 in the e-text, or ch. 2 in paper text...plea
1. Reference is ch. 5 in the e-text, or ch. 2 in paper text...plea1. Reference is ch. 5 in the e-text, or ch. 2 in paper text...plea
1. Reference is ch. 5 in the e-text, or ch. 2 in paper text...plea
AbbyWhyte974
 

More from AbbyWhyte974 (20)

1. Use Postman” to test API at  httpspostman-echo.coma. Use
1. Use Postman” to test API at  httpspostman-echo.coma. Use1. Use Postman” to test API at  httpspostman-echo.coma. Use
1. Use Postman” to test API at  httpspostman-echo.coma. Use
 
1. Use the rubric to complete the assignment and pay attention t
1. Use the rubric to complete the assignment and pay attention t1. Use the rubric to complete the assignment and pay attention t
1. Use the rubric to complete the assignment and pay attention t
 
1. True or false. Unlike a merchandising business, a manufacturing
1. True or false. Unlike a merchandising business, a manufacturing1. True or false. Unlike a merchandising business, a manufacturing
1. True or false. Unlike a merchandising business, a manufacturing
 
1. Top hedge fund manager Sally Buffit believes that a stock with
1. Top hedge fund manager Sally Buffit believes that a stock with 1. Top hedge fund manager Sally Buffit believes that a stock with
1. Top hedge fund manager Sally Buffit believes that a stock with
 
1. This question is on the application of the Binomial option
1. This question is on the application of the Binomial option1. This question is on the application of the Binomial option
1. This question is on the application of the Binomial option
 
1. Tiktaalik httpswww.palaeocast.comtiktaalikW
1. Tiktaalik        httpswww.palaeocast.comtiktaalikW1. Tiktaalik        httpswww.palaeocast.comtiktaalikW
1. Tiktaalik httpswww.palaeocast.comtiktaalikW
 
1. This week, we learned about the balanced scorecard and dashboar
1. This week, we learned about the balanced scorecard and dashboar1. This week, we learned about the balanced scorecard and dashboar
1. This week, we learned about the balanced scorecard and dashboar
 
1. The company I chose was Amazon2.3.4.1) Keep i
1. The company I chose was Amazon2.3.4.1) Keep i1. The company I chose was Amazon2.3.4.1) Keep i
1. The company I chose was Amazon2.3.4.1) Keep i
 
1. Think about a persuasive speech that you would like to present
1. Think about a persuasive speech that you would like to present 1. Think about a persuasive speech that you would like to present
1. Think about a persuasive speech that you would like to present
 
1. The two properties about a set of measurements of a dependent v
1. The two properties about a set of measurements of a dependent v1. The two properties about a set of measurements of a dependent v
1. The two properties about a set of measurements of a dependent v
 
1. The Danube River flows through 10 countries. Name them in the s
1. The Danube River flows through 10 countries. Name them in the s1. The Danube River flows through 10 countries. Name them in the s
1. The Danube River flows through 10 countries. Name them in the s
 
1. The 3 genes that you will compare at listed below. Take a look.
1. The 3 genes that you will compare at listed below. Take a look.1. The 3 genes that you will compare at listed below. Take a look.
1. The 3 genes that you will compare at listed below. Take a look.
 
1. Student and trainer detailsStudent details Full nameStu
1. Student and trainer detailsStudent details  Full nameStu1. Student and trainer detailsStudent details  Full nameStu
1. Student and trainer detailsStudent details Full nameStu
 
1. Student uses MS Excel to calculate income tax expense or refund
1. Student uses MS Excel to calculate income tax expense or refund1. Student uses MS Excel to calculate income tax expense or refund
1. Student uses MS Excel to calculate income tax expense or refund
 
1. Socrates - In your view, what was it about Socrates’ teachings
1. Socrates - In your view, what was it about Socrates’ teachings 1. Socrates - In your view, what was it about Socrates’ teachings
1. Socrates - In your view, what was it about Socrates’ teachings
 
1. Select a patient” (friend or family member) on whom to perform
1. Select a patient” (friend or family member) on whom to perform1. Select a patient” (friend or family member) on whom to perform
1. Select a patient” (friend or family member) on whom to perform
 
1. Respond to your classmates’ question and post. Submission to y
1. Respond to your classmates’ question and post.  Submission to y1. Respond to your classmates’ question and post.  Submission to y
1. Respond to your classmates’ question and post. Submission to y
 
1. Review the HCAPHS survey document, by clicking on the hyperlink
1. Review the HCAPHS survey document, by clicking on the hyperlink1. Review the HCAPHS survey document, by clicking on the hyperlink
1. Review the HCAPHS survey document, by clicking on the hyperlink
 
1. Saint Leo Portal loginUser ID[email protected]
1. Saint Leo Portal loginUser ID[email protected]          1. Saint Leo Portal loginUser ID[email protected]
1. Saint Leo Portal loginUser ID[email protected]
 
1. Reference is ch. 5 in the e-text, or ch. 2 in paper text...plea
1. Reference is ch. 5 in the e-text, or ch. 2 in paper text...plea1. Reference is ch. 5 in the e-text, or ch. 2 in paper text...plea
1. Reference is ch. 5 in the e-text, or ch. 2 in paper text...plea
 

Recently uploaded

Walmart Business+ and Spark Good for Nonprofits.pdf
Walmart Business+ and Spark Good for Nonprofits.pdfWalmart Business+ and Spark Good for Nonprofits.pdf
Walmart Business+ and Spark Good for Nonprofits.pdf
TechSoup
 
How to Build a Module in Odoo 17 Using the Scaffold Method
How to Build a Module in Odoo 17 Using the Scaffold MethodHow to Build a Module in Odoo 17 Using the Scaffold Method
How to Build a Module in Odoo 17 Using the Scaffold Method
Celine George
 
What is Digital Literacy? A guest blog from Andy McLaughlin, University of Ab...
What is Digital Literacy? A guest blog from Andy McLaughlin, University of Ab...What is Digital Literacy? A guest blog from Andy McLaughlin, University of Ab...
What is Digital Literacy? A guest blog from Andy McLaughlin, University of Ab...
GeorgeMilliken2
 
The History of Stoke Newington Street Names
The History of Stoke Newington Street NamesThe History of Stoke Newington Street Names
The History of Stoke Newington Street Names
History of Stoke Newington
 
ANATOMY AND BIOMECHANICS OF HIP JOINT.pdf
ANATOMY AND BIOMECHANICS OF HIP JOINT.pdfANATOMY AND BIOMECHANICS OF HIP JOINT.pdf
ANATOMY AND BIOMECHANICS OF HIP JOINT.pdf
Priyankaranawat4
 
Chapter 4 - Islamic Financial Institutions in Malaysia.pptx
Chapter 4 - Islamic Financial Institutions in Malaysia.pptxChapter 4 - Islamic Financial Institutions in Malaysia.pptx
Chapter 4 - Islamic Financial Institutions in Malaysia.pptx
Mohd Adib Abd Muin, Senior Lecturer at Universiti Utara Malaysia
 
DRUGS AND ITS classification slide share
DRUGS AND ITS classification slide shareDRUGS AND ITS classification slide share
DRUGS AND ITS classification slide share
taiba qazi
 
writing about opinions about Australia the movie
writing about opinions about Australia the moviewriting about opinions about Australia the movie
writing about opinions about Australia the movie
Nicholas Montgomery
 
clinical examination of hip joint (1).pdf
clinical examination of hip joint (1).pdfclinical examination of hip joint (1).pdf
clinical examination of hip joint (1).pdf
Priyankaranawat4
 
The simplified electron and muon model, Oscillating Spacetime: The Foundation...
The simplified electron and muon model, Oscillating Spacetime: The Foundation...The simplified electron and muon model, Oscillating Spacetime: The Foundation...
The simplified electron and muon model, Oscillating Spacetime: The Foundation...
RitikBhardwaj56
 
South African Journal of Science: Writing with integrity workshop (2024)
South African Journal of Science: Writing with integrity workshop (2024)South African Journal of Science: Writing with integrity workshop (2024)
South African Journal of Science: Writing with integrity workshop (2024)
Academy of Science of South Africa
 
How to Setup Warehouse & Location in Odoo 17 Inventory
How to Setup Warehouse & Location in Odoo 17 InventoryHow to Setup Warehouse & Location in Odoo 17 Inventory
How to Setup Warehouse & Location in Odoo 17 Inventory
Celine George
 
Digital Artifact 1 - 10VCD Environments Unit
Digital Artifact 1 - 10VCD Environments UnitDigital Artifact 1 - 10VCD Environments Unit
Digital Artifact 1 - 10VCD Environments Unit
chanes7
 
BÀI TẬP BỔ TRỢ TIẾNG ANH 8 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2023-2024 (CÓ FI...
BÀI TẬP BỔ TRỢ TIẾNG ANH 8 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2023-2024 (CÓ FI...BÀI TẬP BỔ TRỢ TIẾNG ANH 8 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2023-2024 (CÓ FI...
BÀI TẬP BỔ TRỢ TIẾNG ANH 8 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2023-2024 (CÓ FI...
Nguyen Thanh Tu Collection
 
বাংলাদেশ অর্থনৈতিক সমীক্ষা (Economic Review) ২০২৪ UJS App.pdf
বাংলাদেশ অর্থনৈতিক সমীক্ষা (Economic Review) ২০২৪ UJS App.pdfবাংলাদেশ অর্থনৈতিক সমীক্ষা (Economic Review) ২০২৪ UJS App.pdf
বাংলাদেশ অর্থনৈতিক সমীক্ষা (Economic Review) ২০২৪ UJS App.pdf
eBook.com.bd (প্রয়োজনীয় বাংলা বই)
 
Main Java[All of the Base Concepts}.docx
Main Java[All of the Base Concepts}.docxMain Java[All of the Base Concepts}.docx
Main Java[All of the Base Concepts}.docx
adhitya5119
 
Your Skill Boost Masterclass: Strategies for Effective Upskilling
Your Skill Boost Masterclass: Strategies for Effective UpskillingYour Skill Boost Masterclass: Strategies for Effective Upskilling
Your Skill Boost Masterclass: Strategies for Effective Upskilling
Excellence Foundation for South Sudan
 
Pengantar Penggunaan Flutter - Dart programming language1.pptx
Pengantar Penggunaan Flutter - Dart programming language1.pptxPengantar Penggunaan Flutter - Dart programming language1.pptx
Pengantar Penggunaan Flutter - Dart programming language1.pptx
Fajar Baskoro
 
BBR 2024 Summer Sessions Interview Training
BBR  2024 Summer Sessions Interview TrainingBBR  2024 Summer Sessions Interview Training
BBR 2024 Summer Sessions Interview Training
Katrina Pritchard
 
Cognitive Development Adolescence Psychology
Cognitive Development Adolescence PsychologyCognitive Development Adolescence Psychology
Cognitive Development Adolescence Psychology
paigestewart1632
 

Recently uploaded (20)

Walmart Business+ and Spark Good for Nonprofits.pdf
Walmart Business+ and Spark Good for Nonprofits.pdfWalmart Business+ and Spark Good for Nonprofits.pdf
Walmart Business+ and Spark Good for Nonprofits.pdf
 
How to Build a Module in Odoo 17 Using the Scaffold Method
How to Build a Module in Odoo 17 Using the Scaffold MethodHow to Build a Module in Odoo 17 Using the Scaffold Method
How to Build a Module in Odoo 17 Using the Scaffold Method
 
What is Digital Literacy? A guest blog from Andy McLaughlin, University of Ab...
What is Digital Literacy? A guest blog from Andy McLaughlin, University of Ab...What is Digital Literacy? A guest blog from Andy McLaughlin, University of Ab...
What is Digital Literacy? A guest blog from Andy McLaughlin, University of Ab...
 
The History of Stoke Newington Street Names
The History of Stoke Newington Street NamesThe History of Stoke Newington Street Names
The History of Stoke Newington Street Names
 
ANATOMY AND BIOMECHANICS OF HIP JOINT.pdf
ANATOMY AND BIOMECHANICS OF HIP JOINT.pdfANATOMY AND BIOMECHANICS OF HIP JOINT.pdf
ANATOMY AND BIOMECHANICS OF HIP JOINT.pdf
 
Chapter 4 - Islamic Financial Institutions in Malaysia.pptx
Chapter 4 - Islamic Financial Institutions in Malaysia.pptxChapter 4 - Islamic Financial Institutions in Malaysia.pptx
Chapter 4 - Islamic Financial Institutions in Malaysia.pptx
 
DRUGS AND ITS classification slide share
DRUGS AND ITS classification slide shareDRUGS AND ITS classification slide share
DRUGS AND ITS classification slide share
 
writing about opinions about Australia the movie
writing about opinions about Australia the moviewriting about opinions about Australia the movie
writing about opinions about Australia the movie
 
clinical examination of hip joint (1).pdf
clinical examination of hip joint (1).pdfclinical examination of hip joint (1).pdf
clinical examination of hip joint (1).pdf
 
The simplified electron and muon model, Oscillating Spacetime: The Foundation...
The simplified electron and muon model, Oscillating Spacetime: The Foundation...The simplified electron and muon model, Oscillating Spacetime: The Foundation...
The simplified electron and muon model, Oscillating Spacetime: The Foundation...
 
South African Journal of Science: Writing with integrity workshop (2024)
South African Journal of Science: Writing with integrity workshop (2024)South African Journal of Science: Writing with integrity workshop (2024)
South African Journal of Science: Writing with integrity workshop (2024)
 
How to Setup Warehouse & Location in Odoo 17 Inventory
How to Setup Warehouse & Location in Odoo 17 InventoryHow to Setup Warehouse & Location in Odoo 17 Inventory
How to Setup Warehouse & Location in Odoo 17 Inventory
 
Digital Artifact 1 - 10VCD Environments Unit
Digital Artifact 1 - 10VCD Environments UnitDigital Artifact 1 - 10VCD Environments Unit
Digital Artifact 1 - 10VCD Environments Unit
 
BÀI TẬP BỔ TRỢ TIẾNG ANH 8 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2023-2024 (CÓ FI...
BÀI TẬP BỔ TRỢ TIẾNG ANH 8 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2023-2024 (CÓ FI...BÀI TẬP BỔ TRỢ TIẾNG ANH 8 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2023-2024 (CÓ FI...
BÀI TẬP BỔ TRỢ TIẾNG ANH 8 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2023-2024 (CÓ FI...
 
বাংলাদেশ অর্থনৈতিক সমীক্ষা (Economic Review) ২০২৪ UJS App.pdf
বাংলাদেশ অর্থনৈতিক সমীক্ষা (Economic Review) ২০২৪ UJS App.pdfবাংলাদেশ অর্থনৈতিক সমীক্ষা (Economic Review) ২০২৪ UJS App.pdf
বাংলাদেশ অর্থনৈতিক সমীক্ষা (Economic Review) ২০২৪ UJS App.pdf
 
Main Java[All of the Base Concepts}.docx
Main Java[All of the Base Concepts}.docxMain Java[All of the Base Concepts}.docx
Main Java[All of the Base Concepts}.docx
 
Your Skill Boost Masterclass: Strategies for Effective Upskilling
Your Skill Boost Masterclass: Strategies for Effective UpskillingYour Skill Boost Masterclass: Strategies for Effective Upskilling
Your Skill Boost Masterclass: Strategies for Effective Upskilling
 
Pengantar Penggunaan Flutter - Dart programming language1.pptx
Pengantar Penggunaan Flutter - Dart programming language1.pptxPengantar Penggunaan Flutter - Dart programming language1.pptx
Pengantar Penggunaan Flutter - Dart programming language1.pptx
 
BBR 2024 Summer Sessions Interview Training
BBR  2024 Summer Sessions Interview TrainingBBR  2024 Summer Sessions Interview Training
BBR 2024 Summer Sessions Interview Training
 
Cognitive Development Adolescence Psychology
Cognitive Development Adolescence PsychologyCognitive Development Adolescence Psychology
Cognitive Development Adolescence Psychology
 

1) IntroductionThis practical work consists of developing

  • 1. 1) Introduction: This practical work consists of developing a set of definitions of functions which make it possible to generate mazes and draw them using the turtle. In this work, you have to imagine that you are the programmer of a library that allows you to generate labyrinths. You must write functions that will be used by other programmers to make specific drawings. (create a labyrinth of a certain size). The algorithm for generating mazes is imposed on you and is described in the next section. Your task is to code this algorithm, and the necessary helper functions, in Python using Turtle. 2) Labyrinths The mazes you need to generate are based on a rectangular grid like this: This grid is made up of square cells. In this example there are 8 columns and 4 rows of cells. For a given cell there are 4 walls that we will call the North, East, South, and West walls (to simplify N ", E", S ", O") of the cell. A labyrinth has a certain width in number of cells (NX), a certain height in number of cells (NY), and a certain “step”(the width and height of each square cell, in number of pixels). The labyrinth is therefore
  • 2. created by eliminating certain walls from the grid. The outer wall of the grid is drilled at the top left (the entrance to the labyrinth) and lower right (the exit from the labyrinth). The creation of a labyrinth consists of determining which walls in each cell need to be removed. For each cell it is necessary to eliminate at least one of its 4 walls, and possibly all 4. Here is a labyrinth using the previous grid (i.e. with NX = 8, NY = 4, step = 40): The choice of the walls to eliminate cannot be done completely randomly because this could generate a drawing. which is not a labyrinth, that is to say a drawing which does not follow a path from the entrance to the exit. The algorithm you should use uses random numbers to create the maze but ensures that there always is exactly one path between entering and exiting the maze. In fact, the algorithm guarantees that there is always exactly one path between any cell and any other cell (what is formally called an underlying tree). Before explaining the algorithm we must first number each horizontal wall and each vertical wall and give a coordinate (x, y) to each cell as follows: It should be noted that the coordinate system (x, y) of the cells places (0,0) at the top
  • 3. left (x grows towards the right, and grows down there). Also notice that there are NX (NY + 1) horizontal walls and (NX + 1) NY vertical walls. So the horizontal walls are numbered from 0 to (NX (NY + 1)) 1 and the vertical walls from 0 to ((NX + 1) NY) 1. The relation between the (x, y) coordinate of a cell and the numbers of its walls N, E, S, O is the next one : N = x + y x NX E = 1 + x + y  x (NX + 1) S = x + (y + 1)  x NX O = x + y  x (NX + 1) Note that the wall number N can be used to uniquely identify a cell with only one number. For example in the grid above the cell in position (5,2) has the number 21, that is to say 5 + 2 NX. The algorithm uses sets of numbers (in the mathematical sense of a set, i.e. a collection of numbers without duplication). We can define wallsH as the set of horizontal walls (and respectively wallsv as the set of vertical walls) which have not been removed by the maze creation algorithm. The information contained in these sets can be combined with the values of NX and NY to draw a labyrinth by tracing a horizontal line for each
  • 4. horizontal wall whose number is always in wallsH and a vertical line for each vertical wall whose number is always in wallsv. The algorithm considers that the grid is an initially full space except for a randomly chosen cell, which is empty (this is the initial cavity). At each iteration of the algorithm a new cell will be chosen randomly among all the cells neighboring the cavity (but not forming part of the cavity) and one of the walls (i.e. horizontal or vertical) which separates it from the cavity will be removed randomly to form a larger cavity (i.e. from the whole wallsH if it is a horizontal wall or of the wallsv assembly if it is a vertical wall). This process is repeated until all the cells of the grid are part of the cavity. The choice of the next cell to add to the cavity can be done simply by keeping at all times two other sets of numbers: cellar and front. These are sets that contain cell numbers. The cellar set is the set of cells that have been put into the cavity by the algorithm. The forehead set is the set of cells that are neighboring cells in the cavity (but not in the cavity). We can maintain and update these sets as new cells that are selected to add to the cavity. Indeed if we have add to the cavity the cells with coordinates (x, y) contained in the front set, we must add the neighboring cells with coordinates (x, y) horizontally and vertically (but not in the cellar assembly) a the front assembly and remove the cell (x, y) of the front set and add the cell (x, y) to
  • 5. the cellar set. Note that we must remove or add from these sets the number of cells. The coding of this algorithm will be greatly simplified by the writing of set manipulation functions. These functions are described in the next section. Use them judiciously to code the algorithm labyrinth creation. We will use lists of numbers to represent sets. For example the table [9,2,5] represents the set which contains the three elements 2, 5 and 9. 3) Specifications: Function Iota (n): This function takes a non-negative integer n as parameter and returns an array of length n containing in order the integer values from 0 to n 1 inclusive. For example : iota(5) = [0,1,2,3,4] Function contain(tab,x): This function takes as parameters an array of numbers (tab) and a number x and returns a boolean indicating if x is contained in the array by traversing this array with a loop (not the right to use the keyword in). For example : contain([9,2,5], 2) = True contain([9,2,5], 7) = False
  • 6. Function add(tab,x): This function takes an array of numbers (tab) and a number x as parameters and returns a new array with the same content as tab except that x is appended to the end if it is not already contained in tab. For example : add([9,2,5], 2) = [9,2,5] add([9,2,5], 7) = [9,2,5,7] Function remove(tab,x): This function takes an array of numbers (tab) and a number x as parameters and returns a new array with the same contents as tab except that x is removed from the array. For example : remove([9,2,5], 2) = [9,5] remove([9,2,5], 7) = [9,2,5] Function neighbors(x,y,nx,ny): This function takes the coordinate (x, y) of a cell and the size of a grid (width = nx and height = ny) and returns an array containing the number of neighboring cells. For example : neighbors(7, 2, 8, 4) = [15,22,31] Function laby(nx,ny, step):
  • 7. This procedure creates a random maze (width = nx and height = ny) and draws this maze in the center of the drawing window using a grid with cells of pixel pitch width and height. For example, here are two laby calls and the drawings obtained in each case: 20% bonus points for the implementation of the labySol procedure (nx, ny, pas) which draws a labyrinth exactly like the laby procedure but which in addition draws in the labyrinth, in red, the path traversed by Pledge's algorithm to exit the labyrinth from the top left entrance.