Skip to content

Commit

Permalink
Implement Advanced Evaluation Function
Browse files Browse the repository at this point in the history
  • Loading branch information
naderabdalghani committed Dec 27, 2020
1 parent 37adca4 commit 82b386a
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
6 changes: 3 additions & 3 deletions agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ def alpha_beta_pruning(self, game, depth, player, opponent, alpha=float('-inf'),
if self.evaluation_fn == "simple":
game.simple_evaluation_fn()
else:
game.advanced_evaluation_fn()
game.advanced_evaluation_fn(player)
return game.last_move
if player == MAXIMIZING_PLAYER:
max_evaluation = Move(value=float('-inf'))
Expand All @@ -81,7 +81,7 @@ def alpha_beta_pruning(self, game, depth, player, opponent, alpha=float('-inf'),
if self.evaluation_fn == "simple":
temp_game.simple_evaluation_fn()
else:
temp_game.advanced_evaluation_fn()
temp_game.advanced_evaluation_fn(player)
move.value = temp_game.last_move.value
del temp_game
possible_moves = sorted(possible_moves, key=lambda x: x.value, reverse=True)
Expand All @@ -108,7 +108,7 @@ def alpha_beta_pruning(self, game, depth, player, opponent, alpha=float('-inf'),
if self.evaluation_fn == "simple":
temp_game.simple_evaluation_fn()
else:
temp_game.advanced_evaluation_fn()
temp_game.advanced_evaluation_fn(player)
move.value = temp_game.last_move.value
del temp_game
possible_moves = sorted(possible_moves, key=lambda x: x.value)
Expand Down
8 changes: 6 additions & 2 deletions othello.py
Original file line number Diff line number Diff line change
Expand Up @@ -145,5 +145,9 @@ def simple_evaluation_fn(self):
else:
self.last_move.value = -100

def advanced_evaluation_fn(self):
pass
def advanced_evaluation_fn(self, player):
moves = self.move_generator(player)
number_of_moves = len(moves)
if player == MAXIMIZING_PLAYER:
self.last_move.value = number_of_moves
self.last_move.value = -number_of_moves

0 comments on commit 82b386a

Please sign in to comment.