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):
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):

View file

@ -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,
}