Ludii Forum
how to check identity for conditional - Printable Version

+- Ludii Forum (
+-- Forum: Questions (
+--- Forum: About the Ludii Grammar (
+--- Thread: how to check identity for conditional (/showthread.php?tid=744)

how to check identity for conditional - sharmoni - 11-02-2021

I'm having trouble understanding how to get identity of a piece or region for conditional logic.

I was able to use this code to return a player region depending on the player:

(define "EnemyBase"
    (if (is Mover P1) (sites P2) (sites P1))

(regions "Base" P1 {60})
(regions "Base" P2 {66})

Which is used to determine if player has reached their goal:

(end (if (is In (last To) ("EnemyBase")) (result Mover Win)))

Is there a simpler way?

I'm currently getting syntax errors trying to use the following code to determine if the piece being moved is named "Stone" (which has specific restrictions during a multi-hop movement):

(define "PieceIsStone"
    (= (what at:(from)) (id "Stone" Mover))

The code is similar to a line used in Jungle.lud to determine if if an enemy "Elephant" piece is on a space (at least I think that's what it does):

// A rat can capture an elephant if it is not in the water first.
    (not (is In (from) (sites "Water")))
    (= (what at:(to)) (id "Elephant" Next))

Again, is there a simpler way? Or a correct syntax?

RE: how to check identity for conditional - Eric Piette - 11-03-2021


For the first part, you can just use (sites Mover "Base") to get the region of the mover.

For the second part, that's the correct way to do it and your syntax seems to be correct. So my hypothesis is that you have a syntax error somewhere else (probably somewhere calling that define). To help you with that I will need the full .lud you are currently writing.


RE: how to check identity for conditional - sharmoni - 11-04-2021

Thanks for your help!

I tried three different ways of using (sites [roleType] "Base") to get the enemy base region:

(sites Enemy "Base") caused a temporary hang after moving piece and didn't end the move
(sites NonMover "Base") didn't cause a hang but also didn't end the move
(sites Next "Base") only works for non-multi-hop moves—I'm guessing because Mover is also Next—so hopping to player's own base registers as a win for player

Regarding the syntax error for checking which type of piece is moving it is indeed a problem of where I'm trying to call the define. 

I was hoping to use it at the (to if: ) section of the multi-hop [line 45]. Is that possible or should I create alternate hop sequences for each piece type?

If I understand correctly the syntax error is because only sites (to) can be tested at that point in the (move ) ludeme and I'm trying to check a piece identity.

RE: how to check identity for conditional - sharmoni - 11-09-2021

Update: I think Camelot.lud is a better code match for my rules, so I'm currently using that as my base (rather than trying to mash the chess and chinese checkers luds).

RE: how to check identity for conditional - Eric Piette - 11-15-2021


First part:

Oh yes, if in your game you have some (moveAgain) you can't use (sites Next ...) for the reason you are saying, moreover, Enemy or NonMover can't work because this ludeme is supposed to return a region you are defining in the equipment, not many, which can be the case if you have more than 2 players.
Even if in reality I would be able to modify it a little bit the code to do what you expected.... I am going to add a todo to myself to do it in the future.

But for the moment, for this case, what you are doing is correct with the (if ...) solution.

Second part:

No in the (to ...) part any variable can be checked, however their value depends of the place in the ludeme. But here I do not see why that should not work.
In the file you submitted, you did not add the part you mentioned before, so I am not sure what was not working for your side, can you re submit it with exactly the problem you had for me to check?

Thanks !

RE: how to check identity for conditional - sharmoni - 11-15-2021

Thanks for affirming that I can check any variable in the (to ...) part of a move. I was able to get this version working.

RE: how to check identity for conditional - Eric Piette - 11-16-2021

Great :)

Let me know when you think your game is ready to be added to Ludii itself :)