• 🏆 Texturing Contest #33 is OPEN! Contestants must re-texture a SD unit model found in-game (Warcraft 3 Classic), recreating the unit into a peaceful NPC version. 🔗Click here to enter!
  • 🏆 Hive's 6th HD Modeling Contest: Mechanical is now open! Design and model a mechanical creature, mechanized animal, a futuristic robotic being, or anything else your imagination can tinker with! 📅 Submissions close on June 30, 2024. Don't miss this opportunity to let your creativity shine! Enter now and show us your mechanical masterpiece! 🔗 Click here to enter!

[JASS] Pathing Algorithm improvement help

Status
Not open for further replies.
Level 31
Joined
Jul 10, 2007
Messages
6,306
Run the map in wc3 (do not open) and then build a tower in upper right corner. You'll see footmen created like 2x a second, which is the pathing algorithm searching for a path. This is the best way to see how the algorithm currently works.

I want to know if there is any way I can improve this. If you watch it, you'll see it branch out until it finds the path.

I'm essentially using a more optimal version of this algorithm
http://en.wikipedia.org/wiki/Pathfinding#Sample_algorithm

If you notice, only 1 footman is created at each 32x32 cell.

32x32 is the minimum size this can be for path finding.


My problem is that it is lagging =(. I want to know if there is a way to improve the speed of this.

Thank you all =)

