-
Notifications
You must be signed in to change notification settings - Fork 0
/
playAgainstAI.py
29 lines (24 loc) · 910 Bytes
/
playAgainstAI.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
import agents
import ninemensmorris
from agents import AlphaBetaAgent, RandomAgent, HumanAgent
from ninemensmorris import NineMensMorris
from tqdm import trange
import numpy as np
episodes = 1
wins = 0
for i in trange(episodes):
game = NineMensMorris()
smartAgent = np.random.choice([-1, 1])
if smartAgent == 1:
agent1 = AlphaBetaAgent(upper_lim=1_000_000_000, lower_lim=-1_000_000_000, max_depth=3)
agent2 = HumanAgent()
else:
agent1 = HumanAgent()
agent2 = AlphaBetaAgent(upper_lim=1_000_000_000, lower_lim=-1_000_000_000, max_depth=3)
done = False
a1_turn = True
while not (game.isWin(1) or game.isWin(2)):
game, reward = agent1.find_opt_move(game, 1) if a1_turn else agent2.find_opt_move(game, 2)
a1_turn = not a1_turn
wins += 1 if smartAgent*game.eval(1, 1) == 1_000_000_000 else 0
print("Win Rate:", wins/episodes)