Add recurse game mode
And display statistics after
This commit is contained in:
parent
4a8d97c4ed
commit
23468ffe05
1 changed files with 74 additions and 12 deletions
66
src/game.py
66
src/game.py
|
@ -83,6 +83,12 @@ def parse_aguments():
|
||||||
default=[-5, 2, 10,25]
|
default=[-5, 2, 10,25]
|
||||||
)
|
)
|
||||||
|
|
||||||
|
parser.add_argument('-r', '--recursions',
|
||||||
|
help='Number parties to play',
|
||||||
|
type=int,
|
||||||
|
default=1
|
||||||
|
)
|
||||||
|
|
||||||
parser.add_argument('--show-weights-table',
|
parser.add_argument('--show-weights-table',
|
||||||
help='Display weight table used in \'weight\' and \'full\' heuristic calculation and exit',
|
help='Display weight table used in \'weight\' and \'full\' heuristic calculation and exit',
|
||||||
action='store_true',
|
action='store_true',
|
||||||
|
@ -177,16 +183,72 @@ if __name__ == '__main__':
|
||||||
'randomize_moves': args.black_randomize_moves
|
'randomize_moves': args.black_randomize_moves
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
recursions = args.recursions
|
||||||
|
parties = []
|
||||||
|
while recursions > 0:
|
||||||
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)
|
||||||
else:
|
else:
|
||||||
move = wplayer.get_move(game)
|
move = wplayer.get_move(game)
|
||||||
|
# Display informations only id we are not in recurse mode
|
||||||
|
if args.recursions == 1:
|
||||||
print("Player {} move: {},{}".format(
|
print("Player {} move: {},{}".format(
|
||||||
"Black (X)" if move[0] == 2 else "White (O)",
|
"Black (X)" if move[0] == 2 else "White (O)",
|
||||||
move[1],
|
move[1],
|
||||||
move[2]
|
move[2]
|
||||||
))
|
))
|
||||||
game.push(move)
|
game.push(move)
|
||||||
print("Game end - score black:{}, white:{}\n".format(game._nbBLACK, game._nbWHITE))
|
|
||||||
print(game.show_board())
|
parties.append([recursions, game._nbBLACK, game._nbWHITE])
|
||||||
|
score = game._nbBLACK - game._nbWHITE
|
||||||
|
if score == 0:
|
||||||
|
winner = "No winner"
|
||||||
|
elif score > 0:
|
||||||
|
winner = "Black"
|
||||||
|
else:
|
||||||
|
winner = "White"
|
||||||
|
|
||||||
|
print("\nGAME OVER\n---\nWINNER: {} | black:{} | white:{}".format(
|
||||||
|
winner,
|
||||||
|
game._nbBLACK,
|
||||||
|
game._nbWHITE
|
||||||
|
))
|
||||||
|
print("\n{}".format(game.show_board()))
|
||||||
|
game.reset()
|
||||||
|
recursions -= 1
|
||||||
|
|
||||||
|
# Make somes statistics
|
||||||
|
if args.recursions > 1:
|
||||||
|
numbers = len(parties)
|
||||||
|
black = 0
|
||||||
|
white = 0
|
||||||
|
null = 0
|
||||||
|
for p in parties:
|
||||||
|
black += 1 if p[1] > p[2] else 0
|
||||||
|
white += 1 if p[1] < p[2] else 0
|
||||||
|
null += 1 if p[1] == p[2] else 0
|
||||||
|
print("Stats\n---")
|
||||||
|
print("Parties: {}".format(numbers))
|
||||||
|
print("Black: {:>2} | ratio: {:>6} | engine: {}".format(
|
||||||
|
black,
|
||||||
|
black * 100 / numbers,
|
||||||
|
bplayer._get_class_name(),
|
||||||
|
|
||||||
|
))
|
||||||
|
|
||||||
|
print("White: {:>2} | ratio: {:>6} | engine: {}".format(
|
||||||
|
white,
|
||||||
|
white * 100 / numbers,
|
||||||
|
wplayer._get_class_name(),
|
||||||
|
))
|
||||||
|
|
||||||
|
print("Null: {:>2} | ratio: {:>6}".format(
|
||||||
|
null,
|
||||||
|
bplayer._get_class_name(),
|
||||||
|
null * 100 / numbers
|
||||||
|
))
|
||||||
|
print("---\nBlack player options: {}\nWhite player options: {}".format(
|
||||||
|
bplayer.options, wplayer.options
|
||||||
|
))
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue