Ludii Forum
Nesting (forEach Site …) - 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: Nesting (forEach Site …) (/showthread.php?tid=188)



Nesting (forEach Site …) - Michael - 09-23-2020

I can't think of a simple way of finding this out by experiment, so I hope its ok that I just ask instead:
Is it possible to use (forEach Site …) inside (forEach Site …)? And if so, does (site) always have the value it has in the outermost context?


RE: Nesting (forEach Site …) - Eric Piette - 09-23-2020

Hi,

Yes you can use nesting (foreach Site).

And if you do that, the (site) value of the outer one can be used to define the region in the deeper (foreach Site) but in the Moves in the deeper (foreach Site), the (site) value will be defined by each site in the deeper (foreach Site).

Regards,
Eric


RE: Nesting (forEach Site …) - Michael - 09-23-2020

Great! Just to see if I understand, here is what I was thinking:
Code:
(forEach Site
    (sites Occupied by:P1 component:"DoubleCounter")
    (if
        (= 0 (state at:(site)))
        (and
            (forEach Site
                (sites Group at:(site))
                (set State at:(site) 1)
            )
            …
        )
    )
)
The second to last (site) has the outer value, and the last has the inner?


RE: Nesting (forEach Site …) - Eric Piette - 09-23-2020

Yes exactly.

Eric


RE: Nesting (forEach Site …) - Michael - 11-26-2020

Thinking about Alek's swapping-question I have come over a situation where one cannot nest (forEach) because there is no way of specifying which level’s value (site) is supposed to refer to. Here is the relevant define in the attached example:

Code:
(define "SwapAdjacentEnemy"
    (forEach Site
        (sites Occupied by:Mover)
        (forEach Site
            (sites Around (site) Enemy Orthogonal)
            (move Swap Pieces
                (site)
                (site)
            )
        )
    )
)
Shouldn’t there be a way of referring to different levels inside a context like this one?


RE: Nesting (forEach Site …) - Eric Piette - 11-26-2020

Hi,

No (site) is always set by the last ludeme using it.

However I provided a full example to the Swap question (working only in the next release).

Regards,
Eric