JASS:
        static method isBlocked takes integer x, integer y, integer x2, integer y2, integer pt returns boolean
            local integer c=0           //instance count of local lists
            local integer array n       //list next
            local integer array p       //list previous
            local integer array lx      //point x
            local integer array ly      //point y
            local integer array dx      //direction x
            local integer array dy      //direction y
            local thistype k=0          //current list
            local thistype m=0          //new list
            local hashtable ht          //local hashtable for seeing if a coordinate was hit
            local integer o             //open paths
            local boolean f=false       //initially found path already?
            
            //have to work in a 32x32 grid, so format the coordinates
            set x=(x+32)/32*32
            set y=(y+32)/32*32
            set x2=(x2+32)/32*32
            set y2=(y2+32)/32*32
            
            //if the start and end points are pathable, continue
            if (IsPathable(x,y,pt) and IsPathable(x2,y2,pt)) then
                set ht=InitHashtable()
                call SaveBoolean(ht,x,y,true)               //mark start point as hit
                //create first 4 path nodes branching out in 4 directions like a cross
                //from start point
                //! runtextmacro INI_PATH_NODE("32","0")
                //! runtextmacro INI_PATH_NODE("-32","0")
                //! runtextmacro INI_PATH_NODE("0","32")
                //! runtextmacro INI_PATH_NODE("0","-32")
                //if none of the path nodes were the end point, then continue
                if (not f) then
                    //if none of the path nodes were valid, end
                    set k=n[0]
                    if (0==k) then
                        call FlushParentHashtable(ht)
                        set ht=null
                        return true
                    endif
                    //loop through each open path node and branch them out
                    loop
                        //reset the open paths. If this hits 0, path ended up being
                        //a dead end
                        set o=4
                        //branch out
                        //! runtextmacro ALLOCATE_PATH_NODE_2("0","32")
                        //! runtextmacro ALLOCATE_PATH_NODE_2("0","-32")
                        //! runtextmacro ALLOCATE_PATH_NODE_2("32","0")
                        //! runtextmacro ALLOCATE_PATH_NODE_2("-32","0")
                        //dead end
                        if (0==o) then
                            set n[p[k]]=n[k]
                            set p[n[k]]=p[k]
                        endif
                        set k=n[k]
                        //if k is at 0, then it's at the head
                        if (0==k) then
                            set k=n[k]
                            
                            //if thee are no more lists, return blocked
                            if (0==k) then
                                call FlushParentHashtable(ht)
                                set ht=null
                                return true
                            endif
                            
                            //flip pathing
                            //goes between going straight and branching
                            set f=not f
                        endif
                    endloop
                endif
                call FlushParentHashtable(ht)
                set ht=null
                
                //not blocked if at this point
                return false
            endif
            
            //blocked if at this point
            return true
        endmethod

    //this is for initializing the first branching nodes
    //! textmacro INI_PATH_NODE takes DX,DY
        //if no branch nodes have hit the end
        //and the branch point is pathable
        if not f and IsPathable(x+$DX$,y+$DY$,pt) then
            //mark as hit
            call SaveBoolean(ht,x+$DX$,y+$DY$,true)
            
            //allocate
            set k=c+1
            set c=k
            
            //store point
            set lx[k]=x+$DX$
            set ly[k]=y+$DY$
            
            //add to branch list
            set p[n[0]]=k
            set n[k]=n[0]
            set n[0]=k
            
            //store direction*
            set dx[k]=$DX$
            set dy[k]=$DY$
            
            //if the branch point was the goal, mark as goal
            if lx[k]==x2 and ly[k]==y2 then
                set m=k             //store k to m
                set f=true          //mark (ini nodes only)
            endif
        endif
    //! endtextmacro
    //! textmacro ALLOCATE_PATH_NODE_2 takes DX,DY
        //if the branched point was hit or the point wasn't pathable, mark as dead end
        if (HaveSavedBoolean(ht,lx[k]+$DX$,ly[k]+$DY$) or not IsPathable(lx[k]+$DX$,ly[k]+$DY$,pt)) then
            set o=o-1       //dead end counter
        else
            //if a branch (not in same direction as current node)
            if ($DX$!=dx[k] or $DY$!=dy[k]) then
                //only branch if the branching flag is marked true
                //this is to give priority to straight paths so that
                //the shortest path doesn't end up being a spiraling mess
                if (f) then
                    //mark branch point as hit
                    call SaveBoolean(ht,lx[k]+$DX$,ly[k]+$DY$,true)
                    
                    //allocate
                    set m=c+1
                    set c=m
                    
                    //add to branch list
                    set p[n[0]]=m
                    set n[m]=n[0]
                    set n[0]=m
                    
                    //store direction
                    set dx[m]=$DX$
                    set dy[m]=$DY$
                    
                    //store coordinate
                    set lx[m]=lx[k]+$DX$
                    set ly[m]=ly[k]+$DY$
                    
                    //if this node hit the goal, exit loop
                    exitwhen lx[m]==x2 and ly[m]==y2
                endif
            //else if the path was straight, enter if flagged for straight paths
            elseif (not f) then
                //mark point as hit
                call SaveBoolean(ht,lx[k]+$DX$,ly[k]+$DY$,true)
                
                //move the node forward
                set lx[k]=lx[k]+$DX$
                set ly[k]=ly[k]+$DY$
                
                //if the node hit the goal, exit loop
                exitwhen lx[k]==x2 and ly[k]==y2
            endif
        endif
    //! endtextmacro
endlibrary

edit
Here's a look at the pathing algorithm I'm attempting =)

A* ^)^
Code:
82	S	74	80	94	108

76	68	68	B	88	102

76	68	68	B	88	102

76	68	68	B	88	B

82	68	B	B	88	B

88	B	B	B	88	108

B	B	00	G	100	114

-----------------------------------------

82	S	*	*	94	108

76	68	68	B	*	102

76	68	68	B	*	102

76	68	68	B	*	B

82	68	B	B	*	B

88	B	B	B	*	108

B	B	00	G	00	104

Code:
82	S	74	80	00	00

76	68	68	74	00	00

76	68	68	74	00	00

76	68	68	74	00	00

82	68	68	74	00	00

88	74	68	74	00	00

00	80	74	G	00	00

-----------------------------------------

82	S	74	80	00	00

76	68	*	74	00	00

76	68	*	74	00	00

76	68	*	74	00	00

82	68	*	74	00	00

88	74	*	74	00	00

00	80	74	G	00	00


The first table in action
Code:
The start node's total movement cost to goal is estimated and it is added to binary heap

The min cost is set to 68
*	68	*	*	*	*

