display time statistics

This commit is contained in:
Yorick Barbanneau 2023-12-22 11:44:10 +01:00
parent d66cd99751
commit 1f7fa0c988

View file

@ -5,6 +5,7 @@ from classes.Engines import RandomPlayerEngine, HumanPlayerEngine, MinmaxPlayerE
from classes.Heuristic import ScoreHeuristicEngine, WeightHeuristicEngine, FullHeuristicEngine
import logging as log
import argparse as arg
import time
from classes.CustomFormater import CustomFormatter
@ -185,12 +186,17 @@ if __name__ == '__main__':
)
recursions = args.recursions
parties = []
white_time = 0
black_time = 0
while recursions > 0:
while ( not game.is_game_over()):
start_time = time.time()
if game._nextPlayer == 1:
move = bplayer.get_move(game)
black_time = time.time() - start_time
else:
move = wplayer.get_move(game)
white_time += time.time() - start_time
# Display informations only id we are not in recurse mode
if args.recursions == 1:
print("Player {} move: {},{}".format(
@ -200,7 +206,7 @@ if __name__ == '__main__':
))
game.push(move)
parties.append([recursions, game._nbBLACK, game._nbWHITE])
parties.append([recursions, game._nbBLACK, black_time, game._nbWHITE, white_time])
score = game._nbBLACK - game._nbWHITE
if score == 0:
winner = "No winner"
@ -209,10 +215,12 @@ if __name__ == '__main__':
else:
winner = "White"
print("\nGAME OVER\n---\nWINNER: {} | black:{} | white:{}".format(
print("\nGAME OVER\n---\nWINNER: {} | black:{} in {:>5}s | white:{} in {:>5}s".format(
winner,
game._nbBLACK,
game._nbWHITE
black_time,
game._nbWHITE,
white_time
))
print("\n{}".format(game.show_board()))
game.reset()
@ -223,23 +231,29 @@ if __name__ == '__main__':
numbers = len(parties)
black = 0
white = 0
total_time_black = 0
total_time_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
black += 1 if p[1] > p[3] else 0
white += 1 if p[1] < p[3] else 0
null += 1 if p[1] == p[3] else 0
total_time_black += p[2]
total_time_white += p[4]
print("Stats\n---")
print("Parties: {}".format(numbers))
print("Black: {:>2} | ratio: {:>6} | engine: {}".format(
print("Parties: {} in {:>6}s".format(numbers, total_time_white + total_time_black))
print("Black: {:>2} | ratio: {:>6} | time: {:>8}s | engine: {}".format(
black,
black * 100 / numbers,
format(total_time_black, '4.3f'),
bplayer._get_class_name(),
))
print("White: {:>2} | ratio: {:>6} | engine: {}".format(
print("White: {:>2} | ratio: {:>6} | time: {:>8}s | engine: {}".format(
white,
white * 100 / numbers,
format(total_time_white,'4.3f'),
wplayer._get_class_name(),
))