From 66b10f4deb73c3baf48140551c21e441f267ae7a Mon Sep 17 00:00:00 2001 From: Yorick Barbanneau Date: Sat, 16 Dec 2023 23:39:46 +0100 Subject: [PATCH] Weight can be configurable for weight and full heuristic --- src/classes/Heuristic.py | 8 ++++---- src/game.py | 28 ++++++++++++++++++++++------ 2 files changed, 26 insertions(+), 10 deletions(-) diff --git a/src/classes/Heuristic.py b/src/classes/Heuristic.py index bb20a70..cbd82d5 100644 --- a/src/classes/Heuristic.py +++ b/src/classes/Heuristic.py @@ -18,7 +18,7 @@ class ScoreHeuristicEngine(HeuristicEngine): class WeightHeuristicEngine(HeuristicEngine): def get(self, board): - score = get_weight(board) + score = self.get_weight(board) return score def get_weight(self, board): @@ -42,15 +42,15 @@ class WeightHeuristicEngine(HeuristicEngine): # Elements in the corner if pos_x in [0, size -1] and pos_y in [0,size - 1]: - w[pos_x][pos_y] = self.weight[2] + w[pos_x][pos_y] = self.options['weight'][2] # Elements on the border elif pos_x in [0, size -1] or pos_y in [0, size -1]: - w[pos_x][pos_y] = self.weight[1] + w[pos_x][pos_y] = self.options['weight'][1] # Element the center elif pos_x in range( center - padding, center + padding) and pos_y in range(center - padding, center + padding): - w[pos_x][pos_y] = self.weight[0] + w[pos_x][pos_y] = self.options['weight'][0] return w class FullHeuristicEngine(WeightHeuristicEngine): diff --git a/src/game.py b/src/game.py index 9e6f4dc..d600e5a 100755 --- a/src/game.py +++ b/src/game.py @@ -43,13 +43,20 @@ def parse_aguments(): parser.add_argument('-bh', '--black-heuristic-engine', help='Black player heutistic engine', choices= heuristic_choices, - default='board', + default='score', ) parser.add_argument('-wh', '--white-heuristic-engine', help='White player heutistic engine', choices=heuristic_choices, - default='board', + default='score', + ) + + parser.add_argument('--weight', + help='Weight table for weight based heuristic engines', + type=int, + nargs=3, + default=[2,10,25] ) debug_group = parser.add_mutually_exclusive_group() @@ -74,8 +81,8 @@ if __name__ == '__main__': } heuristic_engine = { "score": ScoreHeuristicEngine, - "weight": ScoreHeuristicEngine, - "full": ScoreHeuristicEngine, + "weight": WeightHeuristicEngine, + "full": FullHeuristicEngine, } print("Stating PyReverso...") args = parse_aguments() @@ -99,16 +106,25 @@ if __name__ == '__main__': args.black_engine, args.white_engine )) + logger.debug("Weight value {}".format( args.weight )) wplayer = player_engines[args.white_engine]( logger, - heuristic_engine[args.white_heuristic_engine], + heuristic_engine[args.white_heuristic_engine]( + logger, { + 'weight': args.weight + } + ), { 'depth': args.white_depth_exploration, } ) bplayer = player_engines[args.black_engine]( logger, - heuristic_engine[args.black_heuristic_engine], + heuristic_engine[args.black_heuristic_engine]( + logger, { + 'weight': args.weight + } + ), { 'depth': args.black_depth_exploration, }