ThalesGroup / kessler-game

Kessler is a simulation environment loosely modeled after our internal project PsiBee and the external project Fuzzy Asteroids. The game has ships that shoot bullets at asteroids to gain score. Ships can collide with asteroids and other ships and lose lives.
https://github.com/ThalesGroup/kessler-game
Apache License 2.0
8 stars 5 forks source link

Bug: Asteroid duplication, asteroid can collide with multiple bullets/mines/ships and spawn multiple sets of children #45

Closed Jie-F closed 6 months ago

Jie-F commented 7 months ago

In the update() loop when checking asteroid-bullet collisions, after an asteroid collides with a bullet, the asteroid can go on to collide with more bullets in subsequent loop iterations, and each time it collides, it spawns off 3 new children.

image

To fix this, we can add the following check, so that asteroids marked for removal cannot go on to collide with more bullets:

image

And as a possible optimization, we can actually just cull the asteroids once at the end of update(), and along the way just skip over indices that are marked for removal. That's what I'm doing in my controller to reduce the amount of list comprehensions.

Super sneaky bug that I only found with randomized testing, where my controller using different collision code desynced with the game for seemingly no reason.

Jie-F commented 7 months ago

Oops, missed that this same bug happens in the other loops for mine-asteroid and ship-asteroid collisions too. As a fix, I'll just change over the entire asteroid culling to do one list comprehension at the end, and collect and check deleted asteroid indices along the way. This will fix the bug, along with speeding up asteroid culling.