/
logic.py
216 lines (143 loc) · 4.3 KB
/
logic.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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
from abc import ABCMeta
from helper_classes import OrderList
from typing import List # this is jus to help linters
# TODO: who calls what? See the GitHub Issue.
class Order(metaclass=ABCMeta):
"""All orders inherit from this order."""
@classmethod
def execute(cls, bot: Bot):
raise NotImplementedError()
class SpecialOrder(Order, metaclass=ABCMeta):
"""All special orders inherit from this order."""
class Forward(Order):
forward_constant = 1
@classmethod
def execute(cls, bot):
bot.move_forward(cls.forward_constant)
class ForwardTwice(Forward):
forward_constant = 2
class Rotate(Order):
rotate_constant = 1
@classmethod
def execute(cls, bot):
bot.rotate(cls.rotate_constant)
class RotateLeft(Rotate):
rotate_constant = -1
class RotateRight(Rotate):
rotate_constant = 1
class LoadCrystal(Order):
@classmethod
def execute(cls, bot):
bot.loadCrystal()
raise NotImplementedError()
class UnLoadCrystal(Order):
@classmethod
def execute(cls, bot):
bot.unLoadCrystal()
raise NotImplementedError()
class RotateLeftTwice(Rotate, SpecialOrder):
rotate_constant = -1
class RotateRightTwice(Rotate, SpecialOrder):
rotate_constant = 2
class AntiZap(SpecialOrder):
@classmethod
def execute(cls, bot):
bot.anti_zap = True
raise NotImplementedError()
class AntiTheft(SpecialOrder):
@classmethod
def execute(cls, bot):
bot.anti_theft = True
class UTurn(Rotate, SpecialOrder):
rotate_constant = 3
class ForwardThrice(Forward, SpecialOrder):
forward_constant = 3
class ForwardLoad(SpecialOrder):
@classmethod
def execute(cls, bot):
bot.moveForward(1)
bot.loadCrystal()
raise NotImplementedError()
class Dash(SpecialOrder):
@classmethod
def execute(cls, bot):
bot.dash()
class Jump(SpecialOrder):
@classmethod
def execute(cls, bot):
bot.jump()
class BackUp(Forward, SpecialOrder):
forward_constant = -1
class Zap(Order):
long_range, times = False, 2
@classmethod
def execute(cls, bot):
bot.zap(times=cls.times, long_range=cls.long_range)
class ZapTwice(Zap, SpecialOrder):
times = 2
class ZapLongRange(Zap, SpecialOrder):
long_range = True
class ForwardZap(Forward, Zap, SpecialOrder):
forward_constant = 1
@classmethod
def execute(cls, bot):
Forward.execute(bot)
Zap.execute(bot)
class Bot(object):
"""
Attribute API:
bot_team - access team of bot
orders - access orders in bot
"""
def __init__(self, initial_orders: OrderList):
self.orders = initial_orders
...
# TODO: Implement these methods
def move_forward(self, units):
raise NotImplementedError()
def rotate(self, direction):
raise NotImplementedError()
def zap(self, times=1, long_range=False):
raise NotImplementedError()
if times > 1:
self.zap(times - 1, long_range=long_range)
def jump(self):
raise NotImplementedError()
def dash(self):
raise NotImplementedError()
# TODO: either make anti_zap and anti_theft properties (getter/setter)
# if they are not-permanent, or make them regular ol' attributes.
class PlayBoard(object):
_grid = [[]] # TODO: implement hexagonal grid; other devs can help
def __init__(self):
"""Create an empty play board"""
pass
@classmethod
def generate_random_board(cls):
"""
Fill a playboard with random crystals and/or obstacles
You can override this method in subclasses to create new game varieties.
"""
# return cls(...)
pass
class ProgrammingBoard(object):
# TODO: How does the programming board work?
pass
class Player(object):
def __init__(self):
self.owned_orders = [] # type: List[Order]
self.owned_bots = [] # type: List[Bot]
class GameState(object):
"""
Put helper functions to not pollute the namespace.
Because globals are bad.
Directly modify properties.
"""
bots = []
players = []
def __init__(self):
# we should have a simple system to swap out classes to make it extensible
pass
@property
def num_players(self):
return len(self.players)