Implement heuristics classes
This commit is contained in:
parent
3784faeaed
commit
a1812aaedf
3 changed files with 63 additions and 38 deletions
|
@ -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
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue