Rework options, now can be defined per player
This commit is contained in:
parent
1c039106d9
commit
c3ac347364
2 changed files with 31 additions and 15 deletions
|
@ -6,7 +6,10 @@ class PlayerEngine:
|
||||||
# init logger do display informations
|
# init logger do display informations
|
||||||
self.logger = logger
|
self.logger = logger
|
||||||
self.options = options
|
self.options = options
|
||||||
self.logger.info("Init engine {}".format(self.__class__.__name__))
|
self.logger.info("Init engine {}, options:{}".format(
|
||||||
|
self.__class__.__name__,
|
||||||
|
self.options
|
||||||
|
))
|
||||||
|
|
||||||
def get_move(self, board):
|
def get_move(self, board):
|
||||||
self.logger.info("engine: {} - player:{}".format(
|
self.logger.info("engine: {} - player:{}".format(
|
||||||
|
@ -155,7 +158,6 @@ class AlphabetaPlayerEngine(PlayerEngine):
|
||||||
leafs = 0
|
leafs = 0
|
||||||
if depth == 0 :
|
if depth == 0 :
|
||||||
leafs +=1
|
leafs +=1
|
||||||
self.logger.debug("option: {}".format(self.options))
|
|
||||||
if self.options['heuristic'] == 'weight':
|
if self.options['heuristic'] == 'weight':
|
||||||
score = ReversiHeuristic(self.logger).get(board)
|
score = ReversiHeuristic(self.logger).get(board)
|
||||||
else:
|
else:
|
||||||
|
|
40
src/game.py
40
src/game.py
|
@ -12,28 +12,41 @@ Function to parse command line arguments
|
||||||
"""
|
"""
|
||||||
def parse_aguments():
|
def parse_aguments():
|
||||||
engines_choices=['random', 'human', 'minmax', 'alphabeta']
|
engines_choices=['random', 'human', 'minmax', 'alphabeta']
|
||||||
|
heuristic_choices=['weight',]
|
||||||
parser = arg.ArgumentParser('Playing Reversi with (virtual) friend')
|
parser = arg.ArgumentParser('Playing Reversi with (virtual) friend')
|
||||||
|
|
||||||
parser.add_argument('-w', '--white-engine',
|
parser.add_argument('-we', '--white-engine',
|
||||||
choices=engines_choices,
|
choices=engines_choices,
|
||||||
help='white player engine (random)',
|
help='white player engine (random)',
|
||||||
default='random'
|
default='random'
|
||||||
)
|
)
|
||||||
|
|
||||||
parser.add_argument('-b', '--black-engine',
|
parser.add_argument('-be', '--black-engine',
|
||||||
choices=engines_choices,
|
choices=engines_choices,
|
||||||
help='black player engine (random)',
|
help='black player engine (random)',
|
||||||
default='random'
|
default='random'
|
||||||
)
|
)
|
||||||
|
|
||||||
parser.add_argument('-D', '--depth',
|
parser.add_argument('-bd', '--black-depth-exploration',
|
||||||
help='Minmax exploration depth',
|
help='Black player exploration depth (minmax or alphabeta engine)',
|
||||||
type=int,
|
type=int,
|
||||||
default=3,
|
default=3,
|
||||||
)
|
)
|
||||||
|
|
||||||
parser.add_argument('-H', '--heuristic',
|
parser.add_argument('-wd', '--white-depth-exploration',
|
||||||
help='Define heutistic engine',
|
help='White player exploration depth (minmax or alphabeta engine)',
|
||||||
|
type=int,
|
||||||
|
default=3,
|
||||||
|
)
|
||||||
|
|
||||||
|
parser.add_argument('-bh', '--black-heuristic-engine',
|
||||||
|
help='Black player heutistic engine',
|
||||||
|
choices=['board', 'weight'],
|
||||||
|
default='board',
|
||||||
|
)
|
||||||
|
|
||||||
|
parser.add_argument('-wh', '--white-heuristic-engine',
|
||||||
|
help='White player heutistic engine',
|
||||||
choices=['board', 'weight'],
|
choices=['board', 'weight'],
|
||||||
default='board',
|
default='board',
|
||||||
)
|
)
|
||||||
|
@ -61,7 +74,6 @@ if __name__ == '__main__':
|
||||||
print("Stating PyReverso...")
|
print("Stating PyReverso...")
|
||||||
args = parse_aguments()
|
args = parse_aguments()
|
||||||
logger = log.getLogger()
|
logger = log.getLogger()
|
||||||
print(args)
|
|
||||||
# Create handler for streaming to tty (stderr / stdout)
|
# Create handler for streaming to tty (stderr / stdout)
|
||||||
tty_handler = log.StreamHandler()
|
tty_handler = log.StreamHandler()
|
||||||
tty_handler.setFormatter(CustomFormatter())
|
tty_handler.setFormatter(CustomFormatter())
|
||||||
|
@ -81,12 +93,14 @@ if __name__ == '__main__':
|
||||||
args.black_engine,
|
args.black_engine,
|
||||||
args.white_engine
|
args.white_engine
|
||||||
))
|
))
|
||||||
options = {
|
wplayer = engines[args.white_engine](logger, {
|
||||||
'depth': args.depth,
|
'depth': args.white_depth_exploration,
|
||||||
'heuristic': args.heuristic
|
'heuristic': args.white_heuristic_engine
|
||||||
}
|
})
|
||||||
wplayer = engines[args.white_engine](logger, options)
|
bplayer = engines[args.black_engine](logger, {
|
||||||
bplayer = engines[args.black_engine](logger, options)
|
'depth': args.black_depth_exploration,
|
||||||
|
'heuristic': args.black_heuristic_engine
|
||||||
|
})
|
||||||
while ( not game.is_game_over()):
|
while ( not game.is_game_over()):
|
||||||
if game._nextPlayer == 1:
|
if game._nextPlayer == 1:
|
||||||
move = bplayer.get_move(game)
|
move = bplayer.get_move(game)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue