@@ -22,22 +22,20 @@ def main() -> None:
22
22
"""Various Schnapsen Game Examples"""
23
23
24
24
25
- def play_games_and_return_stats (engine : GamePlayEngine , bot1 : Bot , bot2 : Bot , number_of_games : int ) -> int :
25
+ def play_games_and_return_stats (engine : GamePlayEngine , bot1 : Bot , bot2 : Bot , pairs_of_games : int ) -> int :
26
26
"""
27
- Play number_of_games games between bot1 and bot2, using the SchnapsenGamePlayEngine, and return how often bot1 won.
28
- Prints progress.
27
+ Play 2 * pairs_of_games games between bot1 and bot2, using the SchnapsenGamePlayEngine, and return how often bot1 won.
28
+ Prints progress. Each pair of games is the same original dealing of cards, but the roles of the bots are swapped.
29
29
"""
30
30
bot1_wins : int = 0
31
31
lead , follower = bot1 , bot2
32
- for i in range (1 , number_of_games + 1 ):
33
- if i % 2 == 0 :
34
- # swap bots so both start the same number of times
35
- lead , follower = follower , lead
36
- winner , _ , _ = engine .play_game (lead , follower , random .Random (i ))
37
- if winner == bot1 :
38
- bot1_wins += 1
39
- if i % 500 == 0 :
40
- print (f"Progress: { i } /{ number_of_games } " )
32
+ for game_pair in range (pairs_of_games ):
33
+ for lead , follower in [(bot1 , bot2 ), (bot2 , bot1 )]:
34
+ winner , _ , _ = engine .play_game (lead , follower , random .Random (game_pair ))
35
+ if winner == bot1 :
36
+ bot1_wins += 1
37
+ if game_pair > 0 and (game_pair + 1 ) % 500 == 0 :
38
+ print (f"Progress: { game_pair + 1 } /{ pairs_of_games } game pairs played" )
41
39
return bot1_wins
42
40
43
41
@@ -180,9 +178,10 @@ def try_bot_game() -> None:
180
178
bot1 : Bot = MLPlayingBot (model_location = model_location )
181
179
bot2 : Bot = RandBot (random .Random (464566 ))
182
180
number_of_games : int = 10000
181
+ pairs_of_games = number_of_games // 2
183
182
184
183
# play games with altering leader position on first rounds
185
- ml_bot_wins_against_random = play_games_and_return_stats (engine = engine , bot1 = bot1 , bot2 = bot2 , number_of_games = number_of_games )
184
+ ml_bot_wins_against_random = play_games_and_return_stats (engine = engine , bot1 = bot1 , bot2 = bot2 , pairs_of_games = pairs_of_games )
186
185
print (f"The ML bot with name { model_name } , won { ml_bot_wins_against_random } times out of { number_of_games } games played." )
187
186
188
187
0 commit comments