Ludii Forum
Need advice on debugging - Printable Version

+- Ludii Forum (https://ludii.games/forums)
+-- Forum: Questions (https://ludii.games/forums/forumdisplay.php?fid=13)
+--- Forum: About Ludii (https://ludii.games/forums/forumdisplay.php?fid=14)
+--- Thread: Need advice on debugging (/showthread.php?tid=315)



Need advice on debugging - Michael - 12-05-2020

I thought I was finished with a version of the game I'm working on, but when watching Ludii play itself I noticed moves I could not explain. I cannot find anything in my script that can cause this behavior.

In one of the attached trials you can see that after move 26, suddenly an illegal move can be made. Move 27 is illegal because it moves an entire stack without increasing the distance (measured in steps) from (centrePoint). In the other trial you can se that it is impossible to make the corresponding move.

My problem is that I cannot see that anything relevant is different between the two cases. I'm really stumped. How do I proceed when I am this lost and confused?

The illegal move is an instance of ("MoveStackPart"). But this ludeme should not let you move all the pieces in a stack.

If any one could help me I would be eternally grateful.


RE: Need advice on debugging - Eric Piette - 12-07-2020

Hi,

When you reach such a problem and you are not sure of the source, according to me the process is to comment many parts of the description while the wrong move/illegal move/bug is still there in order to identify the cause.

In looking your game and example, I found something weird in the description which is probably the cause.

The movement of the full stack you show as illegal comes from that:

Code:
(forEach Piece
  ("MoveStackPart")
  Mover
  top:true
)


That means for each piece of the mover at the top of a stack the corresponding moves of "MoveStackPart" are legals in setting the (from) variable for each site where these stacks are.
Until now, no problem.

BUT

The define "MoveStackPart" is a (forEach Value .... (move (from ...) (to ...)) ....)
AND the data in the (from ...) are ALL the sites occupied by the mover with a stack of at least size 2.

Consequently, that means 
For each piece at the top of the stack owned by the mover, you look ALL the sites owned by the mover with a stack of size bigger than 2 and makes legal moves from them.

Consequently the illegal move you found comes from that, because in your trial you have some stacks of size 3 with the top piece owned by the mover and these stacks make possible to move any stack of size 2 owned by the mover (so the full stack can be moved here).

To remove that illegal move just modify the content of (from ...) in this define by just (from) and the illegal move will disappear.
I am not sure that your game will be exactly like you want, but at least now you know the cause and how to fix that.

Regards,
Eric


RE: Need advice on debugging - Michael - 12-07-2020

That's immensely helpful! I think I have fixed it now. I used that region function because I didn't know (from) had an if-parameter. I just replaced the region function with if:(< 1 (size Stack at:(from))). Seems to work :)
Thank you!