-
Notifications
You must be signed in to change notification settings - Fork 0
/
test_basic_neural.py
51 lines (43 loc) · 2.08 KB
/
test_basic_neural.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
#!/usr/bin/env python
# -*- coding: utf-8 -*-
from __future__ import absolute_import
import logging.handlers
import os
import time
from neural import Neuron, Input
PYTHON_LOGGER = logging.getLogger(__name__)
if not os.path.exists("log"):
os.mkdir("log")
HDLR = logging.handlers.TimedRotatingFileHandler("log/test.log",
when="midnight", backupCount=60)
STREAM_HDLR = logging.StreamHandler()
FORMATTER = logging.Formatter("%(asctime)s %(filename)s [%(levelname)s] %(message)s")
HDLR.setFormatter(FORMATTER)
STREAM_HDLR.setFormatter(FORMATTER)
PYTHON_LOGGER.addHandler(HDLR)
PYTHON_LOGGER.addHandler(STREAM_HDLR)
PYTHON_LOGGER.setLevel(logging.DEBUG)
# Absolute path to the folder location of this python file
FOLDER_ABSOLUTE_PATH = os.path.normpath(os.path.dirname(os.path.abspath(__file__)))
if __name__ == "__main__":
from neural import sigmoid
from dino_game import GameController, width
game_speed = Input(value=0)
distance_next_obstacle = Input(value=0)
gap_between_obstacles = Input(value=0)
input_list = [game_speed, distance_next_obstacle, gap_between_obstacles]
neuron_jump = Neuron(input_liste=input_list, max_value=1.0, activation_function=sigmoid)
neuron_no_jump = Neuron(input_liste=input_list, max_value=1.0, activation_function=sigmoid)
controller = GameController(numbers_of_dino=1)
while True:
if controller.game_is_over():
neuron_jump = Neuron(input_liste=input_list, max_value=1.0, activation_function=sigmoid)
neuron_no_jump = Neuron(input_liste=input_list, max_value=1.0, activation_function=sigmoid)
controller.restart_game()
else:
game_speed.set_value(controller.get_speed() / 100.0)
distance_next_obstacle.set_value(controller.get_distance_of_first_obstacle() / float(width))
gap_between_obstacles.set_value(controller.get_distance_between_first_and_second_obstacle() / float(width))
if neuron_jump.compute() > neuron_no_jump.compute():
controller.jump(dino_id=0)
time.sleep(0.1)