Implement heuristics classes

This commit is contained in:
Yorick Barbanneau 2023-12-16 23:02:36 +01:00
parent 3784faeaed
commit a1812aaedf
3 changed files with 63 additions and 38 deletions

View file

@ -1,10 +1,10 @@
import random, math
from .Heuristic import ReversiHeuristic
class PlayerEngine:
def __init__(self, logger, options: dict = {}):
def __init__(self, logger, heuristic, options: dict = {}):
# init logger do display informations
self.logger = logger
self.heuristic = heuristic
self.options = options
self.logger.info("Init engine {}, options:{}".format(
self.__class__.__name__,
@ -91,11 +91,7 @@ class MinmaxPlayerEngine(PlayerEngine):
move = ''
if depth == 0:
leafs +=1
if self.options['heuristic'] == 'weight':
score = ReversiHeuristic(board).get()
else:
score = board.heuristique()
return score, nodes, leafs
return self.heuristic.get(board), nodes, leafs
if friend_move:
value = -math.inf
@ -157,11 +153,7 @@ class AlphabetaPlayerEngine(PlayerEngine):
leafs = 0
if depth == 0 :
leafs +=1
if self.options['heuristic'] == 'weight':
score = ReversiHeuristic(self.logger).get(board)
else:
score = board.heuristique()
return score, nodes, leafs
return self.heuristic.get(board), nodes, leafs
if friend_move:
value = -math.inf