Skip to content

Commit

Permalink
deeper looksahead
Browse files Browse the repository at this point in the history
  • Loading branch information
aeblyve committed Dec 15, 2021
1 parent fab1da7 commit 7b1338d
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions code/bot/qlearning.py
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ def pick_succesor(self, game, state):


class LookaheadQAgent:
"""Get better results by looking one move ahead"""
"""Get better results by looking ahead"""

def __init__(self, evaluator, game):
self.evaluator = evaluator
Expand All @@ -159,12 +159,15 @@ def __init__(self, evaluator, game):
def set_weight(self, func, val):
self.weights[func] = val

def value(self, state):
def value(self, state, lookahead=1):
value = 0
for piece in self.pieces:
piece_value = 0
for succ in game.get_successors(state, given=piece):
piece_value += self.evaluator(succ)
if lookahead == 1:
piece_value += self.evaluator(succ)
else:
piece_value += self.value(succ, lookahead - 1)
value += (1 / len(self.pieces)) * piece_value
return value

Expand Down

0 comments on commit 7b1338d

Please sign in to comment.