Question

Maze Generator in Python, with below specifcations and input as 10 10 matrix in Maze.csv

Maze.csv file is:

1,3,3,3,9,5,3,3,3,9,
8,3,3,9,12,12,5,3,9,12,
8,1,9,12,12,12,8,9,12,12,
12,12,14,12,12,12,12,12,12,12,
12,12,13,12,6,10,12,14,12,12,
12,12,12,6,3,3,10,13,12,12,
12,6,8,13,5,3,3,2,8,12,
4,3,10,12,14,7,3,3,8,12,
12,5,3,2,3,3,3,3,10,14,
14,6,3,3,3,3,3,3,3,3,

Spec:

Maze Matrix Top 1 2 Bottom Top/Bottom 3 2 1=2 2A2=4 243=8 240=1 Left 4 Right Left Bottom Top Top/Left Bottom/Left 6 Top/Botto

2 0 1 2^1= 2 243=8 2/2 =4 Right Left Bottom Top 1 3 3 3 5 3 3 3 9 12 3 3 9 12 12 9 9 8 1 9 12 12 12 8 9 12 12 12 12 14 12 12


Maze Matrix Top 1 2 Bottom Top/Bottom 3 2 1=2 2A2=4 243=8 240=1 Left 4 Right Left Bottom Top Top/Left Bottom/Left 6 Top/Bottom/Left 7 Analysis: If an element in the matrix contains a 12, Right Top/Right this means there is a wall on the Left and Bottom/Right 10 Right side. The only way the robot can go is Up or Down. Top/Bottom/Right 11 Left/Right 12 Top/Left/Right 13 Bottom/Left/Right 14
2 0 1 2^1= 2 243=8 2/2 =4 Right Left Bottom Top 1 3 3 3 5 3 3 3 9 12 3 3 9 12 12 9 9 8 1 9 12 12 12 8 9 12 12 12 12 14 12 12 12 12 12 12 12 12 12 13 6 10 12 12 12 12 14 12 12 12 6 10 13 12 12 12 12 4 13 3 2 CO 4 12 10 12 14 14 12 5 2 3 3 3 3 10 14 3 3 3 13 3 00 m m 7 Lur unw
0 0
Add a comment Improve this question Transcribed image text
Answer #1

Python CODE :

There are some needed editings in the Maze.csv file ; There are 3 wrongs in data ; see the bolded text

__________________________________________________________

1,3,3,3,9,5,3,3,3,9,
4,3,3,9,12,12,5,3,9,12,
4,1,9,12,12,12,4,9,12,12,
12,12,14,12,12,12,12,12,12,12,
12,12,13,12,6,10,12,14,12,12,
12,12,12,6,3,3,10,13,12,12,
12,6,8,13,5,3,3,2,8,12,
4,3,10,12,14,7,3,3,8,12,
12,5,3,2,3,3,3,3,10,14,
14,6,3,3,3,3,3,3,3,3,

#############################################

Execution ::...........

Starting of game

Ending of Game

RAW CODE ::.............

___________________________ Maze.py ______________________________________________________

from tkinter import *

filename = "Maze.csv"

class Cell:
   def __init__(self, arg,cv,Val):
       self.x = arg[1] ; self.y = arg[0]
       self.x2 = self.x+1 ; self.y2 = self.y+1
       self.cv = cv
       self.Val = Val
   def draw(self):
       line_width = 8
       if (self.Val >> 0) & 1 == 1: # top
           self.cv.create_line(self.x*50,self.y*50,self.x2*50,self.y*50,fill="black",width=line_width)
       if (self.Val >> 1) & 1 == 1: # bottom
           self.cv.create_line(self.x*50,self.y2*50,self.x2*50,self.y2*50,fill="black",width=line_width)
       if (self.Val >> 2) & 1 == 1: # left
           self.cv.create_line(self.x*50,self.y*50,self.x*50,self.y2*50,fill="black",width=line_width)
       if (self.Val >> 3) & 1 == 1: # right
           self.cv.create_line(self.x2*50,self.y*50,self.x2*50,self.y2*50,fill="black",width=line_width)

