Ludii Forum
number of friendly pieces in line of sight - 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: number of friendly pieces in line of sight (/showthread.php?tid=159)

Pages: 1 2 3 4 5


number of friendly pieces in line of sight - AlekErickson - 09-10-2020

Hi, I just started working on Mihaw Zapawa's Tumbleweed game. 

In this game, each player takes turns placing stacks on the board.  
Each placed stack has height equal to number of friendly pieces in line of sight from that cell. 
Existing stacks may be replaced with new stacks, only as long as the new stack height is larger than the previous stack height.  

It is quite a simple ruleset and I should be able to figure it out with the Langue Reference, but I post it here anyway, fishing for any kind of advice or general commentary about commands or tricks to use for this. 

Dale I know you were working on Shaka, what do you think about whether the code might be re-usable for this?


RE: number of friendly pieces in line of sight - cambolbro - 09-10-2020

Hi,

I'd suggest looking at existing .lud that implement stacking games for inspiration. Ringo comes to mind, it involves adding and moving stacks (though we cheat there to handle a piece inside a ring as a stack).

Here's the list of .lud that include "stack:true":

Bagh Batti.lud (4 matches)
Bagh Guti.lud (4 matches)
Merimueng-rimueng.lud (2 matches)
Backgammon.lud (10 matches)
Fevga.lud (4 matches)
Plakoto.lud (4 matches)
Portes.lud (10 matches)
Gyan Chaupar.lud (2 matches)
Pachisi.lud (9 matches)
Pagade Kayi Ata (Sixteen-handed).lud (34 matches)
Pente Grammai.lud (5 matches)
Santorini.lud (7 matches)
Connect Four.lud (3 matches)
Ringo.lud (3 matches)
Score Four.lud (2 matches)
Spline.lud
Yavalade.lud (4 matches)
Lasca.lud (7 matches)

Regards,
Cameron


RE: number of friendly pieces in line of sight - Michael - 09-11-2020

I have made a game where you place groups whose size is determined by friendly pieces in sight. It shouldn't be too hard to adapt it from groups to stacks. I have attached the lud-file.


RE: number of friendly pieces in line of sight - AlekErickson - 09-17-2020

Thanks Michael and Cameron, I have made a script for this game but is missing a lot of functionality. Could somebody please take a look and tell me where I'm going wrong?

None of the .lud files recommended by Cameron deal with deploying stacks of arbitrary size. For instance, something like: Rules Move Add Stack (Stack size determined by some variable).

In this case the stack size would be the number of friendly pieces in line of sight of the chosen cell.

For the same reason, I was not able to adapt Michael's .lud file -- I first need to understand how to work with ludeme where players can place stacks as a move.


I attach the current code for the game, which compiles, but it has a lot of problems. I have put comments on where I need specific functionality. Please take a look! 

I will also copy-paste the code here.


(game "Tumbleweed"
    (players 2)
    (equipment
        {
            (board (hex 5))
            (piece "Disc" Each)
            //(stackType Count)
        }
    )
    (rules
        (start (place Random {"Disc1" "Disc2"}))
        (play
            (move
                Add
                (to (
                forEach (sites Board)
                if:(
                and

                (
                (> (count Pieces Mover in:(sites LineOfSight at:(to))) 0)   
                                    // place stacks in line of sight of friendly stacks

                (> (count Pieces Mover in:(sites LineOfSight at:(to))) (topLevel at:(to))) 
                                    // You can only replace an old stack if the newly placed stack is larger
                )
                )
                )
                )

               
                stack:true

              // HEIGHT OF NEWLY PLACED STACK IS EQUAL TO FRIENDLY PIECES IN LINE OF SIGHT 
              // (then
              // (forEach Piece Mover in:(sites LineOfSight at:(lastTo))
              // (add (to (lastTo))))
              // )
            )
        )
        (end
            (if
                (no Moves Next)
                (byScore
                    {
                        (score P1 (count sites in:(sites Occupied by:P1)))
                        (score P2 (count sites in:(sites Occupied by:P2)))
                    }
                )
            )
        )
    )
)


