-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patheval.py
More file actions
33 lines (22 loc) · 930 Bytes
/
Copy patheval.py
File metadata and controls
33 lines (22 loc) · 930 Bytes
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
from agent import *
from env import *
def rollout(agents: list[Agent], board: StrandsBoard,display_s:float = -1) -> int:
"""
Returns +1 for a win for white, -1 for a win for black, 0 for a draw
"""
board.reset()
board.make_first_random_action()
board.draw(display_s)
with torch.no_grad():
while not board.check_for_termination():
i = board.round_idx%2 # 0 for "WHITE to play", 1 for "BLACK to play"
agents[i].act_greedily(board)
board.draw(display_s)
reward = board.compute_reward()
return(reward)
def evaluate(agents: list[Agent], board: StrandsBoard, n_rollouts: int) -> float:
rewards_agent_WHITE = []
for i in range(n_rollouts):
reward_agent_WHITE = rollout(agents, board)
rewards_agent_WHITE.append(reward_agent_WHITE)
return(np.mean(rewards_agent_WHITE), -np.mean(rewards_agent_WHITE))