Ludii Forum
The "else-clause" in (if) - Printable Version

+- Ludii Forum (https://ludii.games/forums)
+-- Forum: Problems (https://ludii.games/forums/forumdisplay.php?fid=5)
+--- Forum: Game Problems (https://ludii.games/forums/forumdisplay.php?fid=17)
+--- Thread: The "else-clause" in (if) (/showthread.php?tid=831)



The "else-clause" in (if) - Michael - 02-16-2022

I have run into a situation where it seems to me that the ludeme in the else-clause of my if-statement is called, even though the condition of the statement is true.

Here is the relevant part of the script:
Code:
("Remove" Enemy
    (then
        (if
            (no Pieces Enemy in:(sites Board)) //CONDITION
            (set Var "Winner" (mover))         //DO THIS
            ("Remove" Mover                    //ELSE THIS
                (then
                    (if
                        (no Pieces Mover in:(sites Board))
                        (set Var "Winner" (+ 1 (% (mover) 2)))
                    )
                )
            )
        )
    )
)

It seems to me that the the action described in the ludeme I have marked with "ELSE THIS" – namely ("Remove" Mover …) – should not be performed if, after ("Remove" Enemy) is performed, (no Pieces Enemy in:(sites Board)) evaluates to True. As far as I can see, this should have the following effect on the behavior of the game: If ("Remove" Enemy) removes all enemy pieces from the board, then friendly pieces should not be removed. 

To spell it out:
If after the action described by ("Remove" Enemy) is performed, (no Pieces Enemy in:(sites Board)) evaluates to True, the action described by the following part of the ludeme should not be performed:
Code:
            ("Remove" Mover
                (then
                    (if
                        (no Pieces Mover in:(sites Board))
                        (set Var "Winner" (+ 1 (% (mover) 2)))
                    )
                )
            )

Yet, in the trial I have attached, after White captures the last remaining black stones, White's own stones are also removed. Thus, the game ends with no pieces on the board. The winner is determined correctly, but the board is never supposed to end up empty at the end of the game.

My script has many other issues besides this, btw. In general, I am unable to perform two conditional actions in order. When I use (do next:), the first action isn't performed if the second action isn't performed. I often get in trouble when a rule has this structure:

First, if condition C1 holds, do A. Secondly (whether or not A was done), if condition C2 now holds, do B.

In this case the structure of the rule is more like:

First, go through all enemy groups and remove those that meet "the condition". Secondly (whether or not any enemy group was removed), go though all friendly groups and remove those that meet "the condition".


RE: The "else-clause" in (if) - Michael - 03-03-2022

I no longer need to fix this particular problem. But I will probably (at some time or another) make a thread about the general problem of performing two conditional nondecision actions in order.


RE: The "else-clause" in (if) - ricecrisis - 12-27-2023

Although the issue remains, based on the movement you demonstrate, it appears that there may be a script flaw or that he is use an other version that skips "Stop Here" and instead chooses the same spot again.


RE: The "else-clause" in (if) - dale walton - 12-27-2023

The particular issue might be due to (remove) acting at different times depending on the parameter 'at:' and being somewwhat special in its implementation. This is where detailed specs could help make sure everyone knows what is supposed to happen, and things don't randomly change in the future.

The general problem probably has to do with the non-procedural nature of the language, and I also grapple with it, trying many alternatives until I find the right one, because it is hard to keep in mind the methods that do work and those that do not, and how to work around them. Usually this forces a clearer more concise script in the end, but sometimes I can only find work-arounds. I would be happy to review scripts with you where you find issues...