Javanaise / mrboom-libretro

Mr.Boom is an 8 player Bomberman clone for RetroArch/Libretro
http://mrboom.mumblecore.org
MIT License
206 stars 61 forks source link

AI bots freezing on Gamecube #78

Closed SimpleTease closed 4 years ago

SimpleTease commented 4 years ago

This pattern is 100% repeatable.

- - - -
- C - -
- A B -
- - - -

Bot starts at A. Walks to B but stops 1 pixel short of destination. AdderX, AdderY = (0,0).

https://github.com/Javanaise/mrboom-libretro/blob/5d7cd0d7adc03bb2a6e615eeccb39703eaa01385/ai/MrboomHelper.hpp#L118-L121

This is where it gets weird.

return(GETXPIXELSTOCENTEROFCELL(player) * framesToCrossACell(player) / CELLPIXELSSIZE);
==> error. Freezes.

int total = GETXPIXELSTOCENTEROFCELL(player) * framesToCrossACell(player);
return(total / CELLPIXELSSIZE);
==> fail. Same problem.

return(GETXPIXELSTOCENTEROFCELL(player) * (framesToCrossACell(player) / CELLPIXELSSIZE));
==> okay. Drops bomb at B and walks to C.
==> Which likely will break later when player has speed disease and rollers.

GETXPIXELSTOCENTEROFCELL(player) = -1
framesToCrossACell(player) = 16
CELLPIXELSSIZE = 16

gcc version 7.5.0. So it likely affects Wii, Wii U also since they share same toolchain.

I have no idea why this happens and was wondering about any alternate fixes.

SimpleTease commented 4 years ago

Compiler was doing some bad optimization trick with negative numbers. Suggestion is to use abs and re-apply sign afterward.