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
10 stars 11 forks source link

Off by two error in bullet/mine shooting cooldowns #49

Closed Jie-F closed 8 months ago

Jie-F commented 8 months ago

The ship's fire time is set to 1/10 seconds, and the mine deploy time is set to 1 second. The game runs at 30 FPS, so we would expect that we can fire bullets once every 3 timesteps, and lay mines once every 30. However in reality, we can only shoot once every 5 timesteps and lay a mine once every 32 timesteps. This off-by-two error is caused by the way we're checking whether the cooldown has hit 0.

On the timestep the cooldown "hits zero", it actually hits 1.3877787807814457e-17 in the case of firing bullets, which isn't below 0. We then spend a timestep decrementing this to a negative number, and another timestep setting that to 0, which costs an extra 2 timesteps than expected.

I propose we fix this for clarity, but just in case this breaks people's controllers, we can change the firing rate to 1/6 seconds, so the firing is still once every 5 frames. But the mine cooldown can be changed from 32 to 30 frames.

We can also add in the can_deploy_mine in the boolean that's passed to the player, so they know whether they can lay a mine again

TimArnettThales commented 8 months ago

Was fixed in #50