xahmol / ludo

Ludo game for 8 bit computers
GNU General Public License v3.0
5 stars 5 forks source link

TI-99/4a - Computer player couldn't finish #1

Open FenmanUK opened 3 years ago

FenmanUK commented 3 years ago

I played Red, computer played the other colours. Blue should have won but couldn't finish. It populated the 3 outer finishing positions but was unable to move any counter to the inner most position, no matter what the dice roll was.

In the end, Green finished 1st, I (Red) finished 2nd after continuing the game, Yellow finished 3rd but no matter what Blue rolled it was still unable to finish.

Hope that helps, thanks for making the game available. I'll have to dig out my Oric Atmos and see if I can get that version loaded.

xahmol commented 3 years ago

Hi, thanks for playing and reporting! Did encounter that issue before, but had trouble reproducing as most games do finish ok.

Did you by any chance have a savegame of this game after you were not able to finish?

Apparently, the valid move routine fails under a specific situation of three pawns in. Sorry for that.

Will dive into it.

xahmol commented 3 years ago

By the way: a save game would be a LUDOSAVx file on your file storage location, where x is a number from 0 to 4. 0 is the autosave, 1 to 4 your own saves. So even if you did not save, there might be an autosave if you did not start a new game after it. Would be very interested in that file if possible.

Thanks!

FenmanUK commented 3 years ago

Hi Xander,

Please find attached a copy of the LUDOSAV0 file, apologies for the slightly offensive player names!

After I took a copy, I tried loading it into the game but it said the autosave was empty. I tried copying the file to LUDOSAV1 and relaunched the game but save slot 1 also showed as empty so I don't know if the save file is corrupted or if there is an issue with the game loading.

Anyway, hope the file is useful.

Thanks,

Pete. LUDOSAV0.zip

xahmol commented 3 years ago

Thanks. Was able to read your save file, very valuable. Schermafbeelding 2021-08-13 083038

And you have discovered another bug, because indeed the Autosave slot says empty. Had to manually hex edit my config file to load this. Strange, as I am sure this worked before, but you are right: it does not anymore. Should be easily fixable though.

The problem of Blue not being able to finish is harder, but now at least finally have a good save game to see why it goes wrong. So thank and will start debugging.

Will keep you posted! (By the way: this big with blue not ebing able to finish is almost cetainly also present in the Oric version, as that part of the code is the same for all targets)

xahmol commented 3 years ago

Think I solved the bug. Found the error in the 'valid turn' logic and changed it. I can now finish your save game for Blue. See attached ZIP for the adapted binaries with your save game, if you now load the autosave game it should a) load and b) you now should be able to finish the game for blue.

Thanks for reporting and providing the save game! This proved to be a very difficult bug to reproduce without savegame. LudoTI994a-v199-20210822-1606.zip

Could you maybe test also on your side?

FenmanUK commented 3 years ago

Thanks Xander, I look forward to giving it another go.I'll be interested to look at the source code and see what the fix actually was. I had a quick look through the code the other week and followed it up to a point but wasn't sure what some of the valid move logic was doing.Thanks, Pete.

xahmol commented 3 years ago

Thx. It was this fix: https://github.com/xahmol/ludo/commit/0ddd371e156cae0d22bb9750bac2b95212e839dc#diff-6a42fde713bb0bd2d8d5735eeeca82a8db715ee78504b4ae6650ca5f88465ec8

Found out that the logic goes wrong if a pawn is in the destination field but is not yet moved to the last position in the destination field, while already other pawns are also in the destination field. The logic tests that you not pass a pawn in the destination field, but missed if the pawn is actually already past that pawn. This only happens therefore in very rare circumstances, therefore hard to catch without you save game.

Solved it by adding a seperate if statement for if the pawn to be checked already is in the destination field, it then checks if the pawn is already past the other pawn to check.

Especially as I actually wrote this logic in BASIC 29 years ago (1992), so also for me it was a puzzle what the code was actually doing ;-) Reason also for the two letter variable names, as that was all that was possible in C128 BASIC 7.0.