Ludii Forum
Problem Mapping Roles to Roles? - Printable Version

+- Ludii Forum (https://ludii.games/forums)
+-- Forum: Problems (https://ludii.games/forums/forumdisplay.php?fid=5)
+--- Forum: Ludii Player Problems (https://ludii.games/forums/forumdisplay.php?fid=6)
+--- Thread: Problem Mapping Roles to Roles? (/showthread.php?tid=344)

Pages: 1 2


Problem Mapping Roles to Roles? - dale walton - 12-20-2020

For a game with varying numbers of players and multi decision turns, I need to find the previous player because the mover has of a special relationship with the previous player's pieces.

1) Your documentation seems gives no guidance as to whether (prev) is whichever play moved on the last turn or is the player with the next lower index. - but (is Prev Mover) (also shown in the documentation as (isPrev Mover)) makes me believe (prev) must be who ever moved in the previous turn - which is not what I need.

Is that correct?

2) The documentation shows the map function can be used to map roles.  Thus I set up a role mapping to find the previous player with a mapEntry function.  However this did not work. Why?


(equipment
  {

    (map "PrevPlayer"
      {
      (pair P2 P1)
      (pair P3 P2)
      (pair P1 P3)
      }
    )
  }
...

  (between if:(is Within (id "Hex" (mapEntry "PrevPlayer" Mover) ) at:(between))
...

Unexpected syntax '(mapEntry "PrevPlayer...' in '(id "Hex" (mapEntry "PrevPlayer...'.


   (sites Occupied by:(mapEntry "PrevPlayer" Mover) component:"Disc")
gave:
Unexpected syntax 'by:(mapEntry "PrevPla...' in '(sites Occupied by:(mapEntry ...'.

Please note I also tried various combinations of  (player (...)) with this, but that didn't help.
If it should work, what is the proper syntax?


RE: Problem Mapping Roles to Roles? - xenos1984 - 12-20-2020

Should it be 1, 2, 3 instead of P1, P2, P3? I remember something similar in Triad, but that uses (if ...) instead of (map ...):

http://ludii.games/lud/games/Triad.lud


RE: Problem Mapping Roles to Roles? - Michael - 12-20-2020

Pretty sure (prev) gives the player who last made a move, yes. What about (+ 1 (% (+ 1 (mover)) 3))?


RE: Problem Mapping Roles to Roles? - dale walton - 12-21-2020

Thanks to all commenters so far.

Re: but that uses (if ...) instead of (map ...):
Yes, a chain of if's is probably the way to go but will be a bit of a nuisance with a selectable number of players.

For the developers:
This is a pretty basic game concept that the language should provide for and the documentation for map and path both talk about role to role maps and illustrate a case for player roles mapping to player roles (but no context.)

The logic guide also says map converts them to integers. The problem is, then, what converts them back; or else, why isn't a map integer for a player role acceptable syntax - can't the compiler go back and check what kind of mapping it is, and if not, then what is the purpose of the map role-to-role - do I need to assign the result to a variable to pass the syntax checking, or is the value actually incompatible with the value that the (id ... ) requires? And in the end, why doesn't (player (...)) turn the map "integer" (if that is what comes out of map) back into something useful?

----------------------------------------------------------------------
Re: Pretty sure (prev) gives the player who last made a move, yes....

in addition to (prev) documentation being unhelpful, in the 14.3.4 Role type documentation this is misleading:

Prev : Player who moved on prior turn
Should be: Player who made the previous decision move
(unless it actually is player who made the previous decision or consequence move - for example what happens after a (then after a (set Player ) consequence?)

Re: What about (+ 1 (% (+ 1 (mover)) 3))?
That kind of approach is what I tried first but more generalized for multi-players. I just tried yours both with and without (player (...)) around it but still getting syntax error in for:
(id "Disc" (+ 1 (% (+ 1 (mover)) 3)))
and for:
(id "Disc" (player (+ 1 (% (+ 1 (mover)) 3))))


RE: Problem Mapping Roles to Roles? - Michael - 12-21-2020

What I wrote is a formula for the index of the player who took the previous turn. Why would you want to use that to get the index of a piece belonging to that player? Wouldn't that just return the same index?


RE: Problem Mapping Roles to Roles? - dale walton - 12-22-2020

Your right I guess. To me this is a black box. There is nothing I can find to turn a player index into a role, and the (id function to find a component index seams to require a role? - or at least a player index derived via a role. If the later, I was hoping that the id function would accept it. Occupied by: also needs a role.

So how can I generate a role index eg "P1" ??, or otherwise check for pieces owned by a specific, dynamically-determined player role?


RE: Problem Mapping Roles to Roles? - Michael - 12-22-2020

(sites Occupied by:<player>) works. Also (forEach (sites Board) if:(= <int> (who at:(site)))). Not sure if you need "level:(size Stack at:(site))" in (who) to only check the top piece, but I don't thing so (I also don't know if the top level is one less than the size of the stack..).


RE: Problem Mapping Roles to Roles? - dale walton - 12-23-2020

(12-22-2020, 07:52 AM)Michael Wrote: (sites Occupied by:<player>) works. Also (forEach (sites Board) if:(= <int> (who at:(site)))). Not sure if you need "level:(size Stack at:(site))" in (who) to only check the top piece, but I don't thing so (I also don't know if the top level is one less than the size of the stack..).
So to specify the component, I need to use
(is In <int> (sites Occupied by:(player <int>) component:"Hex")), 

because in
(is Within <int> at:(<int>))
the component index can't be specified without having a player role.
e.g. (id "Hex" <player role>)

Same for (= <int> (what at:(<int>))


RE: Problem Mapping Roles to Roles? - Eric Piette - 01-04-2021

Hi,

Here what said the documentation is the Ludii Logic Guide:

(prev): Returns the index of the player who has played in the previous state.

So that ludeme returns the player who played in the previous move (not the previous turn).

I will check with the others to add a parameter to prev in order to return the mover of the previous turn.

Something like (prev turn:true)

For the comment about the documentation of the LLR of the Prev RoleType, I agree and I updated it.
-----------------------------------

For the comment about using roleType in the (pair ...) ludeme, that should work. We have many games using that. e.g. Halma.

However I can see in your code that you try to use (id ....) with a name and a IntFunction. But as you can see in the documentation, a RoleType is expected. To be clear, the ludeme (mapEntry ......) is returning an IntFunction corresponding to the id of the RoleType here.

Eric


RE: Problem Mapping Roles to Roles? - Eric Piette - 01-04-2021

Hi,

I added the ludeme (prev MoverLastTurn) to our dev release to get the mover of the previous turn.

It will be available in the next release.

Regards,
Eric