adamleesaintfrancis / spacewar

Automatically exported from code.google.com/p/spacewar
0 stars 0 forks source link

Ship with active shield can endlessly bounce between two astroids #17

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
1. Place a ship that does nothing but activate it's shield in the middle
of space.
2. Place two asteroids of the same size on a collision course with the ship
so that they should hit the ship at the same time.

3.  When they hit, the game will appear to hang. 

What version of the product are you using? On what operating system?
Java 6, Ubuntu 8.04 amd64 beta.

Please provide any additional information below.

What is happening: The ship is bouncing back and forth between the
asteroids thousands of times per timestep.  Because an asteroid doesn't
lose any velocity when colliding with a ship, the two asteroids have no way
to transfer their velocity to each other.  Thus the ship will bounce back
and forth until it's shields give out and it dies.  

The problem: It can take arbitrarily long for the ship to run out of
shields.  In my tests, the ship would collide with the asteroids 850000
times per timestep. The ship's shields last for 15 timesteps.  The ship can
have as much as 5000 energy.  At 250 energy per shield activation, it can
take as long as 300 timesteps or 255 million collisions for the ship to
die.  In a game with breakable asteroids, this could conceivably happen
multiple times per game.  It could theoretically loop infinitely in the
unlikely case where the asteroids were both so close to the ship that the
collisions take zero time.

The fix: Attached is a patch that fixes the problem.  This is accomplished
by giving the shield a maximum amount of damage it can prevent from
collisions.  This damage limit can be arbitrarily high, since bouncing
between the asteroids would essentially deal an infinite amount of damage
to the ship.  In the patch, I set the damage limit to 5000.  In my test,
this reduced the number of collisions to 4.

If the collision happens at very low speeds, there might still be several
thousand collisions before the ship is destroyed.  However, this is true
even if the ship's shields are not active.

Also, please cc: jfager on any new issues that are opened!  Thank you!

Original issue reported on code.google.com by ztidw...@gmail.com on 6 Apr 2008 at 5:22

Attachments:

GoogleCodeExporter commented 9 years ago
Good catch, thanks for the patch.

Original comment by jfa...@gmail.com on 7 Apr 2008 at 3:40