class Maze:
   def __init__(self,cv):
       self.cells = []
       self.maze = []
       self.bot = [0,0]
       self.cv = cv
       self.win = False
       self.read_maze(filename)
       self.draw_maze()
   def read_maze(self,file):
       F = open(file).read().split("\n")
       while "" in F: F.remove("")
       self.maze = F
       for i in range(10):
           self.maze[i] = F[i].split(",")[:10]
       self.check()
   def check(self):
       assert len(self.maze) == 10
       for i in range(10):
           assert len(self.maze[i]) == 10
   def draw_maze(self):
       self.draw_grid()
       self.Make_cells()
       self.draw_bot()
   def draw_bot(self):
       h = self.bot[0] ; w = self.bot[1]
       x = (w+1)*50 - 25 ; y = (h+1)*50 - 25; r = 40/2
       self.cv.create_oval(x-r, y-r, x+r, y+r, fill='red')
   def draw_grid(self):
       grid_width = 3
       for x in range(11):
           self.cv.create_line(x*50,0*50,x*50,10*50,fill="#c4cad3",width=grid_width)
       for y in range(11):
           self.cv.create_line(0,y*50,10*50,y*50,fill="#c4cad3",width=grid_width)
   def Make_cells(self):
       self.cells = self.maze
       for i in range(10):
           for j in range(10):
               val = int(self.maze[i][j])
               self.cells[i][j] = Cell([i,j],self.cv,val)
               self.cells[i][j].draw()
   def bot_move(self,X,Y):
       h = self.bot[0] ; w = self.bot[1]
       x = (w+1)*50 - 25 ; y = (h+1)*50 - 25; r = 42/2
       self.cv.create_oval(x-r, y-r, x+r, y+r, fill='white',outline="white",width=0)
       self.bot[0] += Y ; self.bot[1] += X
       self.draw_bot()
       self.check_win()
   def move(self,x,y):
       if self.win:
           print("You have already won the game!")
           return 0
       if self.check_move(x,y):
           self.bot_move(x,y)
   def check_move(self,x,y):
       X = self.bot[0]
       Y = self.bot[1]
       if x == 0 and y == -1:
           return self.cells[X][Y].Val >> 0 & 1 == 0
       if x == 0 and y == 1:
           return self.cells[X][Y].Val >> 1 & 1 == 0
       if x == -1 and y == 0:
           return self.cells[X][Y].Val >> 2 & 1 == 0
       if x == 1 and y == 0:
           return self.cells[X][Y].Val >> 3 & 1 == 0
   def check_win(self):
       if self.bot == [9,9]:
           self.win = True
           print("Wow! You won the game......")

class Game:
   def __init__(self,window):
       self.h = 10
       self.w = 10
       self.window = window
       self.create_game()
       self.maze = Maze(self.cv)
   def create_game(self):
       mw.title("Maze Game ..")
       mw.geometry("%sx%s"%(self.w*50+2,self.h*50+2))
       mw.resizable(0, 0)
       mw.configure(background='white')
       self.cv = Canvas(mw, width=10*50, height=10*50,bg="white")
       self.cv.pack()
       self.window.bind('<Left>', left)
       self.window.bind('<Right>', right)
       self.window.bind('<Up>', up)
       self.window.bind('<Down>', down)
   def move(self,x,y):
       self.maze.move(x,y)
  

def up(event):
   game.move(0,-1)
def down(event):
   game.move(0,1)
def right(event):
   game.move(1,0)
def left(event):
   game.move(-1,0)

mw = Tk()
game = Game(mw)
mw.mainloop()

################################################################################################

________________________________________ Maze.csv _______________________________________________

1,3,3,3,9,5,3,3,3,9,
4,3,3,9,12,12,5,3,9,12,
4,1,9,12,12,12,4,9,12,12,
12,12,14,12,12,12,12,12,12,12,
12,12,13,12,6,10,12,14,12,12,
12,12,12,6,3,3,10,13,12,12,
12,6,8,13,5,3,3,2,8,12,
4,3,10,12,14,7,3,3,8,12,
12,5,3,2,3,3,3,3,10,14,
14,6,3,3,3,3,3,3,3,3,

################################################################################################

Sorry for not explaining ; I have ran out of time (Time is not sufficient for this problem)

Anyway I have used object oriented Programming ; With understandable function names ;  

you can get better clarity in the code ; I assure that to you

Once again sorry for that inconvenience

#############################

######## Thank you #########

