-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcollector_base.pyx
59 lines (52 loc) · 1.56 KB
/
collector_base.pyx
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
from cython import ccall, cclass, locals, returns
from interface import (clear_all_checkpoints, create_checkpoint,
load_from_checkpoint)
@cclass
class BaseCollector:
"""
Abstract collector class, defines the interface.
"""
@locals(level='dict', bot='BaseBot')
def __init__(self, level, bot):
"""
Initializes the collector for the given level and bot.
"""
self.level = level
self.bot = bot
self.checkpoints = []
@ccall
@returns('int')
@locals(checkpoint='int', bot='BaseBot')
def create_checkpoint(self):
"""
Marks game and bot state for future restoration.
"""
checkpoint = create_checkpoint()
bot = self.bot.clone()
self.checkpoints.append((checkpoint, bot))
return len(self.checkpoints) - 1
@ccall
@returns('void')
@locals(index='int', checkpoint='int', bot='BaseBot')
def load_checkpoint(self, index):
"""
Brings the game and bot state to a past point.
"""
checkpoint, bot = self.checkpoints[index]
load_from_checkpoint(checkpoint)
self.bot = bot
@ccall
@returns('void')
def clear_checkpoints(self):
"""
Removes all checkpoints (potentially freeing up some memory).
"""
clear_all_checkpoints()
self.checkpoints = []
@ccall
@returns('dict')
def collect(self):
"""
The main collector function, returns a dict of data to be stored.
"""
raise NotImplementedError()