I was making a pathfinding thing for a game I was prototyping and noticed that it had less rules, was more accurate in always finding a shortest path, and (because all the rules are late) always updates to target the most recent player location, as best as I can tell. So I'm posting it here for others to see, in case they want to consider using it.
title Enemy Pathfinding Improved
author Brick
homepage
www.puzzlescript.netverbose_logging
(run_rules_on_level_start)
(A fixed pathfinding that uses less rules. Replace 'Wall' with 'Obstacle' in the rules to make the rats pathfind around each other. Mix up the lines in the first loop to change the directional preferences of the pathmap)
========
OBJECTS
========
Background
#201810
Wall
#231 #332 #303820
00210
12000
00012
02100
21002
Player
black orange white blue
.000.
.111.
22222
.333.
.3.3.
Rat
gray pink black brown
.....
...33
....3
.0003
10202
Q
transparent
SmartPathUp
lightblue
..0..
..0..
..0..
.....
.....
SmartPathRight
lightblue
.....
.....
..000
.....
.....
SmartPathDown
lightblue
.....
.....
..0..
..0..
..0..
SmartPathLeft
lightblue
.....
.....
000..
.....
.....
SmartGrow
lightblue
.....
..0..
.000.
..0..
.....
X
transparent
=======
LEGEND
=======
Obstacle = Wall or Rat
SmartPath = SmartPathUp or SmartPathRight or SmartPathDown or SmartPathLeft
. = Background
# = Wall
@ = Player
R = Rat
=======
SOUNDS
=======
sfx0 67117309
sfx1 19502303
================
COLLISIONLAYERS
================
Background
Q
SmartPath
SmartGrow
X
Player, Wall, Rat
======
RULES
======
[> Player | Rat] -> [Rat | Player]
[smartpath] -> []
[Rat no Q] -> [Rat Q]
startloop (Wow, I finally found a way to really use this! And successfully!)
late [Player no SmartGrow no smartpath no X] -> [Player SmartGrow X]
late down [no X no Wall no smartpath| SmartGrow] -> [SmartPathDown | SmartGrow X]
late up [no X no Wall no smartpath| SmartGrow] -> [SmartPathUp | SmartGrow X]
late right [no X no Wall no smartpath| SmartGrow] -> [SmartPathRight | SmartGrow X]
late left [no X no Wall no smartpath| SmartGrow] -> [SmartPathLeft | SmartGrow X]
late [smartpath] -> [smartpath SmartGrow X]
endloop
late [SmartGrow] -> []
late [X] -> []
startloop
late up [Rat SmartPathUp Q | no Obstacle no Player] -> [SmartPathUp | Rat]
late right [Rat SmartPathRight Q | no Obstacle no Player] -> [SmartPathRight | Rat]
late down [Rat SmartPathDown Q | no Obstacle no Player] -> [SmartPathDown | Rat]
late left [Rat SmartPathLeft Q | no Obstacle no Player] -> [SmartPathLeft | Rat]
endloop
late [Q] -> []
==============
WINCONDITIONS
==============
(There's no way to win against a floating eyeball :S )
=======
LEVELS
=======
#######################
#.....................#
#.....................#
#.....................#
#.....................#
#.....................#
#.......R#.#R.........#
#.........@...........#
#........#.#R.........#
#.......R.............#
#.....................#
#.....................#
#.....................#
#.....................#
#.....................#
#######################
#########
#.....R.#
#.......#
#.@.#...#
#.......#
#.....###
#.#####R#
#.#...#.#
#.R.#.#.#
#####.#.#
#...#.#.#
#.#...#.#
#.#####.#
#.......#
#########