Advertisement
mruno

Basic Pathfinding

May 12th, 2022 (edited)
1,650
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
mIRC 1.68 KB | None | 0 0
  1. alias Epirate.FindPath.Estimate {
  2.   ;$Epirate.FindPath.Estimate(start,destination,N) - returns the estimated (straight line) moves it will take to get to goal/destination
  3.   ;if N is 1, returns cells to move and saves epirate.findpath q
  4.   ;if N is 2, returns cells to move
  5.   ;if N is 3, shows # of moves
  6.  
  7.   var %current.x $left($1,1), %current.y $right($1,-1), %d.x $left($2,1), %d.y $right($2,-1)
  8.   var %total 0, %moves $1, %i 0
  9.  
  10.   if ($3 == 1) hdel epirate.pathfind q
  11.  
  12.   while (%i < 75) {
  13.     inc %i
  14.     if ($isodd(%i)) {
  15.       if ($alph(%current.x) < $alph(%d.x)) set %current.x $alph($calc($alph(%current.x) + 1))
  16.       elseif ($alph(%current.x) > $alph(%d.x)) set %current.x $alph($calc($alph(%current.x) - 1))
  17.       inc %total
  18.     }
  19.     else {
  20.       if (%current.y < %d.y) set %current.y $calc(%current.y + 1)
  21.       elseif (%current.y > %d.y) set %current.y $calc(%current.y - 1)
  22.       inc %total
  23.     }
  24.     set %current.x $upper(%current.x)
  25.     set %current.y $upper(%current.y)
  26.     set %moves $addtok(%moves,%current.x $+ %current.y,44)
  27.  
  28.     if (%current.x == %d.x) && (%current.y == %d.y) {
  29.       set %total $gettok(%moves,0,44)
  30.  
  31.       if ($3) {
  32.         if ($3 == 1) {
  33.           if (!$hget(epirate.pathfind)) hmake epirate.pathfind
  34.           hadd epirate.pathfind q $addtok($hget(epirate.pathfind,q),%moves,44)
  35.           return %moves
  36.         }
  37.         elseif ($3 == 2) return %moves
  38.       }
  39.       return %total
  40.  
  41.       break
  42.     }
  43.   }
  44. }
  45. alias alph {
  46.   var %i $lower($1)
  47.   if (%i < 1) return
  48.   elseif (%i isalpha) return $calc($asc(%i) - 96)
  49.   elseif ($1 isnum) return $chr($calc($1 + 96))
  50.   else return
  51. }
  52. alias isodd return $iif(!$iseven($1-),$true,$false)
  53.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement