Ludii Forum
Debug ludeme - Printable Version

+- Ludii Forum (https://ludii.games/forums)
+-- Forum: Suggestions (https://ludii.games/forums/forumdisplay.php?fid=10)
+--- Forum: Ludii Features / Services (https://ludii.games/forums/forumdisplay.php?fid=11)
+--- Thread: Debug ludeme (/showthread.php?tid=365)



Debug ludeme - slimy_asparagus - 01-14-2021

Please could we have a ludeme that helps debug Ludii programs. It should have no game effect at all, but if a debugging option was enabled it would store something in the trial. It could take as an argument a tag and an integer or boolean. Later versions might include other data structures, but integer/boolean would be game changing for us. It would also help the Ludii developers are lot because we would be less likely to come to you with "stupid" questions.

For example you could have

Code:
(debug "Size of Winning Zone" (count Sites (sites "WinningZone")))



RE: Debug ludeme - cambolbro - 01-14-2021

Hi,

Good idea. How do you see the mechanism working, a "Debug" tab in the tab panel that prints such messages when a "Debug" option is turned on in the Dev menu?

Or we could just print them out in the "Status" panel, in which case the following would be appropriate:

Code:
(print string (<int> | <ints> | <float> | <floats> | <boolean> |
               <sites> | <dim> | <range> | <direction> | <graph>))

so you could print out pretty much any useful information.

Another debug option might be a "Dump" mode that saves the current game state to a plain text file with each state update, but this would be difficult to interpret and probably not much use to anyone but us.

Regards,
Cameron


RE: Debug ludeme - slimy_asparagus - 01-14-2021

Cameron,

Thanks for the response.

Printing to the status tab would be great for information such as integers, booleans and directions etc. Bigger stuff would be overwhelming and  better in a file. Maybe the status would only have the first 50 characters or so.

I suggest the output should also go to the trial because:
1. You already have a trial format which is useful for debugging in itself.
2. Debugging stuff output there would be in context. 
3. You can apply textual analysis tools such as  diff and search to a trial file.


The dump stat idea would also be useful to us mortals, but would be something of a last resort. I suggest that you have a mode where you can replay a trial file and Ludii would output a dump file. You could then cross-reference the trial file and the dump stat file. So then you would not turn it on all the time, but only when you saw something you did not understand. 

I suggest "(debug ...)" rather than "(print ...)" because in the latter case people might try to use it in a non-debugging way as an alternative to "note", especially since note only takes strings.


RE: Debug ludeme - cambolbro - 01-14-2021

Hi again,

We actually already have this mechanism in place! I forgot about the (note ...) ludeme which prints messages to the Status panel. Eric has just expanded it to handle a wider range of input parameters, which should make it useful for debugging purposes:

Code:
<note> ::= (note [player:<int> | player:<roleType>]
                 (string | <int> | <ints> | <float> | <boolean> |
                 <sites> | <range> | <direction> | <graph>)
                 [to:<moves.player> | to:<roleType>])

Just put a note in your .lud code where you want something evaluated and printed to the Status panel. This will appear in the next Ludii release.

Eric also suggested adding a debug window in which the user can enter ludeme code then evaluate it for the current board state. We're looking into adding that as well.

Regards,
Cameron


RE: Debug ludeme - slimy_asparagus - 01-14-2021

Eric, Cameron,

Thanks. This will be an enormous help.


RE: Debug ludeme - xenos1984 - 01-14-2021

Another suggestion which just came to my mind: Would it be possible to add a "debug level" integer parameter to (note ...), with some default value, and a corresponding option to the Ludii preferences? The idea would be that one could give a certain level of urgency to messages, and print them to the status window only if their urgency is above a user-defined threshold.


RE: Debug ludeme - cambolbro - 01-15-2021

Hi,

We've added a Test Ludeme dialog in which you can enter ludeme code, press a button, and it will print the result for the current state. This should be useful for debugging.

As to including a debug level option in (note ...), I'm hesitant to do that as that would be making (note ...) too much of a debugging command; we're already abusing it by repurposing this game rule for debugging purposes :)

But we can always add a dedicated debug command something like (debug <boolean> <message> [<level>]) if needed. Please keep this in mind and let us know if it would be useful where the (note ...) mechanism is not.

Regards,
Cameron


RE: Debug ludeme - xenos1984 - 01-15-2021

(01-15-2021, 08:39 AM)cambolbro Wrote: But we can always add a dedicated debug command something like (debug <boolean> <message> [<level>]) if needed. Please keep this in mind and let us know if it would be useful where the (note ...) mechanism is not.
Thanks, Cameron, that sounds reasonable. Indeed, having a dedicated debug output command would make it possible, e.g., to print "note" and "debug" messages on different channels or in different styles, if they have a different audience (players vs. developers).


RE: Debug ludeme - slimy_asparagus - 01-20-2021

Eric, Cameron,

Thank you for implementing this. I am finding some issues however.

I have attached a modified version of chess, were the following debugging code is added to a single pawn move.

Code:
(do
                (note (id "King" P1) to:P2)
                next:(note (sites Occupied by:P1 component:5) to:P2)
            )
I get the following output:

5.

{0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 14, 15, 21}.

If I change the second 5 to "King"  I get {4}. To me this shows that using an id in (sites Occupied) rather than a string does not work.

Now if I try using the dialog I get different answers. 

(id "King" P1) gives -1.

(sites Occupied by:P1 component:"King") gives [40,41,43,44]
(sites Occupied by:P1 component:5) gives [40,41,43,44]


RE: Debug ludeme - Eric Piette - 01-21-2021

Hi,

Thanks for pointing that.
The bug was (also ^^) in (sites Occupied by:...) and is now fixed.

However for (id "King" P1). I get the right value and not -1.

Regards,
Eric