-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain_kow.py
138 lines (101 loc) · 2.1 KB
/
main_kow.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
126
127
128
129
130
131
132
133
134
135
136
137
138
'''
MAZE RACE
v1.k
working board render
needs conditional movment
'''
import random
'''
SETUP GLOBALS
'''
size = 10
board = [[0 for x in xrange(size)] for y in xrange(size)]
'''
INITIALIZE A PLAYABLE BOARD
v1.2
'''
def init_board(size):
for x in xrange(size):
for y in xrange(size):
board[x][y] = [random.choice([0,1]),'u'] # RANDOM CHOICE and UNEXPLORED ='u'
board[size-1][size-1] = [2,'u']
return board
def search(x, y):
if board[x][y][0] == 2:
return True
elif board[x][y][0] == 1:
return False
elif board[x][y][0] == 3:
return False
# mark as visited
board[x][y][0] = 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:
init_board(size)
if search(0,0) == True:
good_board = True
'''
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':[-1,0],
'a':[0,-1],
's':[1,0],
'd':[0,1]
}
move = raw_input('\nMOVE : ',)
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
'''
RENDER FOG OF WAR MAZE
'''
def render_board(board,player_pos):
for x in xrange(size-1):
print '\n'
for y in xrange(size-1):
if [x,y] == player_pos:
print '+',
elif board[x][y][1] == 'e':
print board[x][y][0],
else:
print '-',
'''
MAIN LOOP
prototype v0.1
'''
wilder = player()
board = init_board(size)
WIN = False
while WIN == False:
render_board(board,wilder.position)
wilder.player_move()
if board[wilder.position[0]][wilder.position[1]]== 2:
WIN = True
print 'You found the exit! You won a Maze Race!'