RE: number of friendly pieces in line of sight - AlekErickson - 09-18-2020

I upload a modified version, which gets closer to what I want to do, but does not compile. The problem is, I am improperly using forEach but I don't know why. Now, I am trying to make it so players first select a cell to remove stacks from (as long as the cells contain fewer discs than friendly pieces in line of sight), and then add a disc to that location for each friendly piece in line of sight. Something is not compiling, but from the language reference it seems that I'm using forEach as intended.

(game "Tumbleweed"
(players 2)
(equipment
{
(board (hex 5))
(piece "Disc" Each)
//(stackType Count)
}
)
(rules
(start (place Random {"Disc1" "Disc2"}))
(play
(move
Remove
(to (
forEach (sites Board)
if:(
and

(
(> (count Pieces Mover in:(sites LineOfSight at:(to))) 0)
// place stacks in line of sight of friendly stacks

(> (count Pieces Mover in:(sites LineOfSight at:(to))) (topLevel at:(to)))
// You can only replace an old stack if the newly placed stack is larger
)
)
)
)
(then
(forEach Piece Mover in:(sites LineOfSight at:(to))
(add (piece (id "Disc" Mover)) (to))
)
)
// Height of the new stack is equal to number of friendly pieces in line of sight
stack:true
)
)
(end
(if
(no Moves Next)
(byScore
{
(score P1 (count sites in:(sites Occupied by:P1)))
(score P2 (count sites in:(sites Occupied by:P2)))
}
)
)
)
)
)


RE: number of friendly pieces in line of sight - Michael - 09-18-2020

I really wish I could help you, but I don’t have my computer with me. One thought, though: Have you checked whether topLevel returnes 0 at empty sites? If so, you shouldn’t have to count friendly pieces in line of sight more than once.

Another thought: If forEach Piece doesn’t work that way, you could string together a bunch of «then»s (using (and)) conditional on a comparison between topLevel and friendly pieces in sight. Edit: You don’t need a long string of them, I guess. Maybe you could combine MovesThisTurn and moveAgain, like I did in Even.


RE: number of friendly pieces in line of sight - AlekErickson - 09-18-2020

I think (add...) and (Add...) should have some part of the argument to specify how many, but I cannot figure it out.


RE: number of friendly pieces in line of sight - Michael - 09-18-2020

(09-18-2020, 08:34 AM)AlekErickson Wrote: I think (add...) and (Add...) should have some part of the argument to specify how many, but I cannot figure it out.
Hm. Neither (move Add …) (6.1.1) nor (add …) (6.2.1) seem to have that kind of parameter. Do you mean "should" as in "should have had" (counterfactually), or are you thinking of a different ludeme?
Edit: Jay! (add …) just got a count paramenter in 1.0.7.


RE: number of friendly pieces in line of sight - AlekErickson - 09-18-2020

The code that I have posted above in a previous reply is my attempt at a very simple game.
The way I see it, it should work, but I can't get it to compile. There are 3 rules.

// players take turn placing stacks in line of sight of friendly stacks.
// Height of the new stack is equal to number of friendly pieces in line of sight.
// You can replace an existing stack, only if the newly placed stack is larger.

However, this requires some way to enter a stack of defined height X
(X = # pieces Mover in line of sight)
and if the new stack is being placed on a cell occupied by a smaller stack, then the older stack gets removed.

when i use forEach I get the feeling that Ludii wants to do something with those pieces, rather than just count them, but anyway I tried to use (then (forEach friendly in LOS , (add (to)), hoping that (to) is still the cell the player selected.

It is really confusing! There are many potential ways to approach the problem, but I want to know what's wrong with my approach.


RE: number of friendly pieces in line of sight - Michael - 09-18-2020

(09-18-2020, 01:11 PM)AlekErickson Wrote: There are many potential ways to approach the problem, but I want to know what's wrong with my approach.
Ah! I see. Then I can't help you. Hope someone else can, though. I think it's great that you're implementing Tumbleweed :)