Ludii Forum
Restrictions on where to Add - 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: Restrictions on where to Add (/showthread.php?tid=143)

Pages: 1 2


Restrictions on where to Add - Michael - 08-19-2020

First of all, I would like to say thank you for Ludii! I'm over the moon about this project!

I do find it quite difficult to get my head around this grammar, though. I don't have much experience learning these kinds of technical languages, but I don't doubt for a second that it will be worth it. My most fundamental difficulties are quite general, and I haven't even been able to put them into words, so I will try to be quite concrete.

I have managed to make a trivial basis for a game where one is adding stones to empty cells and gaining a point per stone. The next step is to restrict which empty cells one may add a stone to, but the restriction is quite complicated and I don't know how to implement any part of it. The restriction is this:

You may add a stone at a cell that is part of an isolated connected set of empty cells whose size is greater than the number of friendly stones in the cell’s line of sight.

By "connected set of empty cells" I mean that any pair of cells in the set is connected through a chain of orthogonal adjacencies (and counting a set of a single empty cell as connected) – so it's a "chain" of empty cells, in Go terms. By calling such a set "isolated" I mean to exclude from consideration any cell that is orthogonally adjacent to a stone. To try to put it in constructive terms: First, take all empty cells. Then ignore all cells adjacent to a stone. Then you may add a stone to one of the remaining cells, given that it is part of a connected set of cells that meet a certain size-condition.

Could someone point me in the right direction here? I simply don't understand how to think about these things in Ludii terms.


RE: Restrictions on where to Add - dale walton - 08-20-2020

Can the connected chain include connectivity via the empty adjacent-to-occupied cells, but just not include them in the count, are they excluded from both connecting and being counted?
=============================
I am just learning myself, so this would need a real programmer to check and verify syntax and whether the approach is even possible... I hope I don't set you off on the wrong track, but it seems this last week the staff have got a lot of work , so I will try:

First of all, this looks hard, and is far from a good first project to learn the language. But that's the way I learn too.

A start would be to define "IsolatedCells" and "NumberFriendlyLOS" eg:

