Ludii Forum
Question about (site) and "move Select" - 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: Question about (site) and "move Select" (/showthread.php?tid=329)



Question about (site) and "move Select" - slimy_asparagus - 12-12-2020

I have the attached test code. P1 should select one of their pieces and it should flip.

EDIT: Fixed it! I need to use "(last From)".

EDIT2: Okay I have changed the title, because although I got it working, there is still something that does not make sense to me.

The original (at least at some point in my playing with it) piece of code was:

Code:
    (forEach Site ("FlippableSites")
        (move Select (from (site))
            (then (flip (site)))
        )
         )
It did not work because (site) was no longer valid there. But why not?


RE: Question about (site) and "move Select" - dale walton - 12-14-2020

I looks like a good question. Hope the documentation can be updated to give clarity on the scope of iterator variables, whether or not this is expected or unexpected.

Eg would (apply if:(= 1 1) (flip (site))) work instead of the (then...)?
How about (move Select (from (site) (apply flip (site))))?

Or is (apply if:(...) (...)) exactly equivalent to (then (if (...) (...))), or to (if (...) (then (...)))


RE: Question about (site) and "move Select" - Eric Piette - 12-14-2020

Hi,

For all the variables used inside a move description (site), (to), (from), (between), etc.... They are possible to be used inside the ludeme setting them, like here with the (forEach Site ...)
However when you call a (then ...) you create a consequence of that move. If you look the Ludii Game Logic Guide: "The Then object corresponds to the consequences of each legal move. This object contains its own Moves object evaluated and applied after applying the move decided by the mover."

Consequently, the moves inside the (then ...) are computed after one move is decided by the mover (so applied) and use that state as a reference to be computed. That's why you need use (last To) and (last From) and not any variable set during the computation of the moves in the ludeme. These variables at that moment are already set again to their default value.

So to sum up, when the (then ...) ludeme is used, the moves inside it are not computed in the same time at any other computation in the ludeme. So all the variables used in the first computation are not possible to be used as a reference and you need to use the variables to refer to the temporary state after applying the move decided.

Regards,
Eric


RE: Question about (site) and "move Select" - slimy_asparagus - 12-15-2020

Thanks Eric,

I see what you are saying. However that passage in the Logic Guide hardly jumps out at one. Could this example (or something like it) be added to the Guide?


RE: Question about (site) and "move Select" - Eric Piette - 12-16-2020

Hi,

Not exactly that example, but I will add more explanation about that yes in order to be clearer on that.

Regards,
Eric


RE: Question about (site) and "move Select" - dale walton - 12-16-2020

Thanks for this. 

It would also be good in the section on forEach iteration to note that the scope of iteration is solely the move part of the construct, and does not extend to the  (then ...) at the end. -- and that the scope of the iterator variable is not for the entire forEach operation, but is only available to the main move action within it.

These points are obvious when you know how the language works, but for people who don't yet understand, such comment can provide guideposts for starting to understand.

Related scope questions:
So if using (do ... next:( ... )) is the site iterator available to both the part after the do and the part after the next? I assume it is not available to the ifAfterwards condition as that sounds like it is related to consequences. 

What does  (last To) refer to within the  next: section ? does it refer to the (to) in the move before the (do...), or to the (to) in first move of the (do...), or to the (to) in last consequence in the (do...) ?