PDA

View Full Version : how do I put two exits in a maze?


IOEPsych
04-13-2011, 03:33 AM
I have designed a Vizard maze with an 'exit' that when you move into this area of the maze you hear a 'yipee' sound and the programme closes. I now need to be able to have the option to have two separate exits (so that the maze can be solved in two ways) but I cannot seem to do this as when I put another 'E' into my text file ('E' = END) then the programme opens but doesn't run properly. Any thoughts!???

This bit of my script looks like this:

def allTimers(event):

if (event == LOG_POSITION):
logPosition()
if (event == JOYSTICK_MOVE):
doMove()
if (event == CHECK_KEYBOARD):
checkKeyboard()
if (event == CHECK_END):
checkIfAtEnd()
if (event == STOP):
viz.quit()

def checkIfAtEnd():
''' Checks if the current position is in the end square of the maze.
'''
global endPos
pos = viz.MainView.getPosition()
euler = viz.MainView.getEuler()
lowEndX = endPos[0]*mazeExptParams.XSCALE
highEndX = (endPos[0]+1)*mazeExptParams.XSCALE
lowEndY = endPos[1]*mazeExptParams.YSCALE
highEndY = (endPos[1]+1)*mazeExptParams.YSCALE
x = pos[0]
y = pos[2]

if (x >= lowEndX and x <= highEndX) and (y >= lowEndY and y <= highEndY):
viz.playsound('yipee.wav')
viz.killtimer(CHECK_END)
viz.starttimer(STOP, 2)

Jeff
04-13-2011, 11:54 AM
Sorry, the question is not so clear to me. Are you setting the endpoints of the maze from values taken from a text file? Where is your code to read in the file data?

IOEPsych
04-14-2011, 03:48 AM
Sorry, I didn't put that bit in. I have a text file with the layout of my maze which I import from a separate .py file that has the name of the specific .txt file that I am using e.g. INPUT_FNAME='Maze 2c.txt'

I then have a 'maze dictionary' in which 'E' is assigned as the END position. This part of the file is below. Sorry, I'm not sure if this makes sense explaining it like this...
This is my other .py file that I import in to run the maze:

def transposeMatrix(mazeMatrix):
''' Transposes the given rectangular matrix, such that [i][j] becomes [j][i]
'''
mazeMatrixTransformed = []
for i in range(len(mazeMatrix[0])):
mazeMatrixTransformed.append([])
for i in range(len(mazeMatrix)):
line = mazeMatrix[i]
for j in range(len(line)):
mazeMatrixTransformed[j].append(mazeMatrix[i][j])
return mazeMatrixTransformed

def getMazeInfo(mazeMatrix):

mazeMatrixTransformed = transposeMatrix(mazeMatrix)
print 'transformed maze matrix is',mazeMatrixTransformed,'xLength=',len(mazeMatri xTransformed),'; yLength=',len(mazeMatrixTransformed[0])

rowMatrix=[]
colourMatrix=[]
columnMatrix=[]
objectMatrix=[]
items=[]
redballs=[]
startPos=[]
endPos=[]
item=False

#find start/end/objects
for x in range (len(mazeMatrixTransformed)):
for y in range(len(mazeMatrixTransformed[x])):
char=mazeMatrixTransformed[x][y]

if char=='S':
if startPos!=[]: raise Exception('multiple starts found')
startPos=[x,y]
elif char=='E':
if endPos!=[]: raise Exception('multiple ends found')
endPos=[x,y]


Someone else created this for me who is no longer available and they have set it to disallow multiple ends. Does this make sense? I need to allow two different ends of the maze to be put it. Sorry I'm new to Python!