-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.py
125 lines (95 loc) · 1.93 KB
/
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
'''
MAZE RACE
'''
import random
'''
SETUP GLOBALS
'''
size = 10
board = [[0 for x in xrange(size)] for y in xrange(size)]
'''
INITIALIZE A PLAYABLE BOARD
v1.1
'''
def init_board(size):
for x in xrange(size):
for y in xrange(size):
board[x][y] = random.choice([0,0,0,1]) # RANDOM CHOICE FROM
board[size-1][size-1] = 2
return board
board = init_board(size)
for x in board:
print x
def search(x, y):
if board[x][y] == 2:
print 'found at %d, %d' % (x, y)
return True
elif board[x][y] == 1:
print 'wall at %d, %d' % (x, y)
return False
elif board[x][y] == 3:
print 'visited %d, %d' % (x, y)
return False
print 'visiting %d, %d' % (x, y)
# mark as visited
board [x][y] = 3
# explore neighbors clockwise starting on the right
if ((x < len(board) -1 and search(x+1, y))
or (y > 0 and search(x, y-1))
or (x > 0 and search(x-1, y))
or (y < len(board)-1 and search(x, y+1))):
return True
return False
good_board = False
while good_board == False:
if search(0,0) == True:
good_board = True
else:
init_board(size)
'''
CLASS "PLAYER" PLAYS THROUGH BOARD TO FINISH CONDITION
v0.0
'''
class player():
def __init__(self):
self.position = [0,0] # Start position.
moves = {
'w':[0,1],
'a':[-1,0],
's':[0,-1],
'd':[1,0]
}
def player_move(self):
moves = {
'w':[0,1],
'a':[-1,0],
's':[0,-1],
'd':[1,0]
}
move = raw_input('MOVE : ',)
try:
self.position = [sum(x) for x in zip(self.position,moves[move])]
if self.position <= size:
pass
else:
print 'EDGE!'
except KeyError:
print 'Invalid KEY!'
self.player_move()
def position(self):
return self.position
'''
INITIALIZE PLAYER
'''
wilder = player()
'''
MAIN LOOP
prototype v0.0
'''
WIN = False
while WIN == False:
wilder.player_move()
print wilder.position
if board[wilder.position[0]][wilder.position[1]]== 2:
WIN = True
print 'You found the exit! You won a Maze Race!'