-
Notifications
You must be signed in to change notification settings - Fork 1
/
ai_play.pyw
47 lines (33 loc) · 1.19 KB
/
ai_play.pyw
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
import os
import argparse
import tensorflow as tf
from geneticAI.config import RUN_CONFIG
from snake import DISPLAY_OFF, DISPLAY_ON
from snake.game import Game
parser = argparse.ArgumentParser(description="runs AI playing Snake")
parser.add_argument('-training-file', '-t', help="path to file with training data for snake play")
parser.add_argument('-model-file', '-m', help='path to model .h5 file')
parser.add_argument('-game-config', '-c', help='path to game config data')
args = parser.parse_args()
print(args)
class IllegalArgumentException(ValueError):
pass
def get_config():
config = RUN_CONFIG["base_game_config"]
config['move_sleep'] = 20
config['display_mode'] = DISPLAY_ON
return config
def get_network():
if args.training_file is not None:
return None
elif args.model_file is not None:
return tf.keras.models.load_model(os.path.join(os.getcwd(), args.model_file))
raise IllegalArgumentException("There is no argument for model load.")
def main():
config = get_config()
config["neural_network"] = get_network()
game = Game(config=RUN_CONFIG["base_game_config"])
print(game.run())
pass
if __name__ == '__main__':
main()