Ludii Forum
Can't get the "else" move work in "if" - Printable Version

+- Ludii Forum (https://ludii.games/forums)
+-- Forum: Questions (https://ludii.games/forums/forumdisplay.php?fid=13)
+--- Forum: About the Ludii Grammar (https://ludii.games/forums/forumdisplay.php?fid=15)
+--- Thread: Can't get the "else" move work in "if" (/showthread.php?tid=244)



Can't get the "else" move work in "if" - Castux - 11-09-2020

Hello again. Another thing I'm stuck on. In a game where each player has two moves in a row, and I need to do some maintenance at the end of the turn:

Code:
        (play
            (move
                (from (sites Hand Mover))
                (to (sites Empty))
                (then
                    (if (not "SameTurn")
                        (moveAgain)
                        "Refill"
                    )
                )
            )
        )

The player can correctly play twice in a row, but the "Refill" is not applied afterwards. Note that "Refill" works when using is simply as "then" or as the first clause of the "if".

In case it matters, here is the definition of "Refill":

Code:
(define "Refill"
    (remove (sites hand Mover)
        (then
            (add (piece (id "HexA" Mover)) (to (handSite Mover 0))
                (then
                    (add (piece (id "HexB" Mover)) (to (handSite Mover 1)))
                )
            )
        )
    )
)

The player can play one piece of each of their colors during their turn, but not two of the same, so I'm using a hand with one piece of each, that refills at the end of the turn.

Thanks!


RE: Can't get the "else" move work in "if" - Eric Piette - 11-09-2020

Hi,

That's easier for me to help you if you give me a complete .lud to run. Can you?

Regards,
Eric


RE: Can't get the "else" move work in "if" - Castux - 11-09-2020

Sure! I tried also with "HandEmpty", but that doesn't do anything either :/

Code:
(define "Refill"
    (remove (sites hand Mover)
        (then
            (add (piece (id "HexA" Mover)) (to (handSite Mover 0))
                (then
                    (add (piece (id "HexB" Mover)) (to (handSite Mover 1)))
                )
            )
        )
    )
)

(game "Blooms"
    (players 2)
    (equipment {
        (board (hex 5))
        (piece "HexA" Each)
        (piece "HexB" Each)
        (hand Each size:2)
    })
    (rules

        (start {
            (place "HexA1" (handSite P1 0))
            (place "HexB1" (handSite P1 1))
            (place "HexA2" (handSite P2 0))
            (place "HexB2" (handSite P2 1))
        })
        (play
            (move
                (from (sites Hand Mover))
                (to (sites Empty))
                (then
                    (if ("HandEmpty" Mover)
                        "Refill"
                        (moveAgain)
                    )
                )
            )
        )
        (end
            (if
                (>= (score Mover) 15)
                (result Mover Win)
            )
        )
    )
)

(metadata
    (graphics {
        (player Colour P1 (colour Blue))
        (player Colour P2 (colour Red))
        (piece Colour P1 "HexB" fillColour:(colour LightBlue) )
        (piece Colour P2 "HexB" fillColour:(colour LightRed) )
    })
)

Note that I empty the hand before refilling it, because later I'll add the option to pass after placing a single stone. I'm just not there yet.


RE: Can't get the "else" move work in "if" - Eric Piette - 11-09-2020

Here the correction to your file to do what you expect.

Code:
(define "Refill"
(and {
    (remove (sites hand Mover))
    (add (piece (id "HexA" Mover)) (to (handSite Mover 0)))
    (add (piece (id "HexB" Mover)) (to (handSite Mover 1)))
})
)

//------------------------------------------------------------------------------

(game "Blooms"
    (players 2)
    (equipment {
        (board (hex 5))
        (piece "HexA" Each)
        (piece "HexB" Each)
        (hand Each size:2)
    })
    (rules

        (start {
            (place "HexA1" (handSite P1 0))
            (place "HexB1" (handSite P1 1))
            (place "HexA2" (handSite P2 0))
            (place "HexB2" (handSite P2 1))
        })
        (play
            (move
                (from (sites Hand Mover))
                (to (sites Empty))
                (then
                    (if ("HandEmpty" Mover)
                        "Refill"
                        (moveAgain)
                    )
                )
            )
        )
        (end
            (if
                (>= (score Mover) 15)
                (result Mover Win)
            )
        )
    )
)

//------------------------------------------------------------------------------

(metadata
    (graphics {
        (player Colour P1 (colour Blue))
        (player Colour P2 (colour Red))
        (piece Colour P1 "HexB" fillColour:(colour LightBlue) )
        (piece Colour P2 "HexB" fillColour:(colour LightRed) )
    })
)



RE: Can't get the "else" move work in "if" - Castux - 11-09-2020

Amazing, thanks a lot! I didn't realize that "and" could be used to chain non-decision moves. Although, what was technically wrong in the chaining with "then"?


RE: Can't get the "else" move work in "if" - Eric Piette - 11-09-2020

Hi,

If a site is already empty, the remove Action is not applied (no need).
Consequently the consequence of that move is also not applied if the hand is already empty here. So, no move is computed by that ludeme in that really specific case.

Regards,
Eric


RE: Can't get the "else" move work in "if" - Castux - 11-09-2020

That makes a lot of sense. Thanks again!