Ludii Forum
The behavior of the nondecision operator (forEach) - 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: The behavior of the nondecision operator (forEach) (/showthread.php?tid=193)

Pages: 1 2


RE: The behavior of the nondecision operator (forEach) - Eric Piette - 10-12-2020

Hi Michael,

I added a (forEach Group ...) ludeme to our dev version, it will be included in the next release.
To iterate each group, you will have to refer to it with the ludeme (sites).

Here an example, adding at each turn a score of one to the mover for each group (connected only orthogonally) greater than 2:

Code:
(move Add (to (sites Empty))
    (then
        (forEach Group Orthogonal
            (if (< 1 (count Sites in:(sites)))
                (addScore Mover 1)
            )  
        )
   )
)


Regards,
Eric Piette


RE: The behavior of the nondecision operator (forEach) - Michael - 10-12-2020

Fantastic! Thank you so much, Eric!


RE: The behavior of the nondecision operator (forEach) - Michael - 10-26-2020

I have been trying to make my game work with the new group iteration, but I'm stuck. The fact that it only iterates over the groups owned by the mover seems to make it useless for my purposes.

What I have been trying to do is to give each player a score equal to the sum of the values of each of their groups, where the value of a group is some function of the number of 2-stacks it contains.

In order to do this I have to iterate over groups and, for each group  add the value of that group to the relevant player's score. In order not to add the same values over and over each turn, I make sure I only calculate the score after the (pass) that ends the game. But I realized that only the groups of the player that made the last (pass) gets counted, so I am not able to calculate the score of each player.

I have attached a .lud with the game, but this code would only have worked if the new ludeme iterated over all groups. Another way it could work is if I could choose whose groups to iterate over. Maybe one can with "if:", but I don't understand how it works..

Is there a way of doing what I want with the new ludeme as is?


RE: The behavior of the nondecision operator (forEach) - Michael - 10-26-2020

In a stroke of inspiration I simply set the if-parameter to "true". It seemed to have worked :)
Edit: I spoke too soon.. It does not behave the way I thought it did.