*	*	*	B	*	*

*	*	*	B	*	*

*	*	*	B	*	B

*	*	B	B	*	B

*	B	B	B	*	*

B	B	*	G	*	*

-----------------------------------------
The first node branches out. 5 new nodes are added
and the first node is removed from the binary heap.
82	X	74	*	*	*

76	68	68	B	*	*

*	*	*	B	*	*

*	*	*	B	*	B

*	*	B	B	*	B

*	B	B	B	*	*

B	B	*	G	*	*

-----------------------------------------
All nodes that match the min cost branch out and
are removed
82	X	74	80	*	*

76	X	X	B	*	*

76	68	68	B	*	*

*	*	*	B	*	B

*	*	B	B	*	B

*	B	B	B	*	*

B	B	*	G	*	*

-----------------------------------------
82	X	74	80	*	*

76	X	X	B	*	*

76	X	X	B	*	*

76	68	68	B	*	B

*	*	B	B	*	B

*	B	B	B	*	*

B	B	*	G	*	*

-----------------------------------------
82	X	74	80	*	*

76	X	X	B	*	*

76	X	X	B	*	*

76	X	X	B	*	B

82	68	B	B	*	B

88	B	B	B	*	*

B	B	*	G	*	*

-----------------------------------------
82	X	74	80	*	*

76	X	X	B	*	*

76	X	X	B	*	*

76	X	X	B	*	B

82	X	B	B	*	B

88	B	B	B	*	*

B	B	*	G	*	*

-----------------------------------------
In this case, a new min cost is found, which is 74
All nodes that match the min cost branch out
and are removed.
82	X	X	80	*	*

76	X	X	B	*	*

76	X	X	B	*	*

76	X	X	B	*	B

82	X	B	B	*	B

88	B	B	B	*	*

B	B	*	G	*	*

-----------------------------------------
82	X	X	80	*	*

X	X	X	B	*	*

X	X	X	B	*	*

76	X	X	B	*	B

82	X	B	B	*	B

88	B	B	B	*	*

B	B	*	G	*	*

-----------------------------------------
82	X	X	80	*	*

X	X	X	B	*	*

X	X	X	B	*	*

X	X	X	B	*	B

82	X	B	B	*	B

88	B	B	B	*	*

B	B	*	G	*	*

-----------------------------------------
82	X	X	X	94	*

X	X	X	B	88	*

X	X	X	B	*	*

X	X	X	B	*	B

82	X	B	B	*	B

88	B	B	B	*	*

B	B	*	G	*	*

-----------------------------------------
X	X	X	X	94	*

X	X	X	B	88	*

X	X	X	B	*	*

X	X	X	B	*	B

X	X	B	B	*	B

88	B	B	B	*	*

B	B	*	G	*	*

-----------------------------------------
X	X	X	X	94	108

X	X	X	B	X	102

X	X	X	B	88	102

X	X	X	B	*	B

X	X	B	B	*	B

X	B	B	B	*	*

B	B	*	G	*	*

-----------------------------------------
X	X	X	X	94	108

X	X	X	B	X	102

X	X	X	B	X	102

X	X	X	B	88	B

X	X	B	B	*	B

X	B	B	B	*	*

B	B	*	G	*	*

-----------------------------------------
X	X	X	X	94	108

X	X	X	B	X	102

X	X	X	B	X	102

X	X	X	B	X	B

X	X	B	B	88	B

X	B	B	B	*	*

B	B	*	G	*	*

-----------------------------------------
X	X	X	X	94	108

X	X	X	B	X	102

X	X	X	B	X	102

X	X	X	B	X	B

X	X	B	B	X	B

X	B	B	B	88	108

B	B	*	G	*	*

-----------------------------------------
X	X	X	X	94	108

X	X	X	B	X	102

X	X	X	B	X	102

X	X	X	B	X	B

X	X	B	B	X	B

X	B	B	B	X	108

B	B	*	G	100	114

-----------------------------------------
X	S	O	O	94	108

X	X	X	B	O	102

