i'm trying to make a pathfindin script ... useing A* method .. but i must have mess it up somewhere .. so i need help ...

basicly i don't need the hole path .. just the next noddle ... assuming i got the map, starting point and target point ...

Code:
alias setcurrent {
  set %i 1 
  set %min 1
  while %i <= %olistitems {
    if $calc(%olist.g [ $+ [ %min ] ] + %olist.h [ $+ [ %min ] ]) > $calc(%olist.h [ $+ [ %i ] ] + %olist.g [ $+ [ %i ] ]) { set %min %i }
    inc %i
  }
  set %current.x %olist.x [ $+ [ %min ] ]
  set %current.y %olist.y [ $+ [ %min ] ]
  set %current.g %olist.g [ $+ [ %min ] ]
  set %current.h %olist.h [ $+ [ %min ] ]
  set %olist.x [ $+ [ %min ] ] %olist.x [ $+ [ %olistitems ] ]
  set %olist.y [ $+ [ %min ] ] %olist.y [ $+ [ %olistitems ] ]
  set %olist.g [ $+ [ %min ] ] %olist.g [ $+ [ %olistitems ] ]
  set %olist.h [ $+ [ %min ] ] %olist.h [ $+ [ %olistitems ] ]
  dec %olistitems
}

alias clistadd {
  inc %clistitems
  set %clist.x [ $+ [ %clistitems ] ] $1
  set %clist.y [ $+ [ %clistitems ] ] $2
  set %clist.g [ $+ [ %clistitems ] ] $3
  set %clist.h [ $+ [ %clistitems ] ] $calc($abs(%current.x - %d.x) + $abs(%current.y - %d.y))
  set %clist.px [ $+ [ %clistitems ] ] $4
  set %clist.py [ $+ [ %clistitems ] ] $5
  return 1
}

alias clistexists {
  set %i 1
  while %i <= %clistitems {
    if (%clist.x [ $+ [ %i ] ] == $1 && %clist.y [ $+ [ %i ] ] == $2) { return 1 }
    inc %i
  }
  return 0
}

alias olistexists {
  set %i 1
  while %i <= %olistitems {
    if (%olist.x [ $+ [ %i ] ] == $1 && %olist.y [ $+ [ %i ] ] == $2) { return 1 }
    inc %i
  }
  return 0
}

alias olistadd {
  inc %olistitems
  set %olist.x [ $+ [ %olistitems ] ] $1
  set %olist.y [ $+ [ %olistitems ] ] $2
  set %olist.g [ $+ [ %olistitems ] ] $3
  set %olist.h [ $+ [ %olistitems ] ] $calc($abs(%current.x - %d.x) + $abs(%current.y - %d.y))
  set %olist.px [ $+ [ %olistitems ] ] $4
  set %olist.py [ $+ [ %olistitems ] ] $5
  return 1
}

;**************************************************************************************
alias findpath {
  set %olistitems 0 | set %clistitems 0
  set %start.x $1 | set %start.y $2
  .echo -a $olistadd($1,$2,0,$1,$2)
  set %current.x $1 | set %current.y $2
  while (%current.x != %d.x && %current.y != %d.y) {
    setcurrent ;;removes from open list :)
    .echo -a $clistadd(%current.x,%current.y,%current.g,%current.px,%current.py)
    set %a -1 | 
    while %a <= 1 {
      set %b -2
      while %b <= 0 {
        inc %b
        if (%a == 0 && %b == 0) { continue }
        if (%a != 0 && %b != 0) { continue }
        if $clistexists($calc(%current.x + %a),$calc(%current.y + %b)) == 1 { continue }
        if (%diggermap [ $+ [ $calc(%current.x + %a) ] ] [ $+ [ $calc(%current.y + %b) ] ] == enemy || %diggermap [ $+ [ $calc(%current.x + %a) ] ] [ $+ [ $calc(%current.y + %b) ] ] == empty || %diggermap [ $+ [ $calc(%current.x + %a) ] ] [ $+ [ $calc(%current.y + %b) ] ] == digger) { 
          ;*****************************************************************************************************************************************
          if ($olistexists($calc(%current.x + %a),$calc(%current.y + %b)) == 0) { .echo -a $olistadd($calc(%current.x + %a),$calc(%current.y + %b),$calc(%current.g + 10),%current.x,%current.y) }
                    ;*****************************************************************************************************************************************
        }
      }
      inc %a
    }
if ($calc(%current.x + %a) == %d.x && $calc(%current.y + %b) == %d.y) { return 1 }
          if %olistitems == 0 { return 0 }
  }
}



%diggermap [] [] is the 2D map ... %d.x/%d.y is the finishing point ... and the findpath function takes 2 parameter -> the start point smile


plz ...help smile))))))))))

Last edited by SteeleR; 15/07/05 01:30 PM.

HanPeg HanPeg u BuHaru HanPeg nPu noPa}|{eHue kParoM u nAk HanPeg