Weight can be configurable

for weight and full heuristic
This commit is contained in:
Yorick Barbanneau 2023-12-16 23:39:46 +01:00
parent a1812aaedf
commit 66b10f4deb
2 changed files with 26 additions and 10 deletions

View file

@ -18,7 +18,7 @@ class ScoreHeuristicEngine(HeuristicEngine):
class WeightHeuristicEngine(HeuristicEngine): class WeightHeuristicEngine(HeuristicEngine):
def get(self, board): def get(self, board):
score = get_weight(board) score = self.get_weight(board)
return score return score
def get_weight(self, board): def get_weight(self, board):
@ -42,15 +42,15 @@ class WeightHeuristicEngine(HeuristicEngine):
# Elements in the corner # Elements in the corner
if pos_x in [0, size -1] and pos_y in [0,size - 1]: 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 # Elements on the border
elif pos_x in [0, size -1] or pos_y in [0, size -1]: 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 # Element the center
elif pos_x in range( center - padding, center + padding) and pos_y in range(center - padding, center + padding): 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 return w
class FullHeuristicEngine(WeightHeuristicEngine): class FullHeuristicEngine(WeightHeuristicEngine):

View file

@ -43,13 +43,20 @@ def parse_aguments():
parser.add_argument('-bh', '--black-heuristic-engine', parser.add_argument('-bh', '--black-heuristic-engine',
help='Black player heutistic engine', help='Black player heutistic engine',
choices= heuristic_choices, choices= heuristic_choices,
default='board', default='score',
) )
parser.add_argument('-wh', '--white-heuristic-engine', parser.add_argument('-wh', '--white-heuristic-engine',
help='White player heutistic engine', help='White player heutistic engine',
choices=heuristic_choices, 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() debug_group = parser.add_mutually_exclusive_group()
@ -74,8 +81,8 @@ if __name__ == '__main__':
} }
heuristic_engine = { heuristic_engine = {
"score": ScoreHeuristicEngine, "score": ScoreHeuristicEngine,
"weight": ScoreHeuristicEngine, "weight": WeightHeuristicEngine,
"full": ScoreHeuristicEngine, "full": FullHeuristicEngine,
} }
print("Stating PyReverso...") print("Stating PyReverso...")
args = parse_aguments() args = parse_aguments()
@ -99,16 +106,25 @@ if __name__ == '__main__':
args.black_engine, args.black_engine,
args.white_engine args.white_engine
)) ))
logger.debug("Weight value {}".format( args.weight ))
wplayer = player_engines[args.white_engine]( wplayer = player_engines[args.white_engine](
logger, logger,
heuristic_engine[args.white_heuristic_engine], heuristic_engine[args.white_heuristic_engine](
logger, {
'weight': args.weight
}
),
{ {
'depth': args.white_depth_exploration, 'depth': args.white_depth_exploration,
} }
) )
bplayer = player_engines[args.black_engine]( bplayer = player_engines[args.black_engine](
logger, logger,
heuristic_engine[args.black_heuristic_engine], heuristic_engine[args.black_heuristic_engine](
logger, {
'weight': args.weight
}
),
{ {
'depth': args.black_depth_exploration, 'depth': args.black_depth_exploration,
} }