-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
35 lines (32 loc) · 1.38 KB
/
main.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
from load_model import load_model
import time
from numpy import array
# TODO: define
IO_FN = "com.txt" # file to communicate between ai and csgo helper
MODEL_FN = "./saved_models/BranchedModel_GRU-5layers-v4.h5"
def mod360(v):
return v - (v//360)*360
prev_timestamp = 0
start_time = int(round(time.time() * 1000))
model = load_model(MODEL_FN) # load the model
# continuously checks for input by csgo helper
while True:
status = ""; timestamp = prev_timestamp
# reads game state from shared file with the csgo helper
while status != "input" or int(timestamp) <= prev_timestamp: # check if line type is input and timestamp is different
with open(IO_FN) as inputfile:
last_line = inputfile.readlines()[-1].strip().split(",")
status, timestamp = last_line[:2]
strdata = last_line[2:]
# cleans data to be passed into the neural network
strdata[6] = strdata[6][7:]; strdata[7] = strdata[7][4:]
data = [array([float(d), 0.0, 0.0]) for d in strdata]
new_yaw, new_pitch = model.predict(data)[0] # pass game state into neural network
# writes ideal pitch and yaw to shared file with csgo helper
new_timestamp = int(round(time.time() * 1000)) - start_time
with open(IO_FN, "a") as outputfile:
outputfile.write("output,{},{},{}\n".format(
new_timestamp,
mod360(new_yaw),
mod360(new_pitch)
))