|
| 1 | +from robots.engine_c.engine import * |
| 2 | +from robots.app import App, Battle |
| 3 | +import random |
| 4 | + |
| 5 | +import time |
| 6 | +# app = App() |
| 7 | + |
| 8 | +class RandomRobot(Robot): |
| 9 | + def run(self): |
| 10 | + self.moving = 1 |
| 11 | + self.base_turning = 1 |
| 12 | + self.turret_turning = -1 |
| 13 | + if random.randint(0, 1): |
| 14 | + self.fire(random.randint(1, 3)) |
| 15 | + |
| 16 | +robots = [RandomRobot((255, 0, 0)), RandomRobot((0, 255, 0))] |
| 17 | +eng = Engine(robots=robots) |
| 18 | + |
| 19 | +# app.child = Battle(robots, (600, 400), eng=eng) |
| 20 | +# app.child.set_tick_rate(-1) |
| 21 | +# app.run() |
| 22 | + |
| 23 | + |
| 24 | +print(eng) |
| 25 | +eng.step() |
| 26 | +print([(b.uid, b.owner_uid) for b in eng.bullets]) |
| 27 | + |
| 28 | + |
| 29 | +start = time.perf_counter_ns() |
| 30 | +for i in range(int(1e6)): |
| 31 | + eng.step() |
| 32 | + |
| 33 | +duration = (time.perf_counter_ns() - start)/1e9 |
| 34 | +print(100000/(duration), duration) |
| 35 | +print(eng.get_bullets()) |
| 36 | + |
0 commit comments