X	X	X	B	O	102

X	X	X	B	O	B

X	X	B	B	O	B

X	B	B	B	O	108

B	B	*	G	100	114

-----------------------------------------


The above tables use a movement cost of 10 and a diag movement cost of 14.

In the actual algorithm, a movement cost of 5 and diagonal cost of 7 will be used.

The maximum movement cost across the biggest possible map is 28672


edit
Code:
Nothing
*	S	*	*	*	*

*	*	*	B	*	*

*	*	*	B	*	*

*	*	*	B	*	B

*	*	B	B	*	B

*	B	B	B	*	*

B	B	*	G	*	*
First calculate initial point
-----------------------------------------

*	68	*	*	*	*

*	*	68	B	*	*

*	*	*	B68	*	*

*	*	*	B68	*	B

*	*	B	B68	*	B

*	B	B	B68	*	*

B	B	*	G	*	*
Loop through lowest queue and branch off of each node
Remove all hit nodes
-----------------------------------------
82	68	74	*	*	*

76	68	68	B74	*	*

*	68	68	B68	*	*

*	*	68	B68	*	B

*	*	B	B68	*	B

*	B	B	B68	*	*

B	B	*	G	*	*
Loop through lowest queue and branch off of each node
Remove all hit nodes
-----------------------------------------
82	X	74	84	*	*

76	X	X	B74	*	*

76	X	X	BX	*	*

76	68	X	BX	*	B

*	68	B	BX	*	B

*	B	B	BX	*	*

B	B	*	G	*	*
Loop through lowest queue and branch off of each node
Remove all hit nodes
-----------------------------------------
82	X	74	84	*	*

76	X	X	B74	*	*

76	X	X	BX	*	*

76	X	X	BX	*	B

82	X	B	BX	*	B

88	B	B	BX	*	*

B	B	*	G	*	*
The queue is now empty, so remove queue from heap
Go to next lowest number, which is 74
Note that the second 74 is on an unpathable area, so
it will just be removed
The first one hits all dead ends (all places already hit)
-----------------------------------------
82	X	X	84	*	*

76	X	X	BX	*	*

76	X	X	BX	*	*

76	X	X	BX	*	B

82	X	B	BX	*	B

88	B	B	BX	*	*

B	B	*	G	*	*
Remove 74 from the heap and go to 76
-----------------------------------------
82	X	X	84	*	*

X	X	X	BX	*	*

X	X	X	BX	*	*

X	X	X	BX	*	B

82	X	B	BX	*	B

88	B	B	BX	*	*

B	B	*	G	*	*
Remove 76 from the heap and go to 82
-----------------------------------------
X	X	X	84	*	*

X	X	X	BX	*	*

X	X	X	BX	*	*

X	X	X	BX	*	B

X	X	B	BX	*	B

88	B	B	BX	*	*

B	B	*	G	*	*
Remove 82 from the heap and go to 84
-----------------------------------------
X	X	X	X	98	*

X	X	X	BX	92	*

X	X	X	BX	*	*

X	X	X	BX	*	B

X	X	B	BX	*	B

88	B	B	BX	*	*

B	B	*	G	*	*

-----------------------------------------
Remove 84 from the heap and go to 88
X	X	X	X	98	*

X	X	X	BX	92	*

X	X	X	BX	*	*

X	X	X	BX	*	B

X	X	B	BX	*	B

X	B	B	BX	*	*

B	B	*	G	*	*

-----------------------------------------
Remove 88 from the heap and go to 92
X	X	X	X	98	112

X	X	X	BX	X	106

X	X	X	BX	92	106

X	X	X	BX	*	B

X	X	B	BX	*	B

X	B	B	BX	*	*

B	B	*	G	*	*

-----------------------------------------
X	X	X	X	98	112

X	X	X	BX	X	106

X	X	X	BX	X	106

X	X	X	BX	92	B

X	X	B	BX	*	B

X	B	B	BX	*	*

B	B	*	G	*	*

-----------------------------------------
X	X	X	X	98	112

