A question about the infinite loop teleportation example in the documentation

58 views
Skip to first unread message

Ilija

unread,
Nov 14, 2016, 4:21:05 PM11/14/16
to PuzzleScript


Hi yall, I'm trying to figure out a few things which are bugging me.

In the first page of the documentation stands this text: 







What exactly makes the second code not loop infinitely? I mean, the player position and the sprite are still perpendicular and thus valid for another swap, and yet the code runs as it should this way. And the fact that "the rules are run as much as it's possible" is more confusing. I'm guessing it has something to do with the number of rules, but someone more experienced can elaborate on how exactly are the rules executed.

Thanks. 

Alan Hazelden

unread,
Nov 14, 2016, 4:44:33 PM11/14/16
to Ilija, PuzzleScript
It runs through the rules one-by-one, executing each rule as many times as possible.

So "late [ Sprite | ... | Player ] -> [ Temp | ... | Sprite ]" runs as many times as possible, which is once. Then "late [ Temp ] -> [ Player ]" runs as many times as possible, which is once.

--
You received this message because you are subscribed to the Google Groups "PuzzleScript" group.
To unsubscribe from this group and stop receiving emails from it, send an email to puzzlescript+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Stephen Lavelle

unread,
Nov 14, 2016, 5:34:54 PM11/14/16
to Ilija, PuzzleScript
Have you tried running it with verbose_logging on (see http://www.puzzlescript.net/Documentation/prelude.html )? That may tell you your answer.

The first rule

late [ sprite | ... | player ] -> [ player | ... | sprite]

is broken down by the compiler into a group of four rules, for each direction - let's look at two of them

left [ sprite | ... | player ] -> [ player | ... | sprite]
left [ player | ... | sprite ] -> [ sprite | ... | player]

if the first rule is applied, the second will be applied to swap the sprite and the player back - so the rule group has no effect, but it (and I could perhaps make the engine smarter so it doesn't do this) has noted that one of its rules did something, so it tries to apply it again. 

Rule groups as a whole are applied until none of the subrules can be applied.  However, if two subrules cancel eachother out, it gets stuck in a loop.

Does that clarify things at all?  http://www.puzzlescript.net/documentation/executionorder.html goes into more detail.

--

Ilija

unread,
Nov 14, 2016, 6:20:45 PM11/14/16
to PuzzleScript
Okay, that verbose_logging thing helped a lot. I think I got it, thanks!
Reply all
Reply to author
Forward
0 new messages