Ludii Forum
Stack logic and moving empty stacks - 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: Stack logic and moving empty stacks (/showthread.php?tid=248)



Stack logic and moving empty stacks - Castux - 11-10-2020

Hi! Trying to figure out how to use stacks properly.

In the attached LUD, you'll see I have stacks of neutral pieces in a shared hand, and personal stacks of pieces in personal hands.

At first it seems to work fine (moving neutral pieces to empty board spaces, and moving personal flags onto pieces on the board). But once the hand stacks are empty, the following oddity happens: empty stacks in the hand are still considered valid "from" locations, as evidenced by the "show legal move" option. However, moving them onto the board seems to replace what is there with an "empty stack" of sorts. That happens for both the shared and personal hands.

These destination spaces are not considered empty anymore, but they don't visibly contain anything either. Is the empty stack itself considered an object that can be moved? I even tried to filter the "from" location by stack size (forcing it to be non zero) but that had no effect.

Thanks in advance!

Edit: just to be clear, my expectation is that one cannot "move" anything from an empty stack, the game being over when all pieces have been placed.


RE: Stack logic and moving empty stacks - Eric Piette - 11-10-2020

Hi,

Yes you have to check if the from location is not empty.

Here one way to do it:

Code:
(game "Europa"
    (players 2)
    (equipment {
        (board (hex 3))
        (piece "Flag" Each)
        (piece "HexA" Neutral)
        (piece "HexB" Neutral)
        (piece "HexC" Neutral)
        (hand Shared size:3)
        (hand Each size:1)
    })
   
    (rules
   
        (start {
            (place Stack "HexA0" (handSite Shared 0) count:6)
            (place Stack "HexB0" (handSite Shared 1) count:6)
            (place Stack "HexC0" (handSite Shared 2) count:6)
            (place Stack "Flag1" (handSite P1 0) count:3)
            (place Stack "Flag2" (handSite P2 0) count:3)
        })
       
        (play
            (or
                (forEach Site
                    (sites Hand Shared)
                    (if (!= 0 (count at:(site)))
                        (move
                            (from (site))
                            (to (sites Empty))
                        )
                    )
                )
                (forEach Site
                    (sites Hand Mover)
                    (if (!= 0 (count at:(site)))
                        (move
                            (from (site))
                            (to
                                (sites Board)
                                if:(= (size Stack at:(to)) 1)
                            )
                        )
                    )
                )
            )
        )
       
        (end (if (no Moves Next) (result Mover Win)))
    )
)


Regards,
Eric


RE: Stack logic and moving empty stacks - Castux - 11-10-2020

Great, thanks a bunch. Out of curiosity, why doesn't the usual "if" in "from" do the job?

Code:
(move
    (from (sites Hand Shared)
        if: (!= 0 (count at:(from)))
    )
    (to (sites Empty))
)



RE: Stack logic and moving empty stacks - Eric Piette - 11-10-2020

Hi,

In writing the previous .lud to give an example, I was thinking the same ^^ In reality that "if:" for the from in that ludeme is just not implemented in the corresponding code, so I added that to my todo ;)

So that will work in a future release.

Regards,
Eric


RE: Stack logic and moving empty stacks - Castux - 11-10-2020

:D Oh well...


RE: Stack logic and moving empty stacks - Eric Piette - 11-10-2020

Hi,

Yes, that's also thanks to the users that we found improvement in Ludii and the language. But in general, you can always do it with another way like I sent to you ;)

Regards,
Eric