Ludii Forum
Syntax and semantics for "size Group 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: Syntax and semantics for "size Group if" (/showthread.php?tid=240)



Syntax and semantics for "size Group if" - Castux - 11-08-2020

Hi!

I could find no examples in the included lud files of how to use the "if" argument to (size Group ...) In fact there is little information on how groups are determined, appart from the direction argument. It seems that groups are determined by pieces that are exactly the same, but the group *size* includes also any pieces stacked on top of these?

I'm trying to model a game where you place tiles on the board to form regions by adjacency, and then claim these regions by placing other tokens (say flags) *on top* of these tiles. I would like to prevent a player from placing a flag in a region that already contains one.

I've also defined the tiles to be Neutral, but I don't understand how that interacts with "Occupied by" when using a stack.

Being a programmer, I thought I could write my game definition in a breeze, but it looks like the grammar is designed to be very concise for common operations, and makes more programatic ones less obvious.

I would appreciate the help a lot, as Ludii seems to be an amazing tool (especially with the built-in analysis, UI and AI).
Thanks in advance!


RE: Syntax and semantics for "size Group if" - Michael - 11-08-2020

I’m wondering the same thing. I hope it’s ok that I add a specific question: In the if-parameter, how do I refer back to the piece whose condition for inclusion I am specifying? Do I use «(site)», as in the region functions? As in «if:(is Even (site))». Or does one use «(to)» and «(from)», which sometimes seems to be the case. And if it is the latter, won’t there be clashes between different things «(to)» and «(from)» might refer to, like when we use (size Group) inside a move that has a (to) parameter?


RE: Syntax and semantics for "size Group if" - Eric Piette - 11-09-2020

Hi,

Here an example of the use of the if condition with (size Group ...)

Code:
(game "TestSizeGroupIf"
    (players 2)
    (equipment
        {
        (board (hex 6))       
        (piece "Ball" Each)   
        (piece "Disc" Each) 
        (hand Each size:2)
        }
    )
    (rules
        (start {
            (place "Ball1" (handSite P1))
            (place "Ball2" (handSite P2))
            (place "Disc1" (handSite P1 1))
            (place "Disc2" (handSite P2 1))
        })
        (play 
            (move
                (from (sites Hand Mover))
                (to (sites Empty))
                copy:true
            )
        )
        (end
            (if
                (= 5
                    (size Group at:(last To)
                    if:(= (id "Disc" Mover) (what at:(to))))
                )
                (result Mover Win)
            )
        )
    )
)

We are releasing (I hope soon) a new pdf giving more details about the logic behind the ludeme.
In that new pdf, I already add a lot of examples too and that pdf will be updated according to the feedbacks of all the users of Ludii in order to add missing examples or explanations in order to make easier the use of Ludii in term of designing. 
So when we will release it, we expect a lot of feedbacks from our users to complete it.
The number of possible games/features to do with Ludii is huge, so we are really happy to have users telling us what is buggy in order to fix it or what is not enough explained in their opinion in order to improve.

So once again, thank you for your questions and comments :)


Concerning your questions:
- The (to) ludeme iterates the potential members of the group. 
- If you have stacked pieces, the condition 


Code:
if:(= (id "Disc" Mover) (what at:(to))))


will look the type of piece in the group because the default value of the "level:" in (what ...) is 0. 

If you want to look another level you can just modify that value for example for the top of the stack you can do 


Code:
if:(= (id "Disc" Mover) (what at:(to) level:(topLevel at:(to))))


I hope all of that helps you :)

Regards,
Eric


RE: Syntax and semantics for "size Group if" - Castux - 11-09-2020

Ah, perfect, thanks a lot for the example, I'll try to figure it out!