|
@@ -0,0 +1,509 @@
|
|
1
|
+# coding: utf-8
|
|
2
|
+import pytest
|
|
3
|
+from freezegun import freeze_time
|
|
4
|
+from synergine2_xyz.move.intention import MoveToIntention
|
|
5
|
+from synergine2_xyz.simulation import XYZSimulation
|
|
6
|
+
|
|
7
|
+from opencombat.simulation.move import MoveWithRotationBehaviour
|
|
8
|
+from opencombat.simulation.move import MoveToMechanism
|
|
9
|
+from opencombat.simulation.move import MoveBehaviour
|
|
10
|
+from opencombat.simulation.move import SubjectFinishMoveEvent
|
|
11
|
+from opencombat.simulation.move import SubjectStartRotationEvent
|
|
12
|
+from opencombat.simulation.move import SubjectFinishRotationEvent
|
|
13
|
+from opencombat.simulation.move import SubjectContinueRotationEvent
|
|
14
|
+from opencombat.simulation.move import SubjectStartTileMoveEvent
|
|
15
|
+from opencombat.simulation.move import SubjectContinueTileMoveEvent
|
|
16
|
+from opencombat.simulation.move import SubjectFinishTileMoveEvent
|
|
17
|
+from opencombat.simulation.subject import TankSubject
|
|
18
|
+from opencombat.simulation.subject import ManSubject
|
|
19
|
+from opencombat.user_action import UserAction
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+def test_move_and_rotate_behaviour__begin_rotate(config):
|
|
23
|
+ simulation = XYZSimulation(config)
|
|
24
|
+ simulation.physics.graph.add_edge('0.0', '1.1', {})
|
|
25
|
+ simulation.physics.graph.add_edge('1.1', '2.1', {})
|
|
26
|
+
|
|
27
|
+ subject = TankSubject(
|
|
28
|
+ config,
|
|
29
|
+ simulation,
|
|
30
|
+ position=(0, 0),
|
|
31
|
+ )
|
|
32
|
+ move = MoveToIntention(
|
|
33
|
+ to=(2, 1),
|
|
34
|
+ gui_action=UserAction.ORDER_MOVE,
|
|
35
|
+ )
|
|
36
|
+ subject.intentions.set(move)
|
|
37
|
+
|
|
38
|
+ move_behaviour = MoveWithRotationBehaviour(
|
|
39
|
+ config=config,
|
|
40
|
+ simulation=simulation,
|
|
41
|
+ subject=subject,
|
|
42
|
+ )
|
|
43
|
+
|
|
44
|
+ # Rotation required to begin move
|
|
45
|
+ with freeze_time("2000-01-01 00:00:00", tz_offset=0):
|
|
46
|
+ data = move_behaviour.run({MoveToMechanism: move.get_data()})
|
|
47
|
+ assert {
|
|
48
|
+ 'gui_action': UserAction.ORDER_MOVE,'gui_action': UserAction.ORDER_MOVE,
|
|
49
|
+ 'path': [
|
|
50
|
+ (0, 0),
|
|
51
|
+ (1, 1),
|
|
52
|
+ (2, 1),
|
|
53
|
+ ],
|
|
54
|
+ 'rotate_relative': 45,
|
|
55
|
+ 'rotate_absolute': 45,
|
|
56
|
+ } == data
|
|
57
|
+
|
|
58
|
+ events = move_behaviour.action(data)
|
|
59
|
+ assert events
|
|
60
|
+ assert 1 == len(events)
|
|
61
|
+ assert isinstance(events[0], SubjectStartRotationEvent)
|
|
62
|
+ assert 45.0 == events[0].rotate_relative
|
|
63
|
+ assert 4.9995 == events[0].duration
|
|
64
|
+ assert subject.position == (0, 0)
|
|
65
|
+ assert subject.direction == 0
|
|
66
|
+ assert subject.rotate_to == 45
|
|
67
|
+ assert subject.start_rotation == 946684800.0
|
|
68
|
+ assert subject.rotate_duration == 4.9995
|
|
69
|
+ assert subject.intentions.get(MoveToIntention)
|
|
70
|
+
|
|
71
|
+ # This is 1 second before end of rotation
|
|
72
|
+ with freeze_time("2000-01-01 00:00:04", tz_offset=0):
|
|
73
|
+ data = move_behaviour.run({MoveToMechanism: move.get_data()})
|
|
74
|
+ assert {
|
|
75
|
+ 'gui_action': UserAction.ORDER_MOVE,
|
|
76
|
+ 'rotate_relative': 45,
|
|
77
|
+ 'rotate_absolute': 45,
|
|
78
|
+ } == data
|
|
79
|
+
|
|
80
|
+ events = move_behaviour.action(data)
|
|
81
|
+ assert 1 == len(events)
|
|
82
|
+ assert isinstance(events[0], SubjectContinueRotationEvent)
|
|
83
|
+ assert 9 == round(events[0].rotate_relative)
|
|
84
|
+ assert 0.9995 == events[0].duration
|
|
85
|
+ assert subject.position == (0, 0)
|
|
86
|
+ assert int(subject.direction) == 36
|
|
87
|
+ assert subject.rotate_to == 45
|
|
88
|
+ assert subject.start_rotation == 946684804.0
|
|
89
|
+ assert subject.rotate_duration == 0.9995
|
|
90
|
+ assert subject.intentions.get(MoveToIntention)
|
|
91
|
+
|
|
92
|
+ # We are now just after rotation duration, a move will start
|
|
93
|
+ with freeze_time("2000-01-01 00:00:05", tz_offset=0):
|
|
94
|
+ data = move_behaviour.run({MoveToMechanism: move.get_data()})
|
|
95
|
+ assert {
|
|
96
|
+ 'gui_action': UserAction.ORDER_MOVE,
|
|
97
|
+ 'tile_move_to': (1, 1),
|
|
98
|
+ 'rotate_to_finished': 45,
|
|
99
|
+ } == data
|
|
100
|
+
|
|
101
|
+ events = move_behaviour.action(data)
|
|
102
|
+ assert 2 == len(events)
|
|
103
|
+ assert isinstance(events[1], SubjectStartTileMoveEvent)
|
|
104
|
+ assert isinstance(events[0], SubjectFinishRotationEvent)
|
|
105
|
+ assert (1, 1) == events[1].move_to
|
|
106
|
+ assert 9.0 == events[1].duration
|
|
107
|
+ assert subject.position == (0, 0)
|
|
108
|
+ assert subject.moving_to == (1, 1)
|
|
109
|
+ assert subject.move_duration == 9.0
|
|
110
|
+ assert subject.start_move == 946684805.0
|
|
111
|
+ assert subject.intentions.get(MoveToIntention)
|
|
112
|
+
|
|
113
|
+ # We are during the move
|
|
114
|
+ with freeze_time("2000-01-01 00:00:13", tz_offset=0):
|
|
115
|
+ data = move_behaviour.run({MoveToMechanism: move.get_data()})
|
|
116
|
+ assert {
|
|
117
|
+ 'gui_action': UserAction.ORDER_MOVE,
|
|
118
|
+ 'tile_move_to': (1, 1),
|
|
119
|
+ } == data
|
|
120
|
+
|
|
121
|
+ events = move_behaviour.action(data)
|
|
122
|
+ assert 1 == len(events)
|
|
123
|
+ assert isinstance(events[0], SubjectContinueTileMoveEvent)
|
|
124
|
+ assert (1, 1) == events[0].move_to
|
|
125
|
+ assert 1.0 == events[0].duration
|
|
126
|
+ assert subject.intentions.get(MoveToIntention)
|
|
127
|
+
|
|
128
|
+ # We are after the move
|
|
129
|
+ with freeze_time("2000-01-01 00:00:14", tz_offset=0):
|
|
130
|
+ data = move_behaviour.run({MoveToMechanism: move.get_data()})
|
|
131
|
+ assert {
|
|
132
|
+ 'gui_action': UserAction.ORDER_MOVE,
|
|
133
|
+ 'tile_move_to_finished': (1, 1),
|
|
134
|
+ 'rotate_relative': 45,
|
|
135
|
+ 'rotate_absolute': 90,
|
|
136
|
+ } == data
|
|
137
|
+
|
|
138
|
+ events = move_behaviour.action(data)
|
|
139
|
+ assert 2 == len(events)
|
|
140
|
+ assert isinstance(events[0], SubjectFinishTileMoveEvent)
|
|
141
|
+ assert isinstance(events[1], SubjectStartRotationEvent)
|
|
142
|
+ assert (1, 1) == events[0].move_to
|
|
143
|
+ assert 4.9995 == events[1].duration
|
|
144
|
+ assert 45 == events[1].rotate_relative
|
|
145
|
+ assert (1, 1) == subject.position
|
|
146
|
+ assert (-1, -1) == subject.moving_to
|
|
147
|
+ assert -1 == subject.start_move
|
|
148
|
+ assert -1 == subject.move_duration
|
|
149
|
+ assert subject.rotate_to == 90
|
|
150
|
+ assert subject.start_rotation == 946684814.0
|
|
151
|
+ assert subject.rotate_duration == 4.9995
|
|
152
|
+ assert subject.intentions.get(MoveToIntention)
|
|
153
|
+
|
|
154
|
+ # We are rotating
|
|
155
|
+ with freeze_time("2000-01-01 00:00:18", tz_offset=0):
|
|
156
|
+ data = move_behaviour.run({MoveToMechanism: move.get_data()})
|
|
157
|
+ assert {
|
|
158
|
+ 'gui_action': UserAction.ORDER_MOVE,
|
|
159
|
+ 'rotate_relative': 45,
|
|
160
|
+ 'rotate_absolute': 90,
|
|
161
|
+ } == data
|
|
162
|
+
|
|
163
|
+ events = move_behaviour.action(data)
|
|
164
|
+ assert 1 == len(events)
|
|
165
|
+ assert isinstance(events[0], SubjectContinueRotationEvent)
|
|
166
|
+ assert 9 == round(events[0].rotate_relative)
|
|
167
|
+ assert 0.9995 == events[0].duration
|
|
168
|
+ assert subject.position == (1, 1)
|
|
169
|
+ assert int(subject.direction) == 81
|
|
170
|
+ assert subject.rotate_to == 90
|
|
171
|
+ assert subject.start_rotation == 946684818.0
|
|
172
|
+ assert subject.rotate_duration == 0.9995
|
|
173
|
+ assert subject.intentions.get(MoveToIntention)
|
|
174
|
+
|
|
175
|
+ # We finish rotating and start to move to final tile
|
|
176
|
+ with freeze_time("2000-01-01 00:00:19", tz_offset=0):
|
|
177
|
+ data = move_behaviour.run({MoveToMechanism: move.get_data()})
|
|
178
|
+ assert {
|
|
179
|
+ 'gui_action': UserAction.ORDER_MOVE,
|
|
180
|
+ 'tile_move_to': (2, 1),
|
|
181
|
+ 'rotate_to_finished': 90,
|
|
182
|
+ } == data
|
|
183
|
+
|
|
184
|
+ events = move_behaviour.action(data)
|
|
185
|
+ assert 2 == len(events)
|
|
186
|
+ assert isinstance(events[1], SubjectStartTileMoveEvent)
|
|
187
|
+ assert isinstance(events[0], SubjectFinishRotationEvent)
|
|
188
|
+ assert (2, 1) == events[1].move_to
|
|
189
|
+ assert 9.0 == events[1].duration
|
|
190
|
+ assert subject.position == (1, 1)
|
|
191
|
+ assert subject.moving_to == (2, 1)
|
|
192
|
+ assert subject.move_duration == 9.0
|
|
193
|
+ assert subject.start_move == 946684819.0
|
|
194
|
+ assert subject.intentions.get(MoveToIntention)
|
|
195
|
+
|
|
196
|
+ # We are moving to final tile
|
|
197
|
+ with freeze_time("2000-01-01 00:00:27", tz_offset=0):
|
|
198
|
+ data = move_behaviour.run({MoveToMechanism: move.get_data()})
|
|
199
|
+ assert {
|
|
200
|
+ 'gui_action': UserAction.ORDER_MOVE,
|
|
201
|
+ 'tile_move_to': (2, 1),
|
|
202
|
+ } == data
|
|
203
|
+
|
|
204
|
+ events = move_behaviour.action(data)
|
|
205
|
+ assert 1 == len(events)
|
|
206
|
+ assert isinstance(events[0], SubjectContinueTileMoveEvent)
|
|
207
|
+ assert (2, 1) == events[0].move_to
|
|
208
|
+ assert 1.0 == events[0].duration
|
|
209
|
+ assert subject.intentions.get(MoveToIntention)
|
|
210
|
+
|
|
211
|
+ # We arrived on final tile
|
|
212
|
+ with freeze_time("2000-01-01 00:00:28", tz_offset=0):
|
|
213
|
+ data = move_behaviour.run({MoveToMechanism: move.get_data()})
|
|
214
|
+ assert {
|
|
215
|
+ 'gui_action': UserAction.ORDER_MOVE,
|
|
216
|
+ 'move_to_finished': (2, 1),
|
|
217
|
+ } == data
|
|
218
|
+
|
|
219
|
+ events = move_behaviour.action(data)
|
|
220
|
+ assert 1 == len(events)
|
|
221
|
+ assert isinstance(events[0], SubjectFinishMoveEvent)
|
|
222
|
+ assert (2, 1) == events[0].move_to
|
|
223
|
+ assert (2, 1) == subject.position
|
|
224
|
+ assert (-1, -1) == subject.moving_to
|
|
225
|
+ assert -1 == subject.start_move
|
|
226
|
+ assert -1 == subject.move_duration
|
|
227
|
+ with pytest.raises(KeyError):
|
|
228
|
+ assert subject.intentions.get(MoveToIntention)
|
|
229
|
+
|
|
230
|
+
|
|
231
|
+def test_move_and_rotate_behaviour__begin_move(config):
|
|
232
|
+ simulation = XYZSimulation(config)
|
|
233
|
+ simulation.physics.graph.add_edge('0.0', '0.1', {})
|
|
234
|
+ simulation.physics.graph.add_edge('0.1', '1.1', {})
|
|
235
|
+
|
|
236
|
+ subject = TankSubject(
|
|
237
|
+ config,
|
|
238
|
+ simulation,
|
|
239
|
+ position=(0, 0),
|
|
240
|
+ )
|
|
241
|
+ move = MoveToIntention(
|
|
242
|
+ to=(1, 1),
|
|
243
|
+ gui_action=UserAction.ORDER_MOVE,
|
|
244
|
+ )
|
|
245
|
+ subject.intentions.set(move)
|
|
246
|
+
|
|
247
|
+ move_behaviour = MoveWithRotationBehaviour(
|
|
248
|
+ config=config,
|
|
249
|
+ simulation=simulation,
|
|
250
|
+ subject=subject,
|
|
251
|
+ )
|
|
252
|
+
|
|
253
|
+ # First is a move
|
|
254
|
+ with freeze_time("2000-01-01 00:00:00", tz_offset=0):
|
|
255
|
+ data = move_behaviour.run({MoveToMechanism: move.get_data()})
|
|
256
|
+ assert {
|
|
257
|
+ 'gui_action': UserAction.ORDER_MOVE,
|
|
258
|
+ 'path': [
|
|
259
|
+ (0, 0),
|
|
260
|
+ (0, 1),
|
|
261
|
+ (1, 1),
|
|
262
|
+ ],
|
|
263
|
+ 'tile_move_to': (0, 1),
|
|
264
|
+ } == data
|
|
265
|
+
|
|
266
|
+ events = move_behaviour.action(data)
|
|
267
|
+ assert 1 == len(events)
|
|
268
|
+ assert isinstance(events[0], SubjectStartTileMoveEvent)
|
|
269
|
+ assert (0, 1) == events[0].move_to
|
|
270
|
+ assert 9.0 == events[0].duration
|
|
271
|
+ assert subject.intentions.get(MoveToIntention)
|
|
272
|
+
|
|
273
|
+ # Continue the move, rest 1s
|
|
274
|
+ with freeze_time("2000-01-01 00:00:08", tz_offset=0):
|
|
275
|
+ data = move_behaviour.run({MoveToMechanism: move.get_data()})
|
|
276
|
+ assert {
|
|
277
|
+ 'gui_action': UserAction.ORDER_MOVE,
|
|
278
|
+ 'tile_move_to': (0, 1),
|
|
279
|
+ } == data
|
|
280
|
+
|
|
281
|
+ events = move_behaviour.action(data)
|
|
282
|
+ assert 1 == len(events)
|
|
283
|
+ assert isinstance(events[0], SubjectContinueTileMoveEvent)
|
|
284
|
+ assert (0, 1) == events[0].move_to
|
|
285
|
+ assert 1.0 == events[0].duration
|
|
286
|
+ assert subject.intentions.get(MoveToIntention)
|
|
287
|
+
|
|
288
|
+ # Tile move finished, begin a rotate
|
|
289
|
+ with freeze_time("2000-01-01 00:00:09", tz_offset=0):
|
|
290
|
+ data = move_behaviour.run({MoveToMechanism: move.get_data()})
|
|
291
|
+ assert {
|
|
292
|
+ 'gui_action': UserAction.ORDER_MOVE,
|
|
293
|
+ 'tile_move_to_finished': (0, 1),
|
|
294
|
+ 'rotate_relative': 90,
|
|
295
|
+ 'rotate_absolute': 90,
|
|
296
|
+ } == data
|
|
297
|
+
|
|
298
|
+ events = move_behaviour.action(data)
|
|
299
|
+ assert 2 == len(events)
|
|
300
|
+ assert isinstance(events[0], SubjectFinishTileMoveEvent)
|
|
301
|
+ assert isinstance(events[1], SubjectStartRotationEvent)
|
|
302
|
+ assert (0, 1) == events[0].move_to
|
|
303
|
+ assert 10 == round(events[1].duration)
|
|
304
|
+ assert 90 == events[1].rotate_relative
|
|
305
|
+ assert (0, 1) == subject.position
|
|
306
|
+ assert (-1, -1) == subject.moving_to
|
|
307
|
+ assert -1 == subject.start_move
|
|
308
|
+ assert -1 == subject.move_duration
|
|
309
|
+ assert subject.rotate_to == 90
|
|
310
|
+ assert subject.start_rotation == 946684809.0
|
|
311
|
+ assert round(subject.rotate_duration) == 10
|
|
312
|
+ assert subject.intentions.get(MoveToIntention)
|
|
313
|
+
|
|
314
|
+ # We are rotating, rest 1s
|
|
315
|
+ with freeze_time("2000-01-01 00:00:18", tz_offset=0):
|
|
316
|
+ data = move_behaviour.run({MoveToMechanism: move.get_data()})
|
|
317
|
+ assert {
|
|
318
|
+ 'gui_action': UserAction.ORDER_MOVE,
|
|
319
|
+ 'rotate_relative': 90,
|
|
320
|
+ 'rotate_absolute': 90,
|
|
321
|
+ } == data
|
|
322
|
+
|
|
323
|
+ events = move_behaviour.action(data)
|
|
324
|
+ assert 1 == len(events)
|
|
325
|
+ assert isinstance(events[0], SubjectContinueRotationEvent)
|
|
326
|
+ assert 9 == round(events[0].rotate_relative)
|
|
327
|
+ assert 1 == round(events[0].duration)
|
|
328
|
+ assert subject.position == (0, 1)
|
|
329
|
+ assert int(subject.direction) == 81
|
|
330
|
+ assert subject.rotate_to == 90
|
|
331
|
+ assert subject.start_rotation == 946684818.0
|
|
332
|
+ assert round(subject.rotate_duration) == 1
|
|
333
|
+ assert subject.intentions.get(MoveToIntention)
|
|
334
|
+
|
|
335
|
+ # We finish rotating and start to move to final tile
|
|
336
|
+ with freeze_time("2000-01-01 00:00:19", tz_offset=0):
|
|
337
|
+ data = move_behaviour.run({MoveToMechanism: move.get_data()})
|
|
338
|
+ assert {
|
|
339
|
+ 'gui_action': UserAction.ORDER_MOVE,
|
|
340
|
+ 'tile_move_to': (1, 1),
|
|
341
|
+ 'rotate_to_finished': 90,
|
|
342
|
+ } == data
|
|
343
|
+
|
|
344
|
+ events = move_behaviour.action(data)
|
|
345
|
+ assert 2 == len(events)
|
|
346
|
+ assert isinstance(events[1], SubjectStartTileMoveEvent)
|
|
347
|
+ assert isinstance(events[0], SubjectFinishRotationEvent)
|
|
348
|
+ assert (1, 1) == events[1].move_to
|
|
349
|
+ assert 9.0 == events[1].duration
|
|
350
|
+ assert subject.position == (0, 1)
|
|
351
|
+ assert subject.moving_to == (1, 1)
|
|
352
|
+ assert subject.move_duration == 9.0
|
|
353
|
+ assert subject.start_move == 946684819.0
|
|
354
|
+ assert subject.intentions.get(MoveToIntention)
|
|
355
|
+
|
|
356
|
+ # Continue the move, rest 1s
|
|
357
|
+ with freeze_time("2000-01-01 00:00:27", tz_offset=0):
|
|
358
|
+ data = move_behaviour.run({MoveToMechanism: move.get_data()})
|
|
359
|
+ assert {
|
|
360
|
+ 'gui_action': UserAction.ORDER_MOVE,
|
|
361
|
+ 'tile_move_to': (1, 1),
|
|
362
|
+ } == data
|
|
363
|
+
|
|
364
|
+ events = move_behaviour.action(data)
|
|
365
|
+ assert 1 == len(events)
|
|
366
|
+ assert isinstance(events[0], SubjectContinueTileMoveEvent)
|
|
367
|
+ assert (1, 1) == events[0].move_to
|
|
368
|
+ assert 1.0 == events[0].duration
|
|
369
|
+ assert subject.moving_to == (1, 1)
|
|
370
|
+ assert subject.move_duration == 1.0
|
|
371
|
+ assert subject.start_move == 946684819.0
|
|
372
|
+ assert subject.intentions.get(MoveToIntention)
|
|
373
|
+
|
|
374
|
+ # We arrived on final tile
|
|
375
|
+ with freeze_time("2000-01-01 00:00:28", tz_offset=0):
|
|
376
|
+ data = move_behaviour.run({MoveToMechanism: move.get_data()})
|
|
377
|
+ assert {
|
|
378
|
+ 'gui_action': UserAction.ORDER_MOVE,
|
|
379
|
+ 'move_to_finished': (1, 1),
|
|
380
|
+ } == data
|
|
381
|
+
|
|
382
|
+ events = move_behaviour.action(data)
|
|
383
|
+ assert 1 == len(events)
|
|
384
|
+ assert isinstance(events[0], SubjectFinishMoveEvent)
|
|
385
|
+ assert (1, 1) == events[0].move_to
|
|
386
|
+ assert (1, 1) == subject.position
|
|
387
|
+ assert (-1, -1) == subject.moving_to
|
|
388
|
+ assert -1 == subject.start_move
|
|
389
|
+ assert -1 == subject.move_duration
|
|
390
|
+ with pytest.raises(KeyError):
|
|
391
|
+ assert subject.intentions.get(MoveToIntention)
|
|
392
|
+
|
|
393
|
+
|
|
394
|
+def test_move_behaviour(config):
|
|
395
|
+ simulation = XYZSimulation(config)
|
|
396
|
+ simulation.physics.graph.add_edge('0.0', '0.1', {})
|
|
397
|
+ simulation.physics.graph.add_edge('0.1', '1.1', {})
|
|
398
|
+
|
|
399
|
+ subject = ManSubject(
|
|
400
|
+ config,
|
|
401
|
+ simulation,
|
|
402
|
+ position=(0, 0),
|
|
403
|
+ )
|
|
404
|
+ move = MoveToIntention(
|
|
405
|
+ to=(1, 1),
|
|
406
|
+ gui_action=UserAction.ORDER_MOVE,
|
|
407
|
+ )
|
|
408
|
+ subject.intentions.set(move)
|
|
409
|
+
|
|
410
|
+ move_behaviour = MoveBehaviour(
|
|
411
|
+ config=config,
|
|
412
|
+ simulation=simulation,
|
|
413
|
+ subject=subject,
|
|
414
|
+ )
|
|
415
|
+
|
|
416
|
+ # First begin move
|
|
417
|
+ with freeze_time("2000-01-01 00:00:00", tz_offset=0):
|
|
418
|
+ data = move_behaviour.run({MoveToMechanism: move.get_data()})
|
|
419
|
+ assert {
|
|
420
|
+ 'gui_action': UserAction.ORDER_MOVE,
|
|
421
|
+ 'path': [
|
|
422
|
+ (0, 0),
|
|
423
|
+ (0, 1),
|
|
424
|
+ (1, 1),
|
|
425
|
+ ],
|
|
426
|
+ 'tile_move_to': (0, 1),
|
|
427
|
+ } == data
|
|
428
|
+
|
|
429
|
+ events = move_behaviour.action(data)
|
|
430
|
+ assert 1 == len(events)
|
|
431
|
+ assert isinstance(events[0], SubjectStartTileMoveEvent)
|
|
432
|
+ assert (0, 1) == events[0].move_to
|
|
433
|
+ assert 3.0 == events[0].duration
|
|
434
|
+ assert subject.intentions.get(MoveToIntention)
|
|
435
|
+
|
|
436
|
+ # Continue the move, rest 1s
|
|
437
|
+ with freeze_time("2000-01-01 00:00:02", tz_offset=0):
|
|
438
|
+ data = move_behaviour.run({MoveToMechanism: move.get_data()})
|
|
439
|
+ assert {
|
|
440
|
+ 'gui_action': UserAction.ORDER_MOVE,
|
|
441
|
+ 'tile_move_to': (0, 1),
|
|
442
|
+ } == data
|
|
443
|
+
|
|
444
|
+ events = move_behaviour.action(data)
|
|
445
|
+ assert 1 == len(events)
|
|
446
|
+ assert isinstance(events[0], SubjectContinueTileMoveEvent)
|
|
447
|
+ assert (0, 1) == events[0].move_to
|
|
448
|
+ assert 1.0 == events[0].duration
|
|
449
|
+ assert subject.intentions.get(MoveToIntention)
|
|
450
|
+
|
|
451
|
+ # Tile move finished, begin a new move
|
|
452
|
+ with freeze_time("2000-01-01 00:00:03", tz_offset=0):
|
|
453
|
+ data = move_behaviour.run({MoveToMechanism: move.get_data()})
|
|
454
|
+ assert {
|
|
455
|
+ 'gui_action': UserAction.ORDER_MOVE,
|
|
456
|
+ 'tile_move_to_finished': (0, 1),
|
|
457
|
+ 'tile_move_to': (1, 1),
|
|
458
|
+ } == data
|
|
459
|
+
|
|
460
|
+ events = move_behaviour.action(data)
|
|
461
|
+ assert 2 == len(events)
|
|
462
|
+ assert isinstance(events[0], SubjectFinishTileMoveEvent)
|
|
463
|
+ assert isinstance(events[1], SubjectStartTileMoveEvent)
|
|
464
|
+ assert (0, 1) == events[0].move_to
|
|
465
|
+ assert (1, 1) == events[1].move_to
|
|
466
|
+ assert 3 == events[1].duration
|
|
467
|
+ assert (0, 1) == subject.position
|
|
468
|
+ assert (1, 1) == subject.moving_to
|
|
469
|
+ assert 946684803.0 == subject.start_move
|
|
470
|
+ assert 3 == subject.move_duration
|
|
471
|
+ assert subject.intentions.get(MoveToIntention)
|
|
472
|
+
|
|
473
|
+ # We are moving, rest 1s
|
|
474
|
+ with freeze_time("2000-01-01 00:00:05", tz_offset=0):
|
|
475
|
+ data = move_behaviour.run({MoveToMechanism: move.get_data()})
|
|
476
|
+ assert {
|
|
477
|
+ 'gui_action': UserAction.ORDER_MOVE,
|
|
478
|
+ 'tile_move_to': (1, 1),
|
|
479
|
+ } == data
|
|
480
|
+
|
|
481
|
+ events = move_behaviour.action(data)
|
|
482
|
+ assert 1 == len(events)
|
|
483
|
+ assert isinstance(events[0], SubjectContinueTileMoveEvent)
|
|
484
|
+ assert (1, 1) == events[0].move_to
|
|
485
|
+ assert 1.0 == events[0].duration
|
|
486
|
+ assert (0, 1) == subject.position
|
|
487
|
+ assert (1, 1) == subject.moving_to
|
|
488
|
+ assert 946684805.0 == subject.start_move
|
|
489
|
+ assert 1 == subject.move_duration
|
|
490
|
+ assert subject.intentions.get(MoveToIntention)
|
|
491
|
+
|
|
492
|
+ # We arrived on final tile
|
|
493
|
+ with freeze_time("2000-01-01 00:00:06", tz_offset=0):
|
|
494
|
+ data = move_behaviour.run({MoveToMechanism: move.get_data()})
|
|
495
|
+ assert {
|
|
496
|
+ 'gui_action': UserAction.ORDER_MOVE,
|
|
497
|
+ 'move_to_finished': (1, 1),
|
|
498
|
+ } == data
|
|
499
|
+
|
|
500
|
+ events = move_behaviour.action(data)
|
|
501
|
+ assert 1 == len(events)
|
|
502
|
+ assert isinstance(events[0], SubjectFinishMoveEvent)
|
|
503
|
+ assert (1, 1) == events[0].move_to
|
|
504
|
+ assert (1, 1) == subject.position
|
|
505
|
+ assert (-1, -1) == subject.moving_to
|
|
506
|
+ assert -1 == subject.start_move
|
|
507
|
+ assert -1 == subject.move_duration
|
|
508
|
+ with pytest.raises(KeyError):
|
|
509
|
+ assert subject.intentions.get(MoveToIntention)
|