한 단계를 제외하고 숙제로 모든 것을했습니다.미로 탐색 (파이썬 2.7 사용)
나는 그것을 다른 방식으로했지만 어쨌든 정답을 주었다. 어쨌든, 나는 maz를 탐험해야한다. 그래서이 일의 일부 (Q COMMAND)를 제외하고 모든 것을 완전히 끝내고 모든 것을 완전히 끝내었다.
나는 문자열 방법을 사용할 필요가 .upper()
2.2.6 인터페이스 interact()
가 도입에 설명 된대로 텍스트 기반의 사용자 인터페이스 를 denes 최상위 함수 인 최상위. 마무리 사각형이 발견 될 때 사용자가 종료하거나 을 누르면 상호 작용 기능이 종료됩니다.
def interact():
mazefile = raw_input('Maze File: ')
maze = load_maze(mazefile)
position = (1, 1)
poshis = [position]
while True:
#print poshis, len(poshis)
print 'You are at position', position
command = raw_input('Command: ')
#print command
if command == '?':
print HELP
elif command == 'N' or command == 'E' or command == 'S'or command == 'W':
mov = move(maze, position, command)
if mov[0] == False: #invalid direction
print "You can't go in that direction"
elif mov[1] == True:#finished
print 'Congratulations - you made it!'
break
else: #can move, but not finished
position = mov[2]
poshis.append(position)
elif command == 'R': # reseting the maze to the first pos
position = (1, 1)
poshis = [position]
elif command == 'B': # back one move
if len(poshis) > 1:
poshis.pop()
position = poshis[-1]
elif command == 'L': # listing all possible leg dir
toggle = 0
result = ''
leg_list = get_legal_directions(maze, poshis[-1])
for Legal in leg_list:
if toggle:
result += ', '
result += Legal
else:
result += Legal
if not toggle:
toggle = 1
print result
elif command == 'Q': #quiting
m = raw_input('Are you sure you want to quit? [y] or n: ')
if m == 'y':
break
#print 'Are you sure you want to quit? [y] or n: '
#if raw_input == 'y':
# break
else: #invalid input
print 'Invalid Command:', command
"왜 종료하지 않습니까?" 무슨 일이 일어날 것으로 예상됩니까? 파이썬 2.7이 중요한 이유는 무엇입니까? 마지막 부분을 해결하지 않은 방식에 대한 세부 정보를 게시 할 수 있습니까? 미로 파일의 두 줄 또는 세 줄을 게시 할 수 있습니까? – octopusgrabbus