Ludii Forum
More variables? - 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: More variables? (/showthread.php?tid=121)



More variables? - ccxvii - 08-10-2020

The reference has a rules for (var "string") that seems to allow back multiple state variables. How do I set the values? (set Var ...) does not take a name, it only sets the anonymous (var) value and I find myself in need of more than one variable.

My actual problem is implementing a 'don't undo the last move' rule. The (meta (noRepeat Positional)) does not seem to have an effect, and (avoidStoredState ... (then (rememberState))) also does not work as I want.

I've got this almost working, but need more than one variable to hold the (last From) state as well.

        (do   
                (forEach Piece)
                ifAfterwards:(not (= (var) (last To)))
                (then (set Var (last From)))
        )

Would really like to do this:

        (do   
                (forEach Piece)
                ifAfterwards:(not (and (= (var "LastFrom") (last To)) (= (var "LastTo") (last From))))
                (then (and (set Var "LastFrom" (last From)) (set Var "LastTo" (last To))))
        )


PS. Can you disable smilies by default in this subforum too?


RE: More variables? - Eric Piette - 08-11-2020

Hi,

If I understand correctly, you want to avoid the same player to go back to the previous position of the last piece moved.

Many ways are possible to describe that, but here you can find one using the same mechanism (with the do ludeme) of your example:

Code:
(do 
    (forEach Piece)
    ifAfterwards:(not
       (and
            (is In (last To) (sites Pending))
            (is In (last From) (sites Pending))
       )
    )
    (then
        (and
             (set Pending (sites {(last To) (last From)}))
             (moveAgain)
        )
    )
)


And just for information, I include the (moveAgain) ludeme in this example but maybe you already did it in one in the generator of the move of the pieces.
Moreover, the pending values are values stored only during one state, then they are reset. They are the variables to use for a such case in order to implement it efficiently.

Regards,
Eric Piette


RE: More variables? - MatthewStephenson - 08-11-2020

Hi,

Smiles should now be disabled by default when posting a reply or starting a new thread on any of the Forums.
If you see any more cases where you think they should be disabled please let us know :)

Cheers,
Matthew


RE: More variables? - ccxvii - 08-11-2020

The pieces are shared, but you can only pieces in your area of the board. You are not allowed to "undo" the last players move by moving the piece the previous player moved back to where it came from.

Using the Pending sites worked, but I'm not sure exactly why. I would have expected the list to reset when the next player's turn came up. When are the Pending sites reset exactly?


RE: More variables? - Eric Piette - 08-11-2020

The pending values of the state are stored only for one move turn (one state) then they are reset.

For example, with s = State

for s0 --> s1 --> s2 --> ... --> ...

if from s0 we apply a move including to set some pending Values
in s1 these values will be there and we can access them with (sites Pending)
but in s2 the pending values will be reset and not accessible.

Regards,
Eric Piette.


RE: More variables? - Michael - 10-25-2020

(08-10-2020, 10:19 AM)ccxvii Wrote: The reference has a rules for (var "string") that seems to allow back multiple state variables. How do I set the values? (set Var ...) does not take a name, it only sets the anonymous (var) value and I find myself in need of more than one variable.
I have the same question. The reference says that (var [<string>]) is used to "identify the value stored previously with a key in the context." But I can't find a way to store a value with a key.


RE: More variables? - Eric Piette - 10-26-2020

Hi,

Yes this is something we have in mind in case the designer need more variables (simply with a map between string and integer) however that's not currently possible to set them except the predefined ones such as 'site' or 'value' for the iteration in a (forEach ...) which are stored in that map. I will add a way into setVar to set them, this is not done currently.

Regards,
Eric


RE: More variables? - Eric Piette - 11-16-2020

Hi,

Just to notify you, that I just added to our dev version, a way to set different variables with (set Var ...) in specifying the name of the variable. That will be released with the next version.

Regards,
Eric