Ludii Forum
How can I count the number of pieces a player can move? - 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: How can I count the number of pieces a player can move? (/showthread.php?tid=805)



How can I count the number of pieces a player can move? - AlexanderBrady - 02-01-2022

I have tried (count Pieces Mover if:(can Move (move Step))), but I keep getting a grammar error.

I have also tried some tricks with (forEach Piece (do (if (can Move (move Step)) (set State 1))) (then (count Pieces Mover in:(sites State 1)))), but that also throws a grammar error.

Is there a way to do this?

Thank you for your help.


RE: How can I count the number of pieces a player can move? - Eric Piette - 02-01-2022

Hi,

One way to do this is:

Code:
(count Sites
     in:(forEach 
          (sites Occupied by:Mover)
          if:(can Move (step (from (site)) (to if:(is Empty (to)))))
         )
)

This is looking for all the sites occupied by one of the pieces of the mover if this piece can step to an empty site.
Of course, you will have to adapt this part "(step (from (site)) (to if:(is Empty (to))))" to the moves you want to check for all the pieces owned by the mover.

But your question reminds me of a discussion I had with the other members of the team before which leads to adding a ludeme able to count the number of legal moves for a player, so to make this easier I will probably add this ludeme soon as a (count LegalMoves ....) and maybe a condition to (count Pieces ...) to look specific conditions as you wish.

Eric


RE: How can I count the number of pieces a player can move? - AlexanderBrady - 02-01-2022

Fantastic, this is exactly what I wanted. Thank you so much!