(define "IsolatedCells" (forEach (sites Empty) if:(not (sites Around NotEmpty)))
or
(define "IsolatedCells" (difference  (sites Empty)  (sites Around NotEmpty)))

I am not sure how to  define "NumberFriendlyLOS"

Then in the move one would like to count liberties at the cells, but that would require asking the program to count at a location within "IsolatedCells" region, but the program only count "at": or "In:" but not both combined...

so I guess a work around could be not to define "IsolatedCells", but rather to add neutral pieces, on every turn, to the (sites Around NotEmpty) before moves are calculated then
the decision move would be...

(forEach Piece (move Add
                          (to (sites Empty)
                              if:(> (count (Liberties at:(to) Orthogonal))
                                      ("NumberFriendlyLOS")
                                  )
                        )
)

and then remove all the neutral pieces after the decision move is made.

Every small syntax problem (eg don't add spaces after the ":" ) is going to throw the compiler, so you have a lot of work ahead, -- but I also am thinking it is great that this project exists, and good if we can try to support it by learning it and using it.


RE: Restrictions on where to Add - Michael - 08-20-2020

(08-20-2020, 05:00 PM)dale walton Wrote: Can the connected chain include connectivity via the empty adjacent-to-occupied cells, but just not include them in the count, are they excluded from both connecting and being counted?
Thank you so much, Dale! I meant "connected through a chain of orthogonal adjacencies between empty cells not adjacent to occupied cells". And the number of stones in the cell's line of sigh should be counted in the normal region which includes adjacent-to-occupied cells.

I figured out that I can get the right region like this: (difference (sites Empty) (sites Around (sites Occupied by:All)  Orthogonal))
That looks like your second definition. It seems to work, but the real challenge seems to be to use this set of sites to define the relevantly connected set that each site belongs to.

I have not been able to test a way of counting the mover's stones in the cell's line of sight yet, but I'm looking for a way to test something like this: (count Pieces (Mover) in:(sites LineOfSight Piece at:(to)))
This might be gibberish, though. 

I agree that this isn't the easiest place to start. And this is just half of the placement protocol.. But I'm trying to take things one step at a time. So far I have got the following up and running:

Code:
(game "Trivial"
    (players 2)
    (equipment
        {
            (board (square 8))
            (piece "Ball" Each)
        }
    )
    (rules
        (play
            (or
                (move
                    Add
                    (to
                        (difference
                            (sites Empty)
                            (sites Around (sites Occupied by:All)  Orthogonal)
                        )
                    )
                    (then (addScore Mover 1))
                
                )
                (pass)
            )
        )
        (end
            (if
                (all Passed)
                (byScore)
            )
        )
    )
)



RE: Restrictions on where to Add - dale walton - 08-21-2020

Let me know if you find a way through. I'm stuck at different point on different games.

The system seems to be designed more around piece connectivity rather than dynamic region connectivity - probably for efficiency reasons.
I am having a hard time to find ways to test for the connectivity of a region and/or to split a region into disjoint sub-regions or count such and it seems that to identify the regions you want to test, you also need a way to split them.

Also I am not sure if Liberties are just Empty cells or are Playable cells as defined by normal play, or by a specified set of moves. If the latter, maybe a special kind of test piece could be used to define the liberties you need to test, but still I am not sure there is a concept of connection/adjacency that respects membership in a subregion as a criterion for its existance.


RE: Restrictions on where to Add - Michael - 08-25-2020

I think I have found a way to make my problem more tractable. At the bottom of this post is the code for a trivial but related placement protocol. In this game each player places a group of two stones on their turn. The problem is that I am unable to enforce that the first stone must be placed in such a manner that there is space to place the second. It should be illegal to place in the middle of this formation, for example:
[Image: pic5618380.png]
In the version given below you are able to place a stone here and then you pass automatically on the second move. In my attempt to get from this trivial basis to the game I want I have struggled with three difficulties:
  • I need to be able to scale this to groups larger than 2. In the code given here the second stone is placed at a site in (intersection (sites Around (last To) Orthogonal) (sites Empty)). I thought it would work to replace this "Around" ludeme with (sites Around (sites Group Cell of:Cell at:(last To)) Orthogonal), but I can't get it to work. (It gives a strange error-message full of " ".)
  • I need the size of the group to be a function of the cell at which you place the first stone – more precisely the number of the mover's stones in its line of sight. 
  • And I need, as I mentioned, to restrict the first placement to sites where it is possible to follow up with placing the rest of the stones. I have tried to filter out the sites where this can't be done with (can Move …), but I have not found a way to make that work.
Code:
(game "Trivial2"
    (players 2)
    (equipment
        {
            (board (square 8))
            (piece "Ball" Each)
        }
    )
    (rules
        (play
            (if
                (= (count MovesThisTurn) 0)
                (move Add (to (sites Empty)) (then (moveAgain)))
                (if
                    (< (count MovesThisTurn) 2)
                    (move
                        Add
                        (to
                            (intersection
                                (sites Around (last To) Orthogonal)
                                (sites Empty)
                            )
                        )
                    )
                )
            )
        )
        (end (if (all Passed) (byScore)))
    )
)



RE: Restrictions on where to Add - Michael - 08-26-2020

Quote:I need the size of the group to be a function of the cell at which you place the first stone – more precisely the number of the mover's stones in its line of sight.
I have made progress on this front. Now you place groups of size one more than the number of friendly stones in the line of sight of the first placed stone. The two other problems (along with some others) still remain.

About the scaling problem: When placing a group in this version each stone must be placed adjacent to the last placed. I cannot figure out how to allow placement adjacent to any stone belonging in a group with the last placed stone. It is still the case that if I replace (sites Around (last To) Orthogonal) with (sites Around (sites Group Cell of:Cell at:(last To)) Orthogonal) I get an incomprehensible mess on the "status" screen. It starts out like this: 
Quote:<html><h2>Syntax error: Could not create "game" ludeme from description.</h2><br/><p>(<font color=red>game</font>&nbsp;

Edited to add: Something strange happened when I tried (sites Group Cell of:Cell at:(last To) (mover)) in stead of (sites Group Cell of:Cell at:(last To)). Suddenly I don't get to move again even though I place at a cell with friendly stones in its line of sight.But this time there is no strange error message.

I hope it is not considered spamming to update the thread as I make progress. Please tell me if that is the case.

Code:
(game "Less Trivial"
    (players 2)
    (equipment
        {
            (board (square 8))
            (piece "Ball" Each)
        }
    )
    (rules
        (play
            (if
                (= (count MovesThisTurn) 0)
                (move
                    Add
                    (to (sites Empty))
                    (then
                        (and
                            (set
                                Var
                                (count
                                    Pieces
                                    Mover
                                    in:(sites LineOfSight at:(last To))
                                )
                            )
                            (addScore Mover 1)
                            (then (if (> (var) 0) (moveAgain)))
                        )
                    )
                )
                (if
                    (not (> (count MovesThisTurn) (var)))
                    (move
                        Add
                        (to
                            (intersection
                                (sites Around (last To) Orthogonal)
                                (sites Empty)
                            )
                        )
                        (then (and (addScore Mover 1) (moveAgain)))
                    )
                )
            )
        )
        (end (if (all Passed) (byScore)))
    )
)



RE: Restrictions on where to Add - Eric Piette - 09-06-2020

Hi Michael,

I just read all the messages but I am not sure after all of these messages what exactly you try to do.
Can you explain it to me again here and show me maybe with 2 or 3 examples the expected results?

Regards,
Eric Piette


RE: Restrictions on where to Add - Michael - 09-06-2020

(09-06-2020, 07:54 AM)Eric Piette Wrote: Hi Michael,

I just read all the messages but I am not sure after all of these messages what exactly you try to do.
Can you explain it to me again here and show me maybe with 2 or 3 examples the expected results?

Regards,
Eric Piette
Thank you for trying :) 

Imagine a game where you each turn place a number of connected stones of your color. Say, for simplicity, that you always place two connected stones. Naturally, you have to do this by first placing one stone and then a second stone next to it. So there are two moves each turn. Not all regions of empty cells can fit two connected stones, though. In the following image there is a region of one empty cell in the middle of the stones.

[Image: pic5618380.png]

If I were to spend my first move placing here I would not be able to place a second stone connected to the first. What I can't figure out how to do is to make it illegal to place in such a region. That is: I want a restriction on where to place the first stone that ensures that I don't end up in a situation where I'm unable to place the second.

A slightly less simplified example: In the attached file you place a variable number of connected stones each turn. The number of stones, and therefore the number of moves, is dependent on where I place the first stone. But as things are in this file, I am able to place the first stone in a region where I wont be able to follow up with the rest of the stones (just like in the simpler example). What I want, but can't figure out how to define, is a restriction on where to place the first stone that ensures that I don't end up in a situation where I'm unable to place the rest.


RE: Restrictions on where to Add - Eric Piette - 09-06-2020

Hi,

Thanks for that explanation :)

Ok so I guess if you know the number of pieces you have to place before to play your first move, you should be able to check each empty sites with a (forEach Site ...) ludeme and use a condition on each of these sites according to the number of empty sites belonging to a group starting from that site.

With your example with 2 pieces to place and the site surrounded by pieces.
In checking each site in (sites Empty) if we look the size of the group of empty sites starting for each site and keep only the sites that will be equal or more than 2 except for the site surrounded by pieces.

Consequently something like

(move Add (forEach Site (sites Empty) if:(<= 2 (count Sites in:(sites Group (site) if:(is Empty (to)))))))

can work. (in replacing that 2 by the number of pieces you can place for a more general case)

But unfortunately, like I just answered to you in another post, our ludeme (sites Group ...) seems not completely implemented currently.
So I will take a look next week in order to fix that for the next release.

I will come back to you when that will be done and published, and I will also provide to you a simple .lud file with an example of description doing that.

And by the way, sorry for that delay to answer to you, I officially come back from holidays tomorrow :)

Regards,
Eric Piette


RE: Restrictions on where to Add - Michael - 09-06-2020

(09-06-2020, 09:28 AM)Eric Piette Wrote: Ok so I guess if you know the number of pieces you have to place before to play your first move, you should be able to check each empty sites with a (forEach Site ...) ludeme and use a condition on each of these sites according to the number of empty sites belonging to a group starting from that site.

With your example with 2 pieces to place and the site surrounded by pieces.
In checking each site in (sites Empty) if we look the size of the group of empty sites starting for each site and keep only the sites that will be equal or more than 2 except for the site surrounded by pieces.

Consequently something like

(move Add (forEach Site (sites Empty) if:(<= 2 (count Sites in:(sites Group (site) if:(is Empty (to)))))))

can work.



And by the way, sorry for that delay to answer to you, I officially come back from holidays tomorrow :)
Thank you! I hope you don't feel pressured to spend your time off on this. I'm patient.

If I understand your suggestion correctly it assumes that the groups may be placed on any empty cell, so it happens to not generalize to my actual problem. Here's an example where it breaks down: Take the trivial game I described where you place a group of size 2 every turn, but now add the restriction that groups may not be orthogonally adjacent to each other. Then we can end up in a position like this:
[Image: pic5641150.png]
The center cell belongs to a group of 41 empty cells, but it should still be illegal to place there because it would be impossible to place the entire size-two-group there without violating the restriction that groups may not be orthogonally adjacent.