I have tried to use (forEach Site) to work around the lack of a ludeme that iterates over groups, but it seems my workaround relies on a misunderstanding of how it works.
The point is to implement a kind of triangular scoring where a group consists of 1-stacks and 2-stacks and its value is based on how many 2-stacks it contains (1p for the first, 2p for the second, and so on).
This is my code:
And this is the meaning of "n1":
This is how I thought it worked:
(Choose a white 2-stack whose state is not 1 and do the following: Change the state of its entire group to 1 and add the value of its group to the score of P1.) <== Repeat this until there are no white 2-stacks whose state is not 1.
If it had done this it would have resulted in the score of P1 being equal to the sum of the values of all its groups. What happens instead is that the value of one of the groups is added to the score of P1 once for each white two-stack on the board. Could someone explain to me why this happens?
In short:
It seems to me that the code should
(1) add the value of each group to the score once,
but instead it
(2) adds the value of one group to the score once for each group.
What am I misunderstanding?
I have attached a file that shows it in action. When you add adjacent to no friendly stone you place a 2-stack, otherwise a 1-stack. In this "debug-version" when you pass the score of P1 is calculated.
Edit: A hypothesis that could explain this is that (forEach Site <region> (and <moves1> <moves2>)) is equivalent to (and (forEach Site <region> <moves1>) (forEach Site <region> <moves2>). This seems even to be true in the case where I use (do <moves1> next:<moves2>) in stead of (and <moves1> <moves2>).
The point is to implement a kind of triangular scoring where a group consists of 1-stacks and 2-stacks and its value is based on how many 2-stacks it contains (1p for the first, 2p for the second, and so on).
This is my code:
Code:
(forEach Site
(forEach
(sites Occupied by:P1)
if:(= 2 (size Stack at:(site)))
)
(if
(!= 1 (state at:(site)))
(and
(forEach Site
(sites Group at:(site) )
(set State at:(site) 1)
)
(addScore P1
(/ (* "n1" (+ 1 "n1") ) 2)
)
)
)
)
Code:
(count Sites
in:(intersection
(forEach
(sites Occupied by:P1)
if:(= 2 (size Stack at:(site)))
)
(sites Group at:(site))
)
)
This is how I thought it worked:
(Choose a white 2-stack whose state is not 1 and do the following: Change the state of its entire group to 1 and add the value of its group to the score of P1.) <== Repeat this until there are no white 2-stacks whose state is not 1.
If it had done this it would have resulted in the score of P1 being equal to the sum of the values of all its groups. What happens instead is that the value of one of the groups is added to the score of P1 once for each white two-stack on the board. Could someone explain to me why this happens?
In short:
It seems to me that the code should
(1) add the value of each group to the score once,
but instead it
(2) adds the value of one group to the score once for each group.
What am I misunderstanding?
I have attached a file that shows it in action. When you add adjacent to no friendly stone you place a 2-stack, otherwise a 1-stack. In this "debug-version" when you pass the score of P1 is calculated.
Edit: A hypothesis that could explain this is that (forEach Site <region> (and <moves1> <moves2>)) is equivalent to (and (forEach Site <region> <moves1>) (forEach Site <region> <moves2>). This seems even to be true in the case where I use (do <moves1> next:<moves2>) in stead of (and <moves1> <moves2>).