Ludii Forum
Lines of Sight problem - 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: Lines of Sight problem (/showthread.php?tid=104)



Lines of Sight problem - AlekErickson - 08-02-2020

I am now working on implementing a game where players must add a piece within line of sight of the most recent placement. 
No matter what I try, it doesn't seem to work. I've tried all sorts of combinations with last To , LastTo, placing the parentheses or not, using the at: or not, but I can't get it to work. Can somebody figure out what is preventing it from compiling? 

(game "Trike" (players 2) (equipment {(board (hex triangle 5))(piece "Ball" Each)})
(rules (meta (swap)) (play (or (if (= (count Moves) 0) (move Add (to (sites Empty)))) (move Add (to (sites LineOfSight at: (last To))))))
(end (if (no Moves Next) (byScore {(score P1 (count Neighbours (last To)) P1)(score P2 (count Neighbours (last To)) P2)(addScore Mover 1)})))))


RE: Lines of Sight problem - DennisSoemers - 08-02-2020

There's four points I've noticed looking into your code:

1. The LineOfSight sites part should be written as "(sites LineOfSight at:(last To))". That's almost exactly what you wrote in your post already, but importantly, there cannot be a whitespace between the "at:" argument name and the subsequent opening bracket of the "(last To)".

2. The (score ...) ludeme used in the End rules can only have two arguments; a <roleType> and an <int>. See 13.2.1 of the Ludii Language Reference (https://ludii.games/downloads/LudiiLanguageReference.pdf). Both of the occurrences of this ludeme in your code have a third (again a roleType) at the end, which cannot be included there.

3. The "at:<int>" argument of the (count ...) ludeme is a named argument, so the "at:" prefix needs to be explicitly included, changing "(count Neighbours (last To))" to "(count Neighbours at:(last To))". See 8.5.1 of the Ludii Language Reference.

4. The array argument of (byScore ...) only accepts elements of type "<score>" (see 5.2.1 of the language reference), which doesn't include the (addScore ...) ludeme.

If I remove / tweak some things according to the points above, I end up with the following code which does compile (but I did remove some things so it's probably not yet exactly the game that you wanted, to help more with that we first need to know exactly how you do want the game to play):

Code:
(game "Trike"
    (players 2)
    (equipment {(board (hex triangle 5))(piece "Ball" Each)})
    (rules
        (meta (swap))
        (play
            (or
                (if
                    (= (count Moves) 0)
                    (move Add (to (sites Empty)))
                )
                (move Add (to (sites LineOfSight at:(last To))))
            )
        )
        (end
            (if
                (no Moves Next)
                (byScore
                    {
                        (score P1 (count Neighbours at:(last To)))
                        (score P2 (count Neighbours at:(last To)))
                    }
                )
            )
        )
    )
)



RE: Lines of Sight problem - AlekErickson - 08-06-2020

Thanks for your detailed response last time. The program you sent didn't compile, but with the new release and some discussion with Cameron we got it to compile, however there are way more issues. Now, while the code seems to sometimes recognize lines of sight , other times it does not , making certain legal placements not legal (or at least they are too slow to happen). Also , the scoring is not working. I want the game to count points for every neighbor to the last placed stone of their color, and also the person who made the final move should get 1 point.

Here is the current code.


(game "Trike"
(players 2)
(equipment
{
(board (hex triangle 5))
(piece "Ball" Each)
}
)

(rules
(meta (swap))

(play
(if (= (count Moves) 0)
(move Add (to (sites Empty)))
(move Add (to (sites LineOfSight Farthest at:(last To))))
)
)

(end
(if
(no Moves Next)
(byScore
{
(score P1 (count Neighbours at:(last To)))
(score P2 (count Neighbours at:(last To)))
}
)
)
)
)
)

I should say - your code did compile, but it was not possible to place stones on the board at the time.

- the way it is not working is that it does not actually count any score at all, as far as I can tell.


RE: Lines of Sight problem - AlekErickson - 08-07-2020

Hi, I realized something is wrong. The furthest Argument essentially forces players to choose the furthest move in line of sight of the last-placed stone,

but it should allow players to choose any cell in line of sight from the last-placed stone.

But, when I remove Farthest, then I am not able to place any stones past the first one.

It also seems strange to me that the checking for turn zero envelops the line of sight placements. When I make it inside of an "or" argument, like so:
(or(if (= (count Moves) 0)(move Add (to (sites Empty))))
(move Add (to (sites LineOfSight Farthest at:(last To)))))

the problem becomes that the game never detects an ending somehow - edit, it does detect an ending but the player needs to click an extra time on the board to trigger it, and the scoring doesn't correspond to what I expect.

If I remove the "or", I get this -
Unexpected syntax '(play (if (= (count M...' in '(rules (meta (swap)) (play (i..

Going back to the scoring issue - I see that there is no player specificity to the score - each player always gets the same score. I think this is because there is not P1/P2 designation in the scoring algorithm. So I try some things -

(end
(if
(no Moves Next)
(byScore
{
(score P1 (count (regions P1 Neighbours at:(last To))))
(score P2 (count (regions P2 Neighbours at:(last To))))
}
)
)
)

but it really fails. Do you know an answer for these?

I will post it to the forum as well.

Also - please ignore the "disappeared smilies"  - those were :( in the code between "at" and "last".


RE: Lines of Sight problem - cambolbro - 08-07-2020

Hi,

1. (sites LineOfSight Empty ...) should return all empty sites in line-of-sight. Isn't that what you're after?

2. When changing the (or (if (A)) (B)) structure to an if structure, note that you need to rebracket the second clause to make it mart of the "if" clause, i.e. (if (A) (B)) not (if (A)) (B). I'd suggest checking your bracketing carefully.

3. It's hard to advise on the scoring problem without knowing the rules of your game. If you want the score to be based on number of neighouring pieces then your formulation won't work as (count Neighbours ...) returns the number of sites that are neighbours, i.e. are adjacent. If you want to count the number of *occupied* neighbours, you can do something like the following (this is from the Game of Life, which will appear in an upcoming release):

(define "Nbors"
    (count Sites
        in:(intersection
            (sites Around #1)
            (sites Occupied by:#2)   
        )
    )
)


then call it with ("Nbors" (to) Mover) or ("Nbors" (last To) Mover) or whatever is appropriate for your case.

Regards,
Cameron


RE: Lines of Sight problem - dale walton - 08-10-2020

Version 1.0.2
Problem with  Line of Site
(define "Jumping"     
  (forEach Piece
    (move
      (from)
      (to (sites LineOfSight Farthest at:(from)))
    )
  )
)
Attached see a picture of the result. Correct if there is an empty further along the line, but incorrect if there is not another empty in the line.

Update:
The below solves it.  Main problem is the need for good documentation, but the  if:(is Empty (to)) should be the default, so that if it is not wanted the role for the piece can be specified instead:

(define "Jumping"
  (forEach Piece
    (move
      (from)
      (to (sites LineOfSight Farthest at:(from))
          if:(is Empty (to))
      )
    )
  )
)


RE: Lines of Sight problem - Michael - 09-28-2020

I finally found a little time. I think this almost works, but I don't know how to remove more than one stone.

Edit: Oops. Wrong thread..