Ludii Forum
Mirroring/Rotating Moves - 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: Mirroring/Rotating Moves (/showthread.php?tid=1041)



Mirroring/Rotating Moves - pbcarrara - 06-29-2022

I'm trying to implement Onitama, a game where cards dictate piece moves. When you use a card, you then give it to your opponent, but flipped!

For example:

Player 1 (red) has the cobra card, so they have the following available moves:

[Image: bgEm4O1.png][Image: FYkmDTT.jpeg]

Now, when Player 2 receives the cobra card, they should have the following options (notice how things have flipped):

[Image: RFNsGWo.png][Image: JvKM8aq.jpeg]


I'll implement the cards later on; for now, I'm just trying to have two pawns move in the “Cobra” pattern. But I wouldn't like to define two separate pieces with different walk patters, since I think this will generate verbose and repetitive code. Is there a way I can “horizontally flip” a walk pattern? This being replacing every L with an R and vice-versa.

Code:
// How do I make this more generic?
(define "CobraWalk" { {R F} {F L F} {L F L F} })

(game "Onitama"
    (players { (player N) (player S) })
   
    (equipment
        {
            (board (square 5))
            (piece "pawn" Each (move Leap
                                     "CobraWalk"
                                     rotations:False
                                     (to if:(or (is Empty (to)) (is Enemy (who at:(to))))
                                         (apply (if (is Enemy (who at:(to))) (remove (to)))))))
        }
    )

    (rules
        (start
            {
                (place "pawn1" {"C4"})
                (place "pawn2" {"C2"})
            }
        )
        (play (forEach Piece))
        (end (if (no Moves Next) (result Mover Win)))
    )
)

(metadata
    (graphics {
        (board Style Chess)
        (player Colour P1 (colour Blue))
        (player Colour P2 (colour Red))}))



RE: Mirroring/Rotating Moves - dale walton - 06-30-2022

Related question: is (if <boolean> <walk> <walk>) allowed?


RE: Mirroring/Rotating Moves - Michael - 06-30-2022

You can make the define more generic by replacing the Ls and Rs with #1 and #2. Those stand for the first and second arguments passed.