-
Notifications
You must be signed in to change notification settings - Fork 0
/
UI.py
70 lines (68 loc) · 3.45 KB
/
UI.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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
from SnakeGame import SnakeGame
import time
class UI(object):
def __init__(self):
self.game = None
def run(self):
while True:
pick = input("1. Brute force Reinforcement Algorithm\n2. Genetic Algorithm\n3. Quit\n-> ")
# RL
if int(pick) == 1:
while True:
pick = input("Would you like a pre trained Neural Network (y/n): ")
if pick == "y":
self.game = SnakeGame(reinforcement_learning = True, use_keras = True, pre_trained = True)
self.game.game_loop()
# we are done return the function
return
elif pick == "n":
pick = input("1. Keras MLP\n2. Personal Implementation of MLP\n3. Quit\n-> ")
if int(pick) == 1:
while True:
pick = input("Enter the number of games you would like to train the snake for: ")
if not pick.isdigit():
print("Input should be a number to proceed!")
else:
self.game = SnakeGame(reinforcement_learning = True, use_keras = True, pre_trained = False)
self.game.gather_data(int(pick))
self.game.train_agent()
self.game.game_loop()
return
elif int(pick) == 2:
while True:
pick = input("Enter the number of games you would like to train the snake for: ")
if not pick.isdigit():
print("Input should be a number to proceed!")
else:
self.game = SnakeGame(reinforcement_learning = True, use_keras = False, pre_trained = False)
self.game.gather_data(int(pick))
self.game.train_agent()
self.game.game_loop()
return
elif int(pick) == 3:
return
else:
print("Please select one of the options above\n")
else:
print("Please type in either y or n")
# GA
elif int(pick) == 2:
while True:
pick = input("Snakes per generation: ")
if not pick.isdigit():
print("Input must be a number!")
else:
self.game = SnakeGame(reinforcement_learning = False, population_size = int(pick))
while True:
pick = input("Number of generations: ")
if not pick.isdigit():
print("Input must be a number!")
else:
self.game.train_agent(int(pick))
self.game.game_loop()
return
# Quit
elif int(pick) == 3:
return
else:
print("Please select from one of the options above\n")