-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathreplay_sampler.py
58 lines (40 loc) · 1.33 KB
/
replay_sampler.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
# Author: Mikita Sazanovich
import sys
sys.path.append('.')
from dotaenv import DotaEnvironment
import pickle
import argparse
import os
def transform_into_pair(state):
return state[:83], state[83:]
def record(filename):
env = DotaEnvironment()
state = env.reset()
states = [transform_into_pair(state)]
done = False
while not done:
next_state, reward, done = env.execute(action=0)
states.append(transform_into_pair(next_state))
with open(filename, 'wb') as output_file:
pickle.dump(states, output_file)
def print_out(filename):
with open(filename, 'rb') as input_file:
states = pickle.load(input_file)
for state in states:
observe, actions = state
print('observe', observe[[0, 1, 2, 11, 12, 19, 20]])
print('actions', actions)
print(len(states))
def main():
parser = argparse.ArgumentParser()
parser.add_argument('replay_name')
parser.add_argument('--record', action='store_true', help='Records your actions in the game')
parser.add_argument('--print', action='store_true', help='Print the recorded actions')
args = parser.parse_args()
filename = os.path.join('replays/', args.replay_name)
if args.record:
record(filename)
if args.print:
print_out(filename)
if __name__ == '__main__':
main()