forked from tmdt-buw/Gridworld
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Aktionen.py
127 lines (104 loc) · 3.17 KB
/
Aktionen.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
from GridWorld import GridWorld
grid_world = GridWorld()
def init_gridworld(random_player=False, random_mines=False, maze=False):
global grid_world, zeigen
grid_world = GridWorld(random_player, random_mines, maze)
return grid_world
def zeigen():
grid_world.zeigen()
def bewege_oben():
grid_world.states.append(grid_world.make_move(grid_world.states[len(grid_world.states)-1], 0))
def bewege_unten():
grid_world.states.append(grid_world.make_move(grid_world.states[len(grid_world.states)-1], 1))
def bewege_links():
grid_world.states.append(grid_world.make_move(grid_world.states[len(grid_world.states)-1], 2))
def bewege_rechts():
grid_world.states.append(grid_world.make_move(grid_world.states[len(grid_world.states)-1], 3))
def inhalt(x, y):
last_state = grid_world.states[len(grid_world.states)-1]
if x >= 0 and y >= 0 and x <= grid_world.grid_x - 1 and y <= grid_world.grid_y - 1:
type = last_state[y, x]
if type == 'P' or (type == [0, 0, 0, 1]).all():
return 'Spieler'
elif type == 'X' or (type == [0, 1, 0, 0]).all():
return 'Mine'
elif type == 'W' or (type == [0, 0, 1, 0]).all():
return 'Wand'
elif type == 'G' or (type == [1, 0, 0, 0]).all():
return 'Ziel'
elif type == 'D' or (type == [0, 1, 0, 1]).all():
return 'Tot'
else:
return 'Frei'
else:
return 'A'
def spieler_position():
last_state = grid_world.states[len(grid_world.states) - 1]
loc = grid_world.getLoc(last_state, 3)
return loc[1] , loc[0]
def inhalt_oben():
position = spieler_position()
x = position[0]
y = position[1] - 1
if x>=0 and y>=0 and x<=grid_world.grid_x-1 and y<=grid_world.grid_y-1:
inh = inhalt(x, y)
return inh
else:
return 'A'
def inhalt_unten():
position = spieler_position()
x = position[0]
y = position[1] + 1
if x >= 0 and y >= 0 and x <= grid_world.grid_x-1 and y <= grid_world.grid_y-1:
inh = inhalt(x, y)
return inh
else:
return 'A'
def inhalt_links():
position = spieler_position()
x = position[0] - 1
y = position[1]
if x >= 0 and y >= 0 and x <= grid_world.grid_x-1 and y <= grid_world.grid_y-1:
inh = inhalt(x, y)
return inh
else:
return 'A'
def inhalt_rechts():
position = spieler_position()
x = position[0] + 1
y = position[1]
if x >= 0 and y >= 0 and x <= grid_world.grid_x-1 and y <= grid_world.grid_y-1:
inh = inhalt(x, y)
return inh
else:
return 'A'
def ist_oben_frei():
inh = inhalt_oben()
if inh == 'Frei':
return True
else:
return False
def ist_unten_frei():
inh = inhalt_unten()
if inh == 'Frei':
return True
else:
return False
def ist_links_frei():
inh = inhalt_links()
if inh == 'Frei':
return True
else:
return False
def ist_rechts_frei():
inh = inhalt_rechts()
if inh == 'Frei':
return True
else:
return False
def wenn_dann(bedingung, action):
if bedingung():
action()
return True
else:
return False