PuzzleScript icon indicating copy to clipboard operation
PuzzleScript copied to clipboard

match caching

Open rmmh opened this issue 11 years ago • 0 comments

Sometimes you want random events biased by certain probabilities. You can repeat rules to achieve this: http://www.puzzlescript.net/editor.html?hack=11219921

random [stationary SlimeBlue Moving PFound] -> [Moving SlimeBlue Moving PFound]
+      [stationary SlimeBlue Moving PFound] -> [Moving SlimeBlue Moving PFound]
+      [stationary SlimeBlue Moving PFound] -> [Moving SlimeBlue Moving PFound]
+      [stationary SlimeBlue Moving PFound] -> [Moving SlimeBlue Moving PFound]
+      [stationary SlimeBlue Moving PFound] -> [Moving SlimeBlue Moving PFound]
+      [stationary SlimeBlue Moving PFound] -> [randomdir SlimeBlue Moving PFound]

but it's inefficient since the identical pattern on the left is matched 6 times, when the first search provides enough information. many games have similar cases where an identical pattern appears multiple times in rules that aren't executed

caching matchCellRow* results and invalidating it on a new tick or when applyAt runs would avoid a lot of the redundancies

rmmh avatar Apr 23 '14 15:04 rmmh