display time statistics
This commit is contained in:
parent
d66cd99751
commit
1f7fa0c988
1 changed files with 24 additions and 10 deletions
34
src/game.py
34
src/game.py
|
@ -5,6 +5,7 @@ from classes.Engines import RandomPlayerEngine, HumanPlayerEngine, MinmaxPlayerE
|
||||||
from classes.Heuristic import ScoreHeuristicEngine, WeightHeuristicEngine, FullHeuristicEngine
|
from classes.Heuristic import ScoreHeuristicEngine, WeightHeuristicEngine, FullHeuristicEngine
|
||||||
import logging as log
|
import logging as log
|
||||||
import argparse as arg
|
import argparse as arg
|
||||||
|
import time
|
||||||
from classes.CustomFormater import CustomFormatter
|
from classes.CustomFormater import CustomFormatter
|
||||||
|
|
||||||
|
|
||||||
|
@ -185,12 +186,17 @@ if __name__ == '__main__':
|
||||||
)
|
)
|
||||||
recursions = args.recursions
|
recursions = args.recursions
|
||||||
parties = []
|
parties = []
|
||||||
|
white_time = 0
|
||||||
|
black_time = 0
|
||||||
while recursions > 0:
|
while recursions > 0:
|
||||||
while ( not game.is_game_over()):
|
while ( not game.is_game_over()):
|
||||||
|
start_time = time.time()
|
||||||
if game._nextPlayer == 1:
|
if game._nextPlayer == 1:
|
||||||
move = bplayer.get_move(game)
|
move = bplayer.get_move(game)
|
||||||
|
black_time = time.time() - start_time
|
||||||
else:
|
else:
|
||||||
move = wplayer.get_move(game)
|
move = wplayer.get_move(game)
|
||||||
|
white_time += time.time() - start_time
|
||||||
# Display informations only id we are not in recurse mode
|
# Display informations only id we are not in recurse mode
|
||||||
if args.recursions == 1:
|
if args.recursions == 1:
|
||||||
print("Player {} move: {},{}".format(
|
print("Player {} move: {},{}".format(
|
||||||
|
@ -200,7 +206,7 @@ if __name__ == '__main__':
|
||||||
))
|
))
|
||||||
game.push(move)
|
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
|
score = game._nbBLACK - game._nbWHITE
|
||||||
if score == 0:
|
if score == 0:
|
||||||
winner = "No winner"
|
winner = "No winner"
|
||||||
|
@ -209,10 +215,12 @@ if __name__ == '__main__':
|
||||||
else:
|
else:
|
||||||
winner = "White"
|
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,
|
winner,
|
||||||
game._nbBLACK,
|
game._nbBLACK,
|
||||||
game._nbWHITE
|
black_time,
|
||||||
|
game._nbWHITE,
|
||||||
|
white_time
|
||||||
))
|
))
|
||||||
print("\n{}".format(game.show_board()))
|
print("\n{}".format(game.show_board()))
|
||||||
game.reset()
|
game.reset()
|
||||||
|
@ -223,23 +231,29 @@ if __name__ == '__main__':
|
||||||
numbers = len(parties)
|
numbers = len(parties)
|
||||||
black = 0
|
black = 0
|
||||||
white = 0
|
white = 0
|
||||||
|
total_time_black = 0
|
||||||
|
total_time_white = 0
|
||||||
null = 0
|
null = 0
|
||||||
for p in parties:
|
for p in parties:
|
||||||
black += 1 if p[1] > p[2] else 0
|
black += 1 if p[1] > p[3] else 0
|
||||||
white += 1 if p[1] < p[2] else 0
|
white += 1 if p[1] < p[3] else 0
|
||||||
null += 1 if p[1] == p[2] 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("Stats\n---")
|
||||||
print("Parties: {}".format(numbers))
|
print("Parties: {} in {:>6}s".format(numbers, total_time_white + total_time_black))
|
||||||
print("Black: {:>2} | ratio: {:>6} | engine: {}".format(
|
print("Black: {:>2} | ratio: {:>6} | time: {:>8}s | engine: {}".format(
|
||||||
black,
|
black,
|
||||||
black * 100 / numbers,
|
black * 100 / numbers,
|
||||||
|
format(total_time_black, '4.3f'),
|
||||||
bplayer._get_class_name(),
|
bplayer._get_class_name(),
|
||||||
|
|
||||||
))
|
))
|
||||||
|
|
||||||
print("White: {:>2} | ratio: {:>6} | engine: {}".format(
|
print("White: {:>2} | ratio: {:>6} | time: {:>8}s | engine: {}".format(
|
||||||
white,
|
white,
|
||||||
white * 100 / numbers,
|
white * 100 / numbers,
|
||||||
|
format(total_time_white,'4.3f'),
|
||||||
wplayer._get_class_name(),
|
wplayer._get_class_name(),
|
||||||
))
|
))
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue