I can't figure out what is wrong with my workaround. Here is what I'm trying:
Where "n1" is defined like this:
The intended effect is to score P1 the sum of the values of all of their groups, where the value of a group is a function of the number of DoubleCounters it contains. The function is (#ofDoubleCounters * (#ofDoubleCounters + 1)) / 2.
The way I'm thinking that my "CalculateScoreP1" works is this:
It goes through all sites occupied by P1s DoubleCounters and looks if its state is 1. If it is not, it does the following:
First it changes the state of all sites in the group of the site currently under consideration to 1. This should make it the case that the other DoubleCounters in this group does not pass the "is its state 1?"-test when the (forEach)-iteration eventually gets to these sites.
Then it adds to P1s score a number that is a function of the number of DoubleCounters in the group that the one under consideration belongs to. The function is the one I described above.
Because of the change of state this calculation should only be preformed once per group.
It does not work the way I'm envisioning, though. Every DoubleCounter is counted as if it is a singleton, as if a group can't consist of both Counters and DoubleCounters. But this is not what happens with (count Groups). Then the different pieces of the same color is treated as belonging together in groups. I have attached the relevant game. I would be super grateful for any help with this.
Edit: The attached file contains an unrelated error: When calculating the score of P2 it uses the P1's number ("n1" in stead of "n2").
Code:
(define "CalculateScoreP1"
(forEach Site
(sites Occupied by:P1 component:"DoubleCounter")
(if
(!= 1 (state at:(site)))
(and
(forEach Site
(sites Group at:(site))
(set State at:(site) 1)
)
(addScore P1
(/ (* "n1" (+ 1 "n1") ) 2)
)
)
)
)
)
Code:
(define "n1"
(count Sites in:(intersection (sites Occupied by:P1 component:"DoubleCounter") (sites Group at:(site)) ) )
)
The intended effect is to score P1 the sum of the values of all of their groups, where the value of a group is a function of the number of DoubleCounters it contains. The function is (#ofDoubleCounters * (#ofDoubleCounters + 1)) / 2.
The way I'm thinking that my "CalculateScoreP1" works is this:
It goes through all sites occupied by P1s DoubleCounters and looks if its state is 1. If it is not, it does the following:
First it changes the state of all sites in the group of the site currently under consideration to 1. This should make it the case that the other DoubleCounters in this group does not pass the "is its state 1?"-test when the (forEach)-iteration eventually gets to these sites.
Then it adds to P1s score a number that is a function of the number of DoubleCounters in the group that the one under consideration belongs to. The function is the one I described above.
Because of the change of state this calculation should only be preformed once per group.
It does not work the way I'm envisioning, though. Every DoubleCounter is counted as if it is a singleton, as if a group can't consist of both Counters and DoubleCounters. But this is not what happens with (count Groups). Then the different pieces of the same color is treated as belonging together in groups. I have attached the relevant game. I would be super grateful for any help with this.
Edit: The attached file contains an unrelated error: When calculating the score of P2 it uses the P1's number ("n1" in stead of "n2").