Ludii Forum
Restrict movement for promoted pieces - 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: Restrict movement for promoted pieces (/showthread.php?tid=552)



Restrict movement for promoted pieces - Enrique - 04-24-2021

I've just coded the rules for the movement for all the pieces of my game and everything works fine. I want to add a restriction but I don't know how to do it.

I want that pieces that had been promoted on the previous turn are forbidden to move on the current turn. (But only on the current turn not on turns after this.)

Any idea on how this could be done?


RE: Restrict movement for promoted pieces - cambolbro - 04-24-2021

Hi,

You could try setting the Pending value to equal the site on which a promotion is made, disallow moves at Pending sites, then turn it off again next move. Chess uses a similar mechanism for handling en passant:


Code:
(define "InLocationEnPassant"
    (and
        (is Pending)
        (= (to) (value Pending))
    )
)

Regards,
Cameron


RE: Restrict movement for promoted pieces - charlesrobin - 06-30-2023

Hi,
I would recommend using a custom trait to track whether a piece has been promoted on the previous turn. For example, you could create a trait called "Recently Promoted" with a boolean value that is set to true when a piece is promoted, and false otherwise.

Then, in your movement rules, you can add a conditional statement that checks whether the piece attempting to move has the "Recently Promoted" trait set to true. If it does, then the movement is forbidden. To ensure that this restriction only applies to the current turn, you can add a game state variable that is set to true at the end of each turn, and then reset to false at the beginning of the next turn.