-
Notifications
You must be signed in to change notification settings - Fork 0
/
human-vs-ai.py
53 lines (39 loc) · 1.01 KB
/
human-vs-ai.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
52
53
#! /usr/bin/env python
from src.game.board_state import board_to_string
from src.agents.ai import AI, QLearning, greedy
from src.agents.human import Human
from src.game.game import Game
EPOCHS=10000
def main():
train()
replay = None
while replay != 'n':
play()
print()
print("Play again? y/n")
replay = input()
def play():
game = Game([Human(), AI('o', greedy)])
print("--- HUMAN VS AI ---")
while not game.is_over()[0]:
print()
print(game.game_state)
game.step()
print()
print(game.game_state)
print()
over,winner = game.is_over()
if winner:
print(game.players[game.current_player].name + " won!")
else:
print("Draw!")
def train():
learning = QLearning(epochs=EPOCHS)
learning.train()
# for key in learning.states.keys():
# print()
# print(key)
# print(learning.states[key])
# print(learning.states[key].move_values)
if __name__ == "__main__":
main()