Ludii Forum
Swap pieces - 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: Swap pieces (/showthread.php?tid=284)



Swap pieces - AlekErickson - 11-25-2020

Sorry , could somebody help me find games using the Swap pieces mechanic? 
I want to implement my game Resolve and probably Mike Zapawa's Slyde along the way.


RE: Swap pieces - xenos1984 - 11-25-2020

Running grep on the downloaded game rules shows Senet as the only result that is using Swap Pieces. Is that what you are looking for?


RE: Swap pieces - Eric Piette - 11-25-2020

Hi,

The game Wellisch Chess uses it.

But you can download all the .lud in the download pages in one time if you want.

Regards,
Eric


RE: Swap pieces - AlekErickson - 11-25-2020

I'm having trouble setting up swappable sites - I want players to only be able to swap adjacent enemy pieces, but i'm not sure why my code didn't work. I tried something like this:

(move Swap Pieces (site) (sites Distance from:(site) 1))


RE: Swap pieces - Eric Piette - 11-26-2020

Hi,

(swap Pieces ...) can be used only to swap two pieces. So between 2 IntFunctions and not with a RegionFunction (cf the Ludii Language Reference or the grammar).

However in the next release (because I just fixed/improved something in (forEach Site ...)) for swapping one of your piece with each possible adjacent enemy pieces, you can do it; Here a full example (for the next release):


Code:
(game "Test" 
    (players 2) 
    (equipment {
        (board (square 8))
        (piece "Ball" Each
            (forEach
                Site
                (sites Around (from) if:(is Enemy (who at:(to))))
                (move Swap Pieces (from) (site))
            )
        )
    }) 
    (rules
        (start {
            (place "Ball1" 36)
            (place "Ball2" (sites {35 37}))
        })
        (play (forEach Piece))
        (end (if (no Moves Next) (result Mover Win)))
    )
)

Regards,
Eric


RE: Swap pieces - AlekErickson - 11-28-2020

Eric, I think I am almost solved my problem with this swapping. Check out my following code when you get a spare moment - for some reason it is not allowing me to move at all.

I am trying to allow players to Swap adjacent enemy stones if they place a stone that creates a crosscut.

(define "IsCut" (is Pattern {F R F R F} whats:{(mover) (next)}))
(game "Test" (players 2) (equipment {(board (square 8))
(piece "Ball" Each (forEach Site (sites Around (from) if:(is Enemy (who at:(to)))) (move Swap Pieces (from) (site))))
(regions P1 { (sites Side N) (sites Side S) } ) (regions P2 { (sites Side W) (sites Side E) } )})
(rules
(start {(place "Ball1" (sites {36 51 54} )) (place "Ball2" (sites {35 14 10}))} )
(play (do (move Add (to (sites Empty)) (then (while "IsCut" (forEach Piece ))))))
(end {(if (is Connected All Mover) (result Mover Win))})
)
)

I also tried this code, and it also did not let me add any pieces to the board.

(define "IsCut" (is Pattern {F R F R F} whats:{(mover) (next)})) (game "Test" (players 2)
(equipment {(board (square 8))
(piece "Ball" Each (forEach Site (sites Around (from) if:(is Enemy (who at:(to)))) (move Swap Pieces (from) (site))))
(regions P1 { (sites Side N) (sites Side S) } ) (regions P2 { (sites Side W) (sites Side E) } )})
(rules (play (or (do (move Add (to (sites Empty)) (then (if "IsCut" (moveAgain))))) (forEach Piece )))
(end {(if (is Connected All Mover) (result Mover Win))})))


RE: Swap pieces - Eric Piette - 11-30-2020

Hi,

you have a

(do ....)

alone with no other argument that's a move ludeme.
So the condition not defined is never true, consequently no legal moves for it.
If you just remove it you will have legal moves.

Regards,
Eric


RE: Swap pieces - AlekErickson - 11-30-2020

Wow, okay it works like magic when removing the do. Thank you!
Now I still need to work into the game the nuances of *swap then add* but for now this is a great achievement. Thank you

Wait, nevermind! It seems like the check for pattern is across the whole board, but it does not check whether the last piece was in the pattern. So I need some way to link the last placed piece to the pattern check.