-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsetup_Q_table.py
66 lines (58 loc) · 1.96 KB
/
setup_Q_table.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
import itertools
import csv
#STATES:
#wall left, wall right, wall up, wall down, moving left, moving right, moving up, moving down, food left, food right, food up, food down
#ACTIONS:
#left, right, up, down
def make_states():
table = list(itertools.product([False, True], repeat=12)) #wow this is big lol
#Removing "bad" states for clarity. Might leave in if run into problems later, as they never should show up,
#but thinking it might be helpful to visual debug somewhat.
#Doesn't work for some reason, some slip through but I think it should be fine
#for i in table:
# #Can only have one direction it is moving in
# if (i[4] == True):
# if (i[5] == True or i[6] == True or i[7] == True):
# try:
# table.remove(i)
# except:
# pass
# if (i[5] == True):
# if (i[4] == True or i[6] == True or i[7] == True):
# try:
# table.remove(i)
# except:
# pass
# if (i[6] == True):
# if (i[4] == True or i[5] == True or i[7] == True):
# try:
# table.remove(i)
# except:
# pass
# if (i[7] == True):
# if (i[4] == True or i[5] == True or i[6] == True):
# try:
# table.remove(i)
# except:
# pass
#
# #Removing food is left-and-right and up-and-down
# if (i[8] == True and i[9] == True):
# try:
# table.remove(i)
# except:
# pass
# if (i[10] == True and i[11] == True):
# try:
# table.remove(i)
# except:
# pass
#
return table
def make_q_table():
states = make_states()
Q_table = {}
for s in states:
#print(type(s))
Q_table[s] = [0, 0, 0, 0]
return Q_table