![]() |
How to return different regions depending on the player number? - 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 to return different regions depending on the player number? (/showthread.php?tid=1537) |
How to return different regions depending on the player number? - RubixOne - 04-11-2023 I need help figuring out how to return different regions depending on the. input. Here is the base function I am trying to modify (the Two Pawns function for Yonin Shogi, which needs fixed): (define "OnePawnPerColumn" (= (count Sites in:(sites Occupied by:#1 container:"Board" component:"Fuhyo")) (count Sites in:(difference (sites Occupied by:#1 container:"Board" component:"Fuhyo") (sites Column (column of:(to))))) ) ) I want "(sites Column (column of:(to)))" to be "(sites Row (row of:(to)))" when #1 is even. RE: How to return different regions depending on the player number? - dale walton - 04-12-2023 The documentation shows if is valid for booleans. I have had problems with it sometimes, but in theory: (define "OnePawnPerColumn" (if (= 0 (% #1 2)) // #1 is even (= (count Sites in:(sites Occupied by:#1 container:"Board" component:"Fuhyo")) (count Sites in:(difference (sites Occupied by:#1 container:"Board" component:"Fuhyo") (sites Row (row of:(to))))) ) (= (count Sites in:(sites Occupied by:#1 container:"Board" component:"Fuhyo")) (count Sites in:(difference (sites Occupied by:#1 container:"Board" component:"Fuhyo") (sites Column (column of:(to))))) ) ) ) If not, you could use: (define "OnePawnPerColumn" (or (and (= 0 (% #1 2)) // #1 is even (= (count Sites in:(sites Occupied by:#1 container:"Board" component:"Fuhyo")) (count Sites in:(difference (sites Occupied by:#1 container:"Board" component:"Fuhyo") (sites Row (row of:(to))))) ) ) (and (= 1 (% #1 2)) // #1 is odd (= (count Sites in:(sites Occupied by:#1 container:"Board" component:"Fuhyo")) (count Sites in:(difference (sites Occupied by:#1 container:"Board" component:"Fuhyo") (sites Column (column of:(to))))) ) ) ) ) RE: How to return different regions depending on the player number? - RubixOne - 04-12-2023 These work in theory, but if I try to compile Yonin Shogi.lud with either of these functions implemented, Ludii spits out this error message: Unexpected syntax 'Mover' in '(% Mover 2)'. Edit: I see what is going on. It needs Mover for the rule enforcement portion and (mover) for the modulus operation. Thanks for the help. Edit: It works now, but now I noticed another bug, and as luck would have it, it involves the Drop Pawn Mate rule, specifically for the players who are not next in line to move. Edit: I still can't believe it, but I actually managed to fix the Drop Pawn Mate bug all by myself: // Fixed PlacePawn by RubixOne (define "PlacePawn" (do (move (from (sites Occupied by:#1 container:"Hand" component:"Fuhyo")) (to (difference (sites Empty) (sites #1 "LastRank")) if:("OnePawnPerColumn" #1 #2) ) ) ifAfterwards:(not (or { (and ("IsInCheck" "Osho" P1) ("CanNotMove" P1 1)) (and ("IsInCheck" "Osho" P2) ("CanNotMove" P2 2)) (and ("IsInCheck" "Osho" P3) ("CanNotMove" P3 3)) (and ("IsInCheck" "Osho" P4) ("CanNotMove" P4 4)) })) ) ) RE: How to return different regions depending on the player number? - dale walton - 04-13-2023 Right. If using 1, 2 or (mover), use (sites Occupied by:(player #1) ... If using P1, P2 or Mover, use (= 0 (% (id #1) 2)) Do you need to pass Mover into the define or can you simply put in (mover) and Mover instead of #1 at the appropriate places? RE: How to return different regions depending on the player number? - RubixOne - 05-01-2023 I solved it by just using an extra parameter for the (mover) attribute. |