-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtournament.py
51 lines (39 loc) · 1.65 KB
/
tournament.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
from dataclasses import dataclass
from typing import Optional
from random import sample
from gameplay.game import Game
from alphaconnect4.agents.mcts_agent import MCTSAgent
from alphaconnect4.agents.neural_mcts_agent import NeuralMCTSAgent
from alphaconnect4.agents.minimax_agent import MinimaxAgent
@dataclass
class Player:
name: str
type: str
time: float = 3
pretrained_path: Optional[str] = None
rating: int = 1000
def instanciator(player: Player):
if player.type == "mcts":
return MCTSAgent(simulation_time=player.time)
if player.type == "neural_mcts":
return NeuralMCTSAgent(simulation_time=player.time, model_path=player.pretrained_path)
if player.type == "minimax":
return MinimaxAgent(max_depth=int(player.time))
raise ValueError
contestants = [Player("p1", "mcts", time=0.5),
# Player("p2", "neural_mcts", time=0.5, pretrained_path="./models/model_0.pth"),
# Player("p3", "minimax", time=4),
# Player("p4", "neural_mcts", time=3),
Player("p5", "neural_mcts", time=0.5, pretrained_path="./models/model_2.pth")
]
wins = {p.name: 0 for p in contestants}
for _ in range(100):
players = sample(contestants, k=2)
print(f"Game between {players[0].name} and {players[1].name}")
game = Game(agent0=instanciator(players[0]), agent1=instanciator(players[1]), enable_ui=False)
result = game.play()
print(f"{players[result].name if result != 0.5 else 'Draw - No one'} wins")
wins[players[0].name] += 1 - result
wins[players[1].name] += result
print(wins)
print([(player.name, player.rating) for player in contestants])