08-26-2023, 07:27 AM
(This post was last modified: 08-26-2023, 07:36 AM by dale walton.)
(08-09-2023, 03:03 AM)Alain Busser Wrote: Thank you a lot!
But I still don't have it. There's an error with
Code:(score P1
(+ (count Steps (site) (sites Top) (forEach Site (sites Occupied by:P1) ))
)
)
Even if I switch the "forEach..." and the "count", or if I include the whole ludeme inside brackets.
In the language reference I don't find examples for the use of forEach to retrieve something else than moves or regions.
The results method appears to be the simplest. But I can help with some of your other questions:
Your code above fails because "(+" is not an iterative operator for regions or integers.
It CAN be used to sum arrays such as in the (result) example because (results ...) is an array.
A more cumbersome solution is to store the values into an array using (remember ...)
Or else you can use addScore.
Code:
(forEach Site
(sites Occupied by:P1)
(addScore P1 (count Step (site) (sites Top)))
)
--------------------------
(forEach Site
(sites Occupied by:P1)
(remember Value "P1" (count Step (site) (sites Top))
(then
(score P1 (+ (values Remembered "P1")))
) )
The biggest problem with all these is that they can't be used in the (score ) statements in the (byScore ...) ludeme in the (end ...) section) because they are processes (moves) rather than integers. So if you used them you would need to ad code in the Play section to do them just in the last turn.
The (+ (results ...)) can be used in (score ...) because it is an integer, not the result of moves.
Here is how that might look:...
Code:
(end
(if
(<endcondition>) //i.e. from your code
(byScore
{
("ScoreOf" P1 (sites Top))
("ScoreOf" P2 (sites Bottom))
}
misere:True
) ) )
(define "ScoreOf"
(score #1
(+ (results from:(sites Occupied by:#1) to:(from) (count Steps (from) #2)))
) )
--------------------------------------
Another question is do you allow passing (but giving up a ring)
If so you could do it this way, as an example:
Code:
(piece "DiscFlat" Each
(if
(> (count Stack at:(from)) 1)
(or
(move Select
(from)
)
(move Step
(to if:(is Empty (to)))
stack:True
)
(then (remove (last To) ))
) ) )