logo Hurry, Grab up to 30% discount on the entire course
Order Now logo

Ask This Question To Be Solved By Our ExpertsGet A+ Grade Solution Guaranteed

expert
Jordan CarterEngineering
(5/5)

803 Answers

Hire Me
expert
Aaryan KhannaGeneral article writing
(5/5)

849 Answers

Hire Me
expert
Bhupesh SinglaComputer science
(5/5)

813 Answers

Hire Me
expert
Sohail AliScience
(5/5)

893 Answers

Hire Me
Others
(5/5)

you have to imagine that you are the programmer of a library that allows you to generate labyrinths

INSTRUCTIONS TO CANDIDATES
ANSWER ALL QUESTIONS

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

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.

(5/5)
Attachments:

Related Questions

. The fundamental operations of create, read, update, and delete (CRUD) in either Python or Java

CS 340 Milestone One Guidelines and Rubric  Overview: For this assignment, you will implement the fundamental operations of create, read, update,

. Develop a program to emulate a purchase transaction at a retail store. This  program will have two classes, a LineItem class and a Transaction class

Retail Transaction Programming Project  Project Requirements:  Develop a program to emulate a purchase transaction at a retail store. This

. The following program contains five errors. Identify the errors and fix them

7COM1028   Secure Systems Programming   Referral Coursework: Secure

. Accepts the following from a user: Item Name Item Quantity Item Price Allows the user to create a file to store the sales receipt contents

Create a GUI program that:Accepts the following from a user:Item NameItem QuantityItem PriceAllows the user to create a file to store the sales receip

. The final project will encompass developing a web service using a software stack and implementing an industry-standard interface. Regardless of whether you choose to pursue application development goals as a pure developer or as a software engineer

CS 340 Final Project Guidelines and Rubric  Overview The final project will encompass developing a web service using a software stack and impleme