Add a comment
Know the answer?
Add Answer to:
Maze Generator in Python, with below specifcations and input as 10 10 matrix in Maze.csv Maze.csv...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • 8. Ann x n matrix that is filled with the numbers 1,2,3, ....n2 is a magic...

    8. Ann x n matrix that is filled with the numbers 1,2,3, ....n2 is a magic square if the sum of the elements in each row, in each column, and in the two main diagonals is the same value. For example, 16 3 213 5 10 11 8 9 6 7 12 4 15 14 1 Write the program that reads in 16 values from the keyboard and tests whether they form a magic square when put into a 4...

  • Solve for A: You can resize a matrix (when appropriate) by clicking and dragging the bottom right corner of the matrix...

    Solve for A: You can resize a matrix (when appropriate) by clicking and dragging the bottom right corner of the matrix -4-6-3 2 2 -6 -3 A1--1 6 -8 7 -7 -10 8 2 3 -5-4 000 A-0 0 0 O O 0 Solve for A: You can resize a matrix (when appropriate) by clicking and dragging the bottom right corner of the matrix -4-6-3 2 2 -6 -3 A1--1 6 -8 7 -7 -10 8 2 3 -5-4 000...

  • What is the height of the node that contains 10 in the tree below? A. 8,...

    What is the height of the node that contains 10 in the tree below? A. 8, 13, 4, 2, 5, 14, 9, 1, 10, 15, 6, 3, 11, 7, 12 B. 1, 2, 4, 8, 13, 5, 9, 14, 3, 6, 10, 15, 7, 11, 12 C. 13, 8, 4, 14, 9, 5, 2, 15, 10, 6, 11, 12, 7, 3, 1 D. 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15

  • SHOW STEPS USING Excel & SOLVER-- Create and populate a matrix/spreadsheet that has three col...

    SHOW STEPS USING Excel & SOLVER-- Create and populate a matrix/spreadsheet that has three columns. Starting location (Always Pearlsburg) The other locations    Shortest route solution total time for that path [NOTE: MUST USE SHORTEST ROUTE METHOD - Show work] Hint: You should have 12 rows. Note:   use this numbering scheme 1 Pearlsburg 2 Kitchen Corner 3 Quarry 4 Morgan Creek 5 Stone House 6 Cedar Creek 7 Cutters Store 8 Blakes Crossing 9 Homer 10 McKinney Farm 11 Wellis Farm...

  • Using c++, use a 4x4 maze(for ex this as input: THE NUMBER OF ROOMS DOORS LISTED...

    Using c++, use a 4x4 maze(for ex this as input: THE NUMBER OF ROOMS DOORS LISTED IN ORDER: NORTH, EAST, SOUTH, WEST FOR EACH ROOM: 0 = NO DOORS 0 = 0100 1 = 0111 2 = 0111 3 = 0001 4 = 0100 5 = 1011 6 = 1010 7 = 0010 8 = 0110 9 = 1001 10 = 1100 11 = 1001 12 = 1100 13 = 0101 14 = 0101 15 = 0001 ), Create 3...

  • This needs to be in C++ Problem3.cpp Problem3.h: Given a matrix, clockwise-rotate elements in it. Please...

    This needs to be in C++ Problem3.cpp Problem3.h: Given a matrix, clockwise-rotate elements in it. Please add the code to problem3.h and problem3.cpp, provided. Input 4 Output: 1 8 For 4*4 matrix Input: 4 7 9 10 11 12 13 14 15 16 Output: 9 10 6 4 13 11 7 8 14 15 16 12 #include "problem3.h" 2 3 void rotatematrix(int m, int n, int mat[][MAX]) 4 //write your code here 5 1 #ifndet LAB3 PROBLEM3 2 #define LAB3PROBLEM3...

  • In RobotBASIC what is the best way to solve this random maze generator? cellSize = 80...

    In RobotBASIC what is the best way to solve this random maze generator? cellSize = 80 'pixel size of maze cells mazeWidth = 9 'number of cells horizontally mazeHeight = 6 'number of cells vertically DIM maze[mazeWidth,mazeHeight] 'draw a random maze on the screen Call CreateMaze(mazeWidth,mazeHeight,cellSize) 'place robot in a random location rLocate Random(mazeWidth)*cellSize+cellSize/2, Random(mazeHeight)*cellSize+cellSize/2, 0, 20 Delay 1000 'pause ' YOUR PROGRAM SOLUTION GOES HERE... xyString 0,500,"Done." End 'this must be here! Sub CreateMaze(w,h,s) mConstant maze,0 'zero out entire...

  • Part II: Vectors in a Maze 1. Using only straight lines, find your way from the...

    Part II: Vectors in a Maze 1. Using only straight lines, find your way from the top of the maze to the bottom. 2. Determine the magnitude and direction of the individual vectors required to navigate the maze. 3. Determine the x and y components of each vector. Graphically add the vertical and horizontal components. 5. Draw the resultant 6. Calculate the magnitude and direction of the resultant 7. Measure the magnitude and direction of the resultant. How do they...

  • Question 14 [10 points] Given the following matrix A, find an invertible matrix U so that A is equal to UR, when R...

    Question 14 [10 points] Given the following matrix A, find an invertible matrix U so that A is equal to UR, when R is the reduced row-echelon form of A: You can resize a matrix (when appropriate) by clicking and dragging the bottom right corner of the matrix. 5 -10 5 50 -15 A = 2 -3 1 17 -5 -1-24 7 -3 4 000 000 00 0 Question 14 [10 points] Given the following matrix A, find an invertible...

  • Question 1 [10 points] Given the following matrices A and B, find an elementary matrix E...

    Question 1 [10 points] Given the following matrices A and B, find an elementary matrix E such that B- EA You can resize a matrix (when appropriate) by clicking and dragging the bottom-right corner of the matrbx. 4 6-6 0 7 0 5-2 -4 -7 1-10 -4 6-6 0 4 -4 9-3 4 -4 9-3 o 0 0 E- 0 0 0

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT