Ludii Forum
Oomph - Ludii making actions out of sequence - Printable Version

+- Ludii Forum (https://ludii.games/forums)
+-- Forum: Problems (https://ludii.games/forums/forumdisplay.php?fid=5)
+--- Forum: Game Problems (https://ludii.games/forums/forumdisplay.php?fid=17)
+--- Thread: Oomph - Ludii making actions out of sequence (/showthread.php?tid=499)



Oomph - Ludii making actions out of sequence - dale walton - 03-10-2021

I have got to the point of getting some output yielding movement.
Looking at the full moves in compasison to the code Ludii is processing the script out of order:
The itterated (remember) statement should all be completed before the (then) in the (and) statement is executed, and thus before the actual movements are calculated.  Because of this the moves generated seem somewhat random.

please check the code and suggest a correction/workaround and also kindly fix this longstanding (and) bug.


Moves:

7. [(Select Cell 15 - Cell 16), (Remember Value 'D1' 6), (Move 6-7), (Move 6-8), (Move 6-9), (Move 6-10), (Remember Value 'D1' 12), (Remember Value 'D1' 13), (Move 13-14), (Move 13-15), (Move 13-16), (Move 13-17), (Remember Value 'D2' 7), (Move 12-13), (Remember Value 'D2' 13), (Remember Value 'D2' 14)]

8. [(Select Cell 44 - Cell 30), (Remember Value 'D1' 23), (Move 30-22), (Move 23-15), (Move 15-8), (Forget Value 'D1' 23), (Forget Value 'D1' 30), (Forget Value 'D1' 31), (Forget Value 'D1' 23), (Forget Value 'D2' 15), (Forget Value 'D2' 22), (Forget Value 'D2' 23), (Move 15-2), (Move 23-8), (Move 23-2), (Remember Value 'D1' 30), (Remember Value 'D1' 31), (Move 31-23), (Move 31-15), (Remember Value 'D2' 15), (Remember Value 'D2' 22), (Remember Value 'D2' 23)]

(define "Shift"
(slide
  (from Vertex #1)
  (directions Cell from:(last From) to:(last To))
//  (between (exact 0))
//  (to Vertex)
))

(define "Plow"
(move Select
  (from Cell (sites Board Cell) if:("IsDozerLocation" (from)))
  (to Cell (sites Around Cell (from) OffDiagonal))
  (then
  (and
    {
    (forEach Site ("DozerLocation" (last From)) (remember Value "D1" (site)))
    (forEach Site ("DozerLocation" (last To)) (remember Value "D2" (site)))
    }
    (then
    (forEach Site
      (difference (sites (values Remembered "D1")) (sites (values Remembered "D2")))
      ("Shift" (site))
      (then
      (forEach Site
        (intersection (sites (values Remembered "D1")) (sites (values Remembered "D2")))
        ("Shift" (site))
        (then
        (forEach Site
          (difference (sites (values Remembered "D2")) (sites (values Remembered "D1")))
          ("Shift" (site))
          (then (forget Value All))
))))))))))


RE: Oomph - Ludii making actions out of sequence - Eric Piette - 03-11-2021

Hi,

As far as I can tell what your description is doing (because the description is a bit too long to show an obvious problem), you have a bunch of difference consequences of consequences of consequences.... So the moves returned in the legal moves are corrects.
Because when the computation of the moves is realised, the moves corresponding to the first consequences are obtained so something like
- {(Move1, csq), (Move2, csq), (Move3, csq), (Move4, csq), (Move5, csq)}
Then when each of these (Movei, csq) is computed we got:
- {(Movei1, csq2),(Movei2, csq2),(Movei3, csq2),(Movei4, csq2)}

ect....

so at the end you got (Move1, {(Move11, csq2),(Move12, csq2),(Move13, csq2),(Move14, csq2)} and you repeat that for each csq2 until the last csq. So the order of the actions computed for each move is correct according to your description but just not what you expected from this description.

I think what you are simply trying to do is just

(then
(and {
CsqMove1
CsqMove2
CsqMove3
CsqMove4
CsqMove5
})
)

However, the way you are doing it, with some remember in the consequences, then forget it just after, seems wrong. So I am not sure what you are trying to do, but I do not think you need to remember these sites if you forget them just after.
I guess you can just use them directly, with no need of remembering them.

Regards,
Eric


RE: Oomph - Ludii making actions out of sequence - dale walton - 03-11-2021

I was able to work around this using (do (and ... ) Next:(do (forEach Site ...) Next:(do .......

Also I noted that:

(hop ... (between (exact 0))
is (intentionally?) the same as
(slide ... (between (exact 1))

and the new (direction from: to:) only seems to work with slide and push


RE: Oomph - Ludii making actions out of sequence - dale walton - 03-11-2021

Please try to understand. What I did was intentional and correct. You can see my intent in the other bug report that uses (do) to solve the problem.

The (and .... ) choices should be closed before the (then ) consequences that it contains are handled to be consistent with the rest of the language.
However in the turn shown in the moves tab, we see moves occurring before the remember items have been completed.

If slide is smart enough, I can get rid of the remembers, but I was getting partial slides, and I need the 5 locations (triangle and two locations in front of it with any player's pieces, to move as a block.  Is that what slide does?

In any case, this just freezes on red dots for a while, then reverts to blue dots without doing anything

(define "Plow"
(move Select
  (from Cell (sites Board Cell) if:("IsDozerLocation" (from)))
  (to Cell (sites Around Cell (from) OffDiagonal))
  (then
  (and
    {
    ("Shift" (difference ("DozerLocation" (last To)) ("DozerLocation" (last From))))
    ("Shift" (intersection ("DozerLocation" (last From)) ("DozerLocation" (last To))))
    ("Shift" (difference ("DozerLocation" (last From)) ("DozerLocation" (last To))))
    }
))))

(define "DozerLocation" (sites Incident Vertex of:Cell at:(#1)))

(define "Shift"
(slide
  (from Vertex #1)
  (directions Cell from:(last From) to:(last To))
  (between (exact 1))
))
-----------------------------------------------------------
Ideally the following should work and be enough:

(define "Plow"
(move Select
  (from Cell (sites Board Cell) if:("IsDozerLocation" (from)))
  (to Cell (sites Around Cell (from) OffDiagonal))
  (then
   ("Shift" (union ("DozerLocation" (last To)) ("DozerLocation" (last From))))
)))


RE: Oomph - Ludii making actions out of sequence - Eric Piette - 03-12-2021

Hi,

For you first message:
- Yes a slide of exact 1 is just a step move and a hop of nothing is also a step move. That's intentional.
- I just tried (directions Cell from:1 to:2) on a hop move on a test game, that works perfectly well.

For the second message:
- I tried to explain to you how works the consequences, but I guess I was not enough clear. The consequences moves are merged to each move computed by a moves ludeme. So if you have consequence2 of consequence1, the moves of consequences2 will be merge to each move of consequence1, ect... if you more consequence of consequence. Consequently, if at some point one of the consequence is empty, some consequence of the last consequence can be applied before another, because you merge many consequences of different point in your tree of consequences.
So that's not a bug in Ludii, that was just a description which does not correspond to what you expected.

For the message in which you speak about using a (do ...) to solve your problem, that's just the right way to do what you expected.

For the last part about a description and a comment about slide, like always I need a full .lud to try it and see the special state you are talking about.

Regards,
Eric


RE: Oomph - Ludii making actions out of sequence - dale walton - 03-12-2021

OK thanks for the info on Ludii. I think the confusion is that the (earlier?) documentation indicated that this merging was by action (move), not by (decision) move.

Also because the term "Consequence" comes from "with sequence" so the expectation is that the part before the "then" is at a separate stage than the part after, in a consequence of a consequence.

Also the way you have implemented these consequences can get duplicated as well (by design...) which can lead to poor performance if not properly understood.

OK, I am now warned of what to expect.

I will send the full file in a while, but you already complained it is too complicated for you.


RE: Oomph - Ludii making actions out of sequence - dale walton - 03-13-2021

Just to be sure I understand correctly about (and { (<A>) (<B>) (<C>) } (then (<D>))) .
Is this 100% equivalent to (and { (<A>) (<B>) (<C>) (<D>) } )? -- If not, what is the difference?
Is it 100% equivalent to (and { (<A> (then (<D>))) (<B> (then (<D>))) (<C> (then (<D>))) } )? -- If not, what is the difference?

Do all the above have the same limitations on no reuse of values / dependancies on values contained in A,B,C and/or D?


RE: Oomph - Ludii making actions out of sequence - Eric Piette - 03-15-2021

Hi,

The merging is not done by decision move, I did not say that. They are done by moves computed by the ludemes (by their eval methods) as explained in previous messages.
The term consequence here is right, they come as a sequence, but as a sequence of each move in the list of moves computed by the eval method which is I think you do not get from my explanation.
Not sure what you mean by "poor performance" that's the most performing implementation possible for the consequences, because they are computed only if the legal move is applied, consequently their computation is the fastest in Ludii compare to effect for example (apply ...).
Concerning "... you already complained it is too complicated for you." That's not the file is too complicated, that's just because the file you are sending is not showing only the problem you mention but a bunch of others things with it, so for a person external to the one who write it, that's not possible in a short term to find what you mean and we can not look many hours each file just to find an hypothetical problem. We do our best to help each user, but the user also has to help us to be helped ;)

That one :  (and { (<A>) (<B>) (<C>) } (then (<D>)))
And (and { (<A>) (<B>) (<C>) (<D>) } )

Are not equivalent. And differently according to the fact they are in a (then ...) or not.
So if they are not, for the first one you got the legal moves corresponding to A B C, then for each of the legal moves you have the consequence D. And for the second one you have the legal moves corresponding to A B C D
If they are in a (then ....), for the first one, you are computing the legal moves of A B C, then for each of them when applied the computation of D is done, and their moves (according to the moves applied by A B C) will be applied. For the second one, you just apply all the moves of A B C D.

For (and { (<A> (then (<D>))) (<B> (then (<D>))) (<C> (then (<D>))) } )

If you are not in a (then ...), you compute A then D, B then D, C then D as legal moves.
IF you are in a (then ...) you apply the moves of A, then compute D according to A applied on the state to apply it. AND you apply B and compute D according to B applied to the state to apply it, AND finally you apply C then compute D according to C applied to the state and apply it.

For the last question, not 100% sure what you mean, but I guess you mean to use variable like (site) (to) (from) ect....? if that's right, the answer is yes, because they are possible to be used only inside a ludeme, these ones are more considering as iterators rather then variables.
If you are speaking of the variables like (var ....) or (remember ...) ect.... These ones depends if the moves is applied and the moves computed after it. As a general advice, that's better to use them in different states.

Regards,
Eric


RE: Oomph - Ludii making actions out of sequence - dale walton - 03-15-2021

It will take me a while to digest exactly what you explained.


RE: Oomph - Ludii making actions out of sequence - emmausa0106 - 04-01-2024

I am really impressed with your article. The information you share will be an important document for me to learn more about this topic.
slope