06-29-2022, 09:09 PM
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]](https://i.imgur.com/bgEm4O1.png)
![[Image: FYkmDTT.jpeg]](https://i.imgur.com/FYkmDTT.jpeg)
Now, when Player 2 receives the cobra card, they should have the following options (notice how things have flipped):
![[Image: RFNsGWo.png]](https://i.imgur.com/RFNsGWo.png)
![[Image: JvKM8aq.jpeg]](https://i.imgur.com/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.
For example:
Player 1 (red) has the cobra card, so they have the following available moves:
![[Image: bgEm4O1.png]](https://i.imgur.com/bgEm4O1.png)
![[Image: FYkmDTT.jpeg]](https://i.imgur.com/FYkmDTT.jpeg)
Now, when Player 2 receives the cobra card, they should have the following options (notice how things have flipped):
![[Image: RFNsGWo.png]](https://i.imgur.com/RFNsGWo.png)
![[Image: JvKM8aq.jpeg]](https://i.imgur.com/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))}))