forked from wT-/TekkenBot
-
Notifications
You must be signed in to change notification settings - Fork 45
/
BotRecorder.py
92 lines (61 loc) · 2.88 KB
/
BotRecorder.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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
from tkinter import *
from tkinter.ttk import *
import time
from datetime import date
from MatchRecorder import MatchRecorder
from TekkenGameState import TekkenGameState
from GameInputter import *
from BasicCommands import *
from NotationParser import *
class BotRecorder():
def __init__(self):
self.toplevel = Tk()
self.recorder = MatchRecorder()
self.game_state = TekkenGameState()
self.playback_going = False
self.is_recording = False #set this to true to record some matches
self.is_playback_mode = True
def update_launcher(self):
time1 = time.time()
buffer = 4
successful = self.game_state.Update(buffer)
if successful and self.game_state.IsGameHappening():
if self.game_state.WasTimerReset():
print("timer reset")
if self.is_recording:
self.recorder.PrintInputLog()
self.playback_going = False
if self.game_state.DidTimerStartTicking(buffer + 60):
self.playback("2017_Jul_20_22.15.36S_ALISAvKING")
print("ticking begins")
if self.is_recording:
self.recorder = MatchRecorder()
self.playback_going = True
if len(self.game_state.stateLog) > 2:
self.recorder.Update(self.game_state)
if self.playback_going and self.is_playback_mode:
self.p1_controller.Update(self.game_state.IsForegroundPID(), self.game_state.IsBotOnLeft())
self.p2_controller.Update(self.game_state.IsForegroundPID(), not self.game_state.IsBotOnLeft())
self.p1_bot.Update(self.game_state)
self.p2_bot.Update(self.game_state)
time2 = time.time()
elapsed_time = 1000 * (time2 - time1)
self.toplevel.after(max(2, 8 - int(round(elapsed_time))), self.update_launcher)
def playback(self, filename):
p1_controller = GameControllerInputter(False)
p2_controller = GameControllerInputter(True)
p1_bot = BotCommands(p1_controller, True)
p2_bot = BotCommands(p2_controller, True)
with open("TekkenData/Replays/" + filename) as fr:
p1_commands = fr.readline().strip()
p2_commands = fr.readline().strip()
p1_bot.AddCommand([(Command.ReleaseAll, 0), (Command.Wait, 1)] + ParseMoveList(p1_commands) + [(Command.ReleaseAll, 1)])
p2_bot.AddCommand([(Command.ReleaseAll, 0), (Command.Wait, 1)] + ParseMoveList(p2_commands) + [(Command.ReleaseAll, 1)])
self.p1_controller = p1_controller
self.p2_controller = p2_controller
self.p1_bot = p1_bot
self.p2_bot = p2_bot
if __name__ == '__main__':
app = BotRecorder()
app.update_launcher()
app.toplevel.mainloop()