X	X	X	BX	X	106

X	X	X	BX	X	106

X	X	X	BX	X	B

X	X	B	BX	92	B

X	B	B	BX	*	*

B	B	*	G	*	*

-----------------------------------------
X	X	X	X	98	112

X	X	X	BX	X	106

X	X	X	BX	X	106

X	X	X	BX	X	B

X	X	B	BX	X	B

X	B	B	BX	92	112

B	B	*	G	*	*

-----------------------------------------
X	X	X	X	98	112

X	X	X	BX	X	106

X	X	X	BX	X	106

X	X	X	BX	X	B

X	X	B	BX	X	B

X	B	B	BX	X	112

B	B	*	G	104	118

-----------------------------------------
X	*	X	*	98	112

X	X	*	BX	*	106

X	X	X	BX	*	106

X	X	X	BX	*	B

X	X	B	BX	*	B

X	B	B	BX	*	112

B	B	*	G	104	118

-----------------------------------------
 

Attachments

  • Anti Block.w3x
    34.6 KB · Views: 61
Last edited:
Level 31
Joined
Jul 10, 2007
Messages
6,306
I have been banging my head against this for hours on end and still can't figure out why it's bugging up.

Download the map and run it in warcraft 3 (do not open it with WE or NewGen as you won't be able to save it).

Build a tower in the top right corner. You'll see the algorithm work perfectly. Now build a tower in the middle of the algorithm's path. It'll go all skitzer.... I have no idea what's causing it >.<.

The algorithm is A* running on a binary heap. I checked the binary heap itself and it never bugged up. The smallest value was always on the top. What I'm wondering is why some of the nodes are never worked off of.. you'll see it literally carve a square around the goal >.<.

Anyways, if anyone can help me figure this out, I'd much appreciate it.

Scattered through out the code are various debug messages and many comments.

JASS:
private static method U takes Path q, integer x, integer y, integer x2, integer y2, integer pt returns boolean
            local integer c=1       //instance count
            local integer hc=1      //heap instance count
            
            local integer k         //node
            local integer m         //node
            
            local integer array n   //next on stack
            local integer array p   //previous node on path* stack
            
            local integer array hn  //heap node
            
            local integer array px  //point x
            local integer array py  //point y
            
            local integer cx        //coordinate x
            local integer cy        //coordinate y
            local integer ax        //add x
            local integer ay        //add y
            local boolean d         //loop done
            local boolean z=false   //leave heap early
            
            local integer oq=1      //open queue
            
            //heap table (value -> node)
            local Table ht=Table.create()
            
            //F = G + H
            //
            //G = the movement cost to move from the starting point A to 
            //a given square on the grid, following the path generated to get there
            //
            //H = the estimated movement cost to move from that given square on 
            //the grid to the final destination, point B.
            local integer array f   //F-Cost
            local integer g
            local integer h
            
            local integer v         //value
            
            //used to see if a coordinate was already hit
            local hashtable nc=InitHashtable()
            
            //test
                local string s
                local integer r
            
            //first, mark start as hit
            call SaveBoolean(nc,x,y,true)
            
            //store start point into the first open queue
            set px[1]=x
            set py[1]=y
            call SetUnitScale(CreateUnit(Player(0),'hfoo',x,y,0),.5,.5,.5)
            
            loop
                //branch in all directions from current open stack
                loop
                    set d=false
                    set ax=-32
                    set ay=0
                    
                    //-32,0
                    //0,-32
                    //0,32
                    //32,0
                    loop
                        set cx=px[oq]+ax
                        set cy=py[oq]+ay
                        
                        //if the current coordinates are the goal, exit
                        exitwhen cx==x2 and cy==y2
                        
                        //if the current coordinates weren't hit and are pathable, continue
                        if (not HaveSavedBoolean(nc,cx,cy) and IsPathable(cx,cy,pt)) then
                            //mark as hit
                            call SaveBoolean(nc,cx,cy,true)
                            call SetUnitScale(CreateUnit(Player(0),'hfoo',cx,cy,0),.5,.5,.5)
                        
                            //allocate node
                            set k=c+1
                            set c=k
                            set px[k]=cx
                            set py[k]=cy
                            set p[k]=oq         //parent node of current node, where this node came from
                        
                            //retrieve path cost of current node
                            
                            //calculate g
                            set g=(cx-x)
                            set v=(cy-y)
                            set g=R2I(SquareRoot(g*g+v*v)+.5)
                            
                            //begin calculation of h
                            set h=(x2-cx)
                            set v=(y2-cy)
                            set v=R2I(SquareRoot(h*h+v*v)+.5)+g        //calculate final cost (g+h)
                            
                            //if the new node is part of the current open stack, add
                            if (v==f[hn[1]]) then
                                set n[k]=n[oq]
                                set n[oq]=k
                            else
                                set z=v<f[hn[1]]        //leave heap early?
                                
                                //retrieve cost's stack head
                                set g=ht[v]
                                
                                //if the heap node doesn't exist, create it
                                if (0==g or (0!=g and 0==n[g])) then
                                    if (0==g) then
                                        //allocate stack head
                                        set g=c+1
                                        set c=g
                                        set ht[v]=g     //store stack head into cost
                                        set f[g]=v      //store cost into stack head
                                    endif
                                
                                    //allocate heap node
                                    set m=hc+1
                                    set hc=m
                                    
                                    set h=m/2       //parent
                                    
                                    //add stack to heap
                                    loop
                                        //if the value is less than the parent's value, swap with parent
                                        exitwhen 0==h or v>f[hn[h]]
                                        set hn[m]=hn[h]         //move parent down
                                        set m=h                 //move node up
                                        set h=h/2               //go to next parent
                                    endloop
                                    set hn[m]=g                 //store the stack node into the found heap node
                                    /*
                                    //test
                                    set s=""
                                    set v=1
                                    set r=2
                                    loop
                                        set s=s+I2S(f[hn[v]])+","
                                        exitwhen v==hc
                                        set v=v+1
                                        if (v==r) then
                                            set s=s+"\n"
                                            set r=r*2
                                        endif
                                        if (f[hn[v]]<f[hn[1]]) then
                                            call DisplayTimedTextToPlayer(GetLocalPlayer(),0,0,60,"BUGGED ADD")
                                        endif
                                    endloop
                                    call DisplayTimedTextToPlayer(GetLocalPlayer(),0,0,60,"Added\n-------------------\n" + s)
                                    call TriggerSleepAction(.05)
                                    */
                                endif
                                
                                //add node to stack
                                set n[k]=n[g]
                                set n[g]=k
                            endif
                        endif
                        exitwhen d
                        if (0==ay) then
                            set ax=0
                            set ay=-32
                        elseif (0>ay) then
                            set ay=32
                        else
                            set ax=32
                            set ay=0
                            set d=true
                        endif
                    endloop
                    //loop through all nodes in the current open queue until that queue is empty
                    exitwhen z or 0==n[oq] or (cx==x2 and cy==y2)
                    set oq=n[oq]
                    call TriggerSleepAction(.05)
                endloop
                
                //if at the end, exit
                exitwhen cx==x2 and cy==y2
                
                //remove the current open heap
                set v=hn[hc]
                set hn[hc]=0
                set hc=hc-1
                
                //if the heap is completely empty, then the pathing failed
                exitwhen 0==hc
                
                //go to the open queue (will always be 1) and remove it from the heap
                set oq=1
                set n[hn[1]]=0
                loop
                    set g=oq*2      //left
                    set h=g+1       //right
                    //exitwhen at the bottom row
                    exitwhen 0==hn[h] and 0==hn[g]
                    //if the left side is smaller than right side, left is new root
                    if (0==f[hn[h]] or f[hn[g]]<f[hn[h]]) then
                        set hn[oq]=hn[g]
                        set hn[g]=0
                        set oq=g
                    //otherwise right is new root
                    else
                        set hn[oq]=hn[h]
                        set hn[h]=0
                        set oq=h
                    endif
                endloop
                set h=oq/2       //parent
                set g=f[v]
                
                //add stack to heap
                loop
                    //if the value is less than the parent's value, swap with parent
                    exitwhen 0==h or g>f[hn[h]]
                    set hn[oq]=hn[h]        //move parent down
                    set oq=h                //move node up
                    set h=h/2               //go to next parent
                endloop
                set hn[oq]=v
                /*
                //test
                set s=""
                set v=1
                set r=2
                loop
                    set s=s+I2S(f[hn[v]])+","
                    exitwhen v==hc
                    set v=v+1
                    if (v==r) then
                        set s=s+"\n"
                        set r=r*2
                    endif
                    if (f[hn[v]]<f[hn[1]]) then
                        call DisplayTimedTextToPlayer(GetLocalPlayer(),0,0,60,"BUGGED REMOVE")
                    endif
                endloop
                call DisplayTimedTextToPlayer(GetLocalPlayer(),0,0,60,"Removed\n-------------------\n" + s)
                call TriggerSleepAction(.05)
                */
                //go to queue with lowest cost
                set oq=n[hn[1]]
            endloop
            
            //clean
            call FlushParentHashtable(nc)
            set nc=null
            call ht.destroy()
            
            call DisplayTimedTextToPlayer(GetLocalPlayer(),0,0,60,"Done")
            
            //if a path was found, generate it
            /*
            if (cx==x2 and cy==y2) then
                call SetUnitScale(CreateUnit(Player(0),'hfoo',cx,cy,0),.5,.5,.5)
                loop
                    exitwhen 0==oq
                    call SetUnitScale(CreateUnit(Player(0),'hfoo',px[oq],py[oq],0),.5,.5,.5)
                    call TriggerSleepAction(.05)
                    set oq=p[oq]
                endloop
            endif
            */
            return false
        endmethod
 

Attachments

  • Anti Block.w3x
    42.4 KB · Views: 58
Level 14
Joined
Jan 5, 2009
Messages
1,127
I see what you mean by it going crazy.

I'm no expert at vJass or Jass but I will try to help.

Well, from testing the map, even though I havent fully read the code properly, it seems to save some points. I started off with starting construction of the tower in the middle, didn't finish it though. Canceled it. Then Built the tower in the corner.
 
In your first post:
JASS:
            set x=(x+32)/32*32
            set y=(y+32)/32*32
            set x2=(x2+32)/32*32
            set y2=(y2+32)/32*32

We all know Jass math is slow, so why don't you do this:

JASS:
            set x=(x+32)/1024
            set y=(y+32)/1024
            set x2=(x2+32)/1024
            set y2=(y2+32)/1024

In your second post:

local hashtable nc=InitHashtable()

Initializing a hashtable ingame is a huge no-no
Try using a global hashtable, or better yet, the Table library.
 
Mag, you forget how programming math is parsed?

He's basically using the modulo function.

He also needs a full hashtable for this due to the huge
lookups on the x, y coordinates. He might be able to
get away with a TableArray of size 20,000 or so, but
then you have to consider he flushes the data when it's
done, so that would really lose efficiency (4 trigger
evaluations to flush all 20,000 child hashtables).
 
Mag, you forget how programming math is parsed?

He's basically using the modulo function.

RIGHT! I keep forgetting that :p
I thought "priority rules" would apply here :/

Here's another thing:
Save Player(0) in a local player variable

Oh and:

JASS:
set g=(cx-x)
                            set v=(cy-y)
                            set g=R2I(SquareRoot(g*g+v*v)+.5)
                            
                            //begin calculation of h
                            set h=(x2-cx)
                            set v=(y2-cy)
                            set v=R2I(SquareRoot(h*h+v*v)+.5)+g        //calculate final cost (g+h)

Removing those SquareRoots should be of a high priority inorder to increase efficiency.
I don't know if it's possible in this case, but if it is, then do it :p
 
Status
Not open for further replies.
Top