final working i think
This commit is contained in:
parent
e4fca60692
commit
ed2bfe4f88
4 changed files with 11 additions and 5 deletions
13
nim.py
13
nim.py
|
|
@ -62,7 +62,7 @@ class NimAI():
|
|||
float: The Q-value associated with the (state, action) pair.
|
||||
Returns 0 if the pair is not yet in the Q-table.
|
||||
"""
|
||||
print(self.q, state, action)
|
||||
# print(self.q, state, action)
|
||||
try:
|
||||
return self.q[(tuple(state), action)]
|
||||
except:
|
||||
|
|
@ -123,10 +123,13 @@ class NimAI():
|
|||
# keys = [key[1] for key in self.q.key if key[0] == state]
|
||||
# for key in keys:
|
||||
else:
|
||||
try:
|
||||
return max([key[1] for key in self.q.keys() if key[0] == state])
|
||||
except:
|
||||
return (0,0)
|
||||
# state = tuple(state)
|
||||
# max(self.q[state, action]) for action in [key[1] for key in self.q if key[0] == state]
|
||||
# for q in self.q:
|
||||
# if q[0] == state:
|
||||
|
||||
return list(self.q.keys())[list(self.q.values()).index(self.best_future_reward(state))][1]
|
||||
|
||||
|
||||
def train(n):
|
||||
player = NimAI()
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue