Ludii Forum
Conditional movement - 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: Conditional movement (/showthread.php?tid=532)



Conditional movement - Enrique - 04-04-2021

I just started with ludii and I'm learning how the language works. Now I'm struggling with a conditional clause for movement.

The setup is a square board with checkers pieces on it. I want to move the pieces in any direction through empty spaces until they reach the farthest location.

I've managed to accomplish this with:

Code:
(piece "Disc" Each
    (move
      (from)
      (to (sites LineOfSight Farthest at:(from)))
    )
)

But I want to allow this movement only if the piece ends it next to an Enemy piece in the same direction. I've tried to add somewhere an if clause similar to the following one

Code:
if:(not (is Friend (who at:(sites LineOfSight Piece at:(from)))))

but I don't know how to make it work. Do you know any examples I can look at?


RE: Conditional movement - cambolbro - 04-04-2021

Hi,

You could try directionCapture, something like:


Code:
(directionCapture
    (from (last To))
    (to if:(is Enemy (who at:(to))) (apply (remove (to))))
)

See Fanorona.lud and Vela.lud.

Regards,
Cameron


RE: Conditional movement - Enrique - 04-04-2021

Thanks! I will take a look at it to see how it works.


RE: Conditional movement - Eric Piette - 04-06-2021

Hi,

If I understand correctly what you are trying to do, this is not a capturing move, but just moving a piece in the farthest empty sites next to an enemy piece in the same direction.

In that case the correct description is

Code:
(do
   (move
      (from)
      (to (sites LineOfSight Farthest at:(from)))
   )
   ifAfterwards:(is Enemy
       (who
           at:(ahead
                (last To)
                (directions Cell from:(from) to:(last To))
              )
       )
   )
)

That's just the move you described inside a (do ...) ludeme checking if the piece after your move is an enemy piece.

Regards,
Eric


RE: Conditional movement - Enrique - 04-06-2021

Yes! That's exactly what I wanted. Thanks.

But now I have a compilation error:

Unexpected syntax '(directions Cell from...' in 'at:(ahead (last To) (directio...'.

Is it because Cell is not defined?


RE: Conditional movement - Eric Piette - 04-06-2021

Are you using the last version? 1.1.16.
Because that works perfectly here.

Eric


RE: Conditional movement - Enrique - 04-06-2021

Yes, 1.1.16


The complete code I'm using is:

Code:
(game "Collider"

    (players 2)

    (equipment
        {
            (board (square 6))

            (piece "Disc" Each
        (do
             (move
                (from)
                (to (sites LineOfSight Farthest at:(from)))
                  )
                  ifAfterwards:(is Enemy
                   (who
                     at:(ahead
                              (last To)
                              (directions Cell from:(from) to:(last To))
                             )
                           )
            )
                )
        )          



        (piece "Circle" Shared (move (from) (to (sites LineOfSight Farthest at:(from)))))

        }
    )

    (rules

        (start
            {
            (place "Disc1" (difference (union (sites Top) (sites Bottom)) (sites Corners)))
            (place "Disc2" (difference (union (sites Right) (sites Left)) (sites Corners)))
            }
        )

        (play
            (forEach Piece)
        )

        (end
            (if
                (no Moves Next)
            )
        )

    )

)

(metadata
    (graphics
        {
            (board Style Chess)
        }
    )
)

Thanks,

Enrique


RE: Conditional movement - Eric Piette - 04-06-2021

Hi,

Your description works perfectly fine here. So I guess you will have to wait our next release.

Regards,
Eric


RE: Conditional movement - Enrique - 04-06-2021

Glad to know. I'll wait and then I'll come back with more questions to complete the game ;-)


RE: Conditional movement - Enrique - 04-24-2021

I've just tried it with the new version (1.1.17) and works like a charm. Thanks!