REVO2700 A* Maya-Ball 3 1 --http://www.policyalmanac.org/games/aStarTutorial.htm local forbidden, theOpen, theTarget, theData on mouseUp --change these values for a different gridsize (only interesting for forbidden & unhilite) put 20 into maxX put 20 into maxY if word 1 of the target is "button" then put the short name of the Target into theTarget put word 2 of theTarget into theTarget if not item 1 of theTarget is a number or not item 2 of theTarget is a number then pass mouseUp end if else pass mouseUp end if --cleanup put "" into forbidden put "" into theOpen put "" into theData --make list of allowed/not allowed squares repeat with x = 0 to maxX + 1 repeat with y = 0 to maxX + 1 if there is no button ("grid" && x,y) then put true into forbidden[x,y] else if the label of button ("grid" && x,y) = "not allowed" then put true into forbidden[x,y] unhilite button ("grid" && x,y) else --gui cleanup unhilite button ("grid" && x,y) end if end repeat end repeat --add square 1 to open list put item 1 of the beginning of this stack into theX put item 2 of the beginning of this stack into theY put abs(item 1 of theTarget - theX) + abs(item 2 of theTarget - theY) into targetDist --this is "H" --put "a",theX,theY,theX,theY,0,targetDist,targetDist into theOpen put theX,theY,targetDist into theOpen put theX,theY,0,targetDist,targetDist into theData[theX,theY] --timing info put the milliseconds into theTime --start searching from square 1... -- call function which calls itself put findPath(the beginning of this stack) into theError --error var --backstep trough the list to find the path put theTarget into theCurrent if theError then beep else repeat until theCurrent = the beginning of this stack add one to counter put item 1 to 2 of theData[theCurrent] into theCurrent put theCurrent & return before theList end repeat end if --timing info put the milliseconds - theTime repeat for each line theLine in char 1 to -2 of theList hilite button ("grid" && theLine) end repeat hilite button ("grid" && theTarget) end mouseUp private function findPath theCurrent --find adjectant squares put item 1 of theCurrent into x put item 2 of theCurrent into y --parts in a handler, because of simpler to code, might slow it down? put x,y,theData[x,y] into currentValues addTile x-1,y-1, currentValues addTile x-1,y, currentValues addTile x-1,y+1, currentValues addTile x,y-1, currentValues addTile x,y+1, currentValues addTile x+1,y-1, currentValues addTile x+1,y, currentValues addTile x+1,y+1, currentValues --yay, finished! if x,y = theTarget then return "" end if --put square 1 into close list put true into forbidden[x,y] --remove current square from open list delete line lineOffset(theCurrent, theOpen) of theOpen --if theOpen is depleted, then there is no route to the target if the number of words in theOpen <= 0 then return true --notify parent handler of problem end if -- first find lowest square sort theOpen numeric by item 3 of each put line 1 of theOpen into theNext --uncomment this if things are buggy (slowly shows buildup of path) --debugShow item 1 to 2 of theNext --start again from the lowest square -- more steps to take, function calls itself return findPath(theNext) end findPath private on addTile theX, theY, theParentValues --set the scores of the found squares (G,H,H+G=F), and set the parent of them to the prev square put item 5 of theParentValues + 1 into startDist --this is "G" if not forbidden[theX,theY] then put theData[theX,theY] into theCurr if theCurr <> "" then put item 5 of theCurr into prevStartDist --make sure to only overwrite squares if the new distance from the start square (G) is lower if prevStartDist < startDist then --modify existing entry put item 1 to 2 of theParentValues into theParent put abs(item 1 of theTarget -theX) + abs(item 2 of theTarget -theY) into targetDist --this is "H" put theX,theY,startDist+targetDist into line lineoffset((theX,theY),theOpen) of theOpen put theParent, startDist, targetDist, startDist+targetDist into theData[theX,theY] end if exit addTile end if put item 1 to 2 of theParentValues into theParent put abs(item 1 of theTarget -theX) + abs(item 2 of theTarget -theY) into targetDist --this is "H" --watch out "theParent" is a coordinate, and therefore 2 items! put return & theX,theY,startDist+targetDist after theOpen put theParent, startDist, targetDist, startDist+targetDist into theData[theX,theY] end if end addTile on debugShow theCurrent repeat with x = 0 to 10 repeat with y = 0 to 10 if there is a button ("grid" && x,y)then unhilite button ("grid" && x,y) end if end repeat end repeat repeat until theCurrent = the beginning of this stack put item 1 to 2 of theData[theCurrent] into theCurrent put theCurrent & return before theList end repeat repeat for each line theLine in char 1 to -2 of theList hilite button ("grid" && theLine) end repeat hilite button ("grid" && theTarget) --unlock screen sort theOpen by item 2 of each sort theOpen by item 1 of each put theOpen into theList put theList --put theData[8,1] wait 0.3 seconds end debugShow e beginning 9,1 U Lucida Grande U Lucida Grande W Lucida Grande cREVGeneral scriptChecksum ;F<{-#ۊ debugObjects handlerList mouseUp theCheckbreakpoints scriptSelection char 2856 to 2866breakpointstates bookmarks breakpointconditions scripteditorvscroll 1467scripteditorselection 2986prevHandler mouseUptempScript stackfileversion 2.7script )
global theSource --populated by mouseup of the troop button
local theParents, theG, theH, theF --arrays
local theAllowed, theDisallowed --lists
local theParent --single lines
on mouseUp
lock screen
put the short name of the target into theName
put word two of theName into theNumber
if word 1 of theName = "grid" and item one of theNumber is a number and item two of theNumber is a number then
put theSource & return into theAllowed
put theSource into theParent
put "" into theParents
put "" into theG
put 0 into theG[theParent]
put "" into theH
put 10000 into theF[theSource]
put "" into theDisallowed
put 0 into theOldGCost
repeat forever
put 10001 into x
repeat for each line theLine in theAllowed
if theF[theLine] < x then
put theF[theLine] into x
put theLine into theParent
end if
end repeat
--put theParent
put theParent & return after theDisallowed
delete line lineoffset(theParent, theAllowed) of theAllowed
put word 2 of theParent into theNumbers
put ("grid" && item one of theNumbers - 1, item two of theNumbers - 1) into theField
theCheck theField, 14, theNumber
put ("grid" && item one of theNumbers, item two of theNumbers - 1) into theField
theCheck theField, 10, theNumber
put ("grid" && item one of theNumbers + 1, item two of theNumbers - 1) into theField
theCheck theField, 14, theNumber
put ("grid" && item one of theNumbers - 1, item two of theNumbers) into theField
theCheck theField, 10, theNumber
put ("grid" && item one of theNumbers + 1, item two of theNumbers) into theField
theCheck theField, 10, theNumber
put ("grid" && item one of theNumbers - 1, item two of theNumbers + 1) into theField
theCheck theField, 14, theNumber
put ("grid" && item one of theNumbers, item two of theNumbers + 1) into theField
theCheck theField, 10, theNumber
put ("grid" && item one of theNumbers + 1, item two of theNumbers + 1) into theField
theCheck theField, 14, theNumber
if theName is among the lines of theDisallowed then
exit repeat
else if theAllowed = "" then
beep
exit to top
end if
end repeat
put theName into theStart
repeat 100 times
put theStart & return after thePath
put theParents[theStart] into theStart
if theStart = "" then
exit repeat
end if
end repeat
put 0 into x
repeat for the number of buttons times
add one to x
unhilite button x
end repeat
repeat for each line theLine in thePath
hilite button theLine
end repeat
end if
end mouseUp
on theCheck theField theGCost theNumber
if exists(button theField) and the label of button theField <> "not allowed" and theField is not among the lines of theDisallowed then
put theGCost + theG[theParent] into theOldGCost
if theField is not among the lines of theAllowed then
put theField & return after theAllowed
put theParent into theParents[theField]
put theOldGCost into theG[theField]
put word -1 of theField into theNumber2
put abs(item 1 of theNumber - item 1 of theNumber2) * 10 into theH[theField]
add abs(item 2 of theNumber - item 2 of theNumber2) * 10 to theH[theField]
put theH[theField] + theG[theField] into theF[theField]
else --already on the list
if theOldGCost < theG[theField] then
put theParent into theParents[theField]
put theOldGCost into theG[theField]
put theH[theField] + theG[theField] into theF[theField]
end if
end if
end if
end theCheck
cREVGeometryCache stackID 3823 @ cREVGeometryCacheIDs h1249899526234 37961249899526235 37981249899526236 37991249899526237 38001249899526238 38021249899526239 38031249899526240 38041249899526241 38061249899526242 38071249899502133 37241249899526243 38081249899502134 37251249899526244 38101249899502135 37301249899526245 38111249899502136 37351249899526246 38131249899502137 37391249899526247 38141249899502138 37441249899526248 38151249899502139 37481249899502140 37531249899526249 38171249899526250 38181249899502141 37571249899526251 38191249899502142 37611249899526252 38211249899502143 37661249899526253 38221249899502144 37701249899526254 38231249899502145 37741153007503163 13151249899502146 37771249899502147 37811249899502148 37851249899502149 37891249899502150 37931249899502151 37971249899502152 38011249899502153 38051249899502154 38091249899502155 38121249899502156 38161249899502157 38201152989597631 10041152994017507 11081249833304249 14181249899526180 37261249899526181 37271249899526182 37281249899526183 37291249899526184 37311249899526185 37321249899526186 37331249899526187 37341249899526188 37361249899526189 37371249899526190 37381249899526200 37511249899526191 37401249899526201 37521249899526202 37541249899526192 37411249899526203 37551249899526193 37421249899526204 37561249899526194 37431249899526205 37581249899526195 37451249899526206 37591249899526196 37461249899526207 37601249899526197 37471249899526208 37621249899526198 37491249899526210 37641249899526209 37631249899526199 37501249899526211 37651249899526212 37671249899526213 37681249899526214 37691249899526215 37711249899526216 37721249899526217 37731249899526218 37751249899526220 37781249899526219 37761249899526221 37791249899526222 37801249899526223 37821249899526224 37831249899526225 37841249899526226 37861249899526227 37871249899526228 37881249899526229 37901249899526230 37911249899526231 37921249899526232 37941249899526233 3795 cREVGeometrycache total 104order T # create grid Epon mouseUp put 64,32 into theLoc put 0 into x put 0 into y put 10 into theRectangle put "" into temp repeat for theRectangle times lock screen add one to y repeat for theRectangle times add 64 to item one of theLoc add one to x clone button "grid" set the name of it to "grid" && x,y if random(3) = 1 then set the label of it to "not allowed" end if set the loc of it to theLoc end repeat repeat theRectangle times subtract one from x subtract 64 from item one of theLoc end repeat unlock screen add 64 to item two of theLoc end repeat set the layer of button "troop" to top end mouseUp R 2 cREVGeneral scriptChecksum (RȮ&5#CۡhandlerList mouseUpscriptSelection char 398 to 397revUniqueID 1152989597631 bookmarks scripteditorvscroll 0scripteditorselection 488tempScript prevHandler mouseUpscripton mouseUp
put 30,30 into theLoc
--put theLoc & return into temp
put 0 into x
put 0 into y
put "" into temp
repeat for 10 times
add one to y
repeat for 10 times
add 60 to item one of theLoc
add one to x
clone button "grid"
set the name of it to "grid" && x,y
set the loc of it to theLoc
end repeat
repeat 10 times
subtract one from x
subtract 60 from item one of theLoc
end repeat
add 60 to item two of theLoc
end repeat
put temp
end mouseUp
T delete grid Ep%on mouseUp put the number of buttons into x lock screen repeat for the number of buttons times if word one of the short name of button x = "grid" and word 2 of the short name of button x <> "" then delete button x end if subtract one from x end repeat end mouseUp R cREVGeneral scriptChecksum gZ62/rhandlerList mouseUpscriptSelection char 258 to 257 bookmarks revUniqueID 1152994017507scripteditorvscroll 0scripteditorselection 266prevHandler mouseUptempScript scripton mouseUp
put the number of buttons into x
repeat for the number of buttons times
if word one of the short name of button x = "grid" and word 2 of the short name of button x is a number then
delete button x
end if
subtract one from x
end repeat
end mouseUp
grid g 6 @ @ T cREVGeneral revUniqueID 1249833304249 grid 1,1 g ` @ @ [ cREVGeneral revUniqueID 1249899502133 grid 2,1 %g @ @ [ not allowed cREVGeneral revUniqueID 1249899502134 grid 3,1 %g @ @ Y not allowed cREVGeneral revUniqueID 1249899526180 grid 4,1 %g @ @ Y not allowed cREVGeneral revUniqueID 1249899526181 grid 5,1 g ` @ @ _ cREVGeneral revUniqueID 1249899526182 grid 6,1 g @ @ _ cREVGeneral revUniqueID 1249899526183 grid 7,1 g @ @ ] cREVGeneral revUniqueID 1249899502135 grid 8,1 g @ @ ] cREVGeneral revUniqueID 1249899526184 grid 9,1 g ` @ @ [ cREVGeneral revUniqueID 1249899526185 grid 10,1 g @ @ [ cREVGeneral revUniqueID 1249899526186 grid 1,2 g ` @ @ @ Y cREVGeneral revUniqueID 1249899526187 grid 2,2 g @ @ @ Y cREVGeneral revUniqueID 1249899502136 grid 3,2 g @ @ @ _ cREVGeneral revUniqueID 1249899526188 grid 4,2 g @ @ @ _ cREVGeneral revUniqueID 1249899526189 grid 5,2 %g ` @ @ @ ] not allowed cREVGeneral revUniqueID 1249899526190 grid 6,2 g @ @ @ ] cREVGeneral revUniqueID 1249899502137 grid 7,2 g @ @ @ [ cREVGeneral revUniqueID 1249899526191 grid 8,2 g @ @ @ [ cREVGeneral revUniqueID 1249899526192 grid 9,2 %g ` @ @ @ Y not allowed cREVGeneral revUniqueID 1249899526193 grid 10,2 %g @ @ @ Y not allowed cREVGeneral revUniqueID 1249899526194 grid 1,3 g ` @ @ cREVGeneral revUniqueID 1249899502138 grid 2,3 g @ @ cREVGeneral revUniqueID 1249899526195 grid 3,3 %g @ @ } not allowed cREVGeneral revUniqueID 1249899526196 grid 4,3 g @ @ } cREVGeneral revUniqueID 1249899526197 grid 5,3 g ` @ @ { cREVGeneral revUniqueID 1249899502139 grid 6,3 g @ @ { cREVGeneral revUniqueID 1249899526198 grid 7,3 g @ @ y cREVGeneral revUniqueID 1249899526199 grid 8,3 g @ @ y cREVGeneral revUniqueID 1249899526200 grid 9,3 %g ` @ @ not allowed cREVGeneral revUniqueID 1249899526201 grid 10,3 g @ @ cREVGeneral revUniqueID 1249899502140 grid 1,4 g ` @ @ } cREVGeneral revUniqueID 1249899526202 grid 2,4 g @ @ } cREVGeneral revUniqueID 1249899526203 grid 3,4 g @ @ { cREVGeneral revUniqueID 1249899526204 grid 4,4 %g @ @ { not allowed cREVGeneral revUniqueID 1249899502141 grid 5,4 g ` @ @ y cREVGeneral revUniqueID 1249899526205 grid 6,4 %g @ @ y not allowed cREVGeneral revUniqueID 1249899526206 grid 7,4 %g @ @ not allowed cREVGeneral revUniqueID 1249899526207 grid 8,4 g @ @ cREVGeneral revUniqueID 1249899502142 grid 9,4 %g ` @ @ } not allowed cREVGeneral revUniqueID 1249899526208 grid 10,4 g @ @ } cREVGeneral revUniqueID 1249899526209 grid 1,5 g ` @ @ { cREVGeneral revUniqueID 1249899526210 grid 2,5 g @ @ { cREVGeneral revUniqueID 1249899526211 grid 3,5 g @ @ y cREVGeneral revUniqueID 1249899502143 grid 4,5 g @ @ y cREVGeneral revUniqueID 1249899526212 grid 5,5 g ` @ @ cREVGeneral revUniqueID 1249899526213 grid 6,5 %g @ @ not allowed cREVGeneral revUniqueID 1249899526214 grid 7,5 g @ @ } cREVGeneral revUniqueID 1249899502144 grid 8,5 g @ @ } cREVGeneral revUniqueID 1249899526215 grid 9,5 %g ` @ @ { not allowed cREVGeneral revUniqueID 1249899526216 grid 10,5 %g @ @ { not allowed cREVGeneral revUniqueID 1249899526217 grid 1,6 %g `@ @ @ y not allowed cREVGeneral revUniqueID 1249899502145 grid 2,6 g @ @ @ y cREVGeneral revUniqueID 1249899526218 grid 3,6 g @ @ @ cREVGeneral revUniqueID 1249899526219 grid 4,6 %g @ @ @ not allowed cREVGeneral revUniqueID 1249899502146 grid 5,6 g `@ @ @ cREVGeneral revUniqueID 1249899526220 grid 6,6 %g @ @ @ not allowed cREVGeneral revUniqueID 1249899526221 grid 7,6 %g @ @ @ not allowed cREVGeneral revUniqueID 1249899526222 grid 8,6 %g @ @ @ not allowed cREVGeneral revUniqueID 1249899502147 grid 9,6 g `@ @ @ cREVGeneral revUniqueID 1249899526223 grid 10,6 %g @ @ @ not allowed cREVGeneral revUniqueID 1249899526224 grid 1,7 g ` @ @ cREVGeneral revUniqueID 1249899526225 grid 2,7 %g @ @ not allowed cREVGeneral revUniqueID 1249899502148 grid 3,7 g @ @ cREVGeneral revUniqueID 1249899526226 grid 4,7 g @ @ cREVGeneral revUniqueID 1249899526227 grid 5,7 %g ` @ @ not allowed cREVGeneral revUniqueID 1249899526228 grid 6,7 %g @ @ not allowed cREVGeneral revUniqueID 1249899502149 grid 7,7 %g @ @ not allowed cREVGeneral revUniqueID 1249899526229 grid 8,7 %g @ @ not allowed cREVGeneral revUniqueID 1249899526230 grid 9,7 g ` @ @ cREVGeneral revUniqueID 1249899526231 grid 10,7 g @ @ cREVGeneral revUniqueID 1249899502150 grid 1,8 g ` @ @ cREVGeneral revUniqueID 1249899526232 grid 2,8 g @ @ cREVGeneral revUniqueID 1249899526233 grid 3,8 %g @ @ not allowed cREVGeneral revUniqueID 1249899526234 grid 4,8 g @ @ cREVGeneral revUniqueID 1249899502151 grid 5,8 %g ` @ @ not allowed cREVGeneral revUniqueID 1249899526235 grid 6,8 %g @ @ not allowed cREVGeneral revUniqueID 1249899526236 grid 7,8 g @ @ cREVGeneral revUniqueID 1249899526237 grid 8,8 %g @ @ not allowed cREVGeneral revUniqueID 1249899502152 grid 9,8 g ` @ @ cREVGeneral revUniqueID 1249899526238 grid 10,8 g @ @ cREVGeneral revUniqueID 1249899526239 grid 1,9 g ` @ @ cREVGeneral revUniqueID 1249899526240 grid 2,9 %g @ @ not allowed cREVGeneral revUniqueID 1249899502153 grid 3,9 g @ @ cREVGeneral revUniqueID 1249899526241 grid 4,9 g @ @ cREVGeneral revUniqueID 1249899526242 grid 5,9 %g ` @ @ ? not allowed cREVGeneral revUniqueID 1249899526243 grid 6,9 %g @ @ ? not allowed cREVGeneral revUniqueID 1249899502154 grid 7,9 g @ @ = cREVGeneral revUniqueID 1249899526244 grid 8,9 %g @ @ = not allowed cREVGeneral revUniqueID 1249899526245 grid 9,9 %g ` @ @ ; not allowed cREVGeneral revUniqueID 1249899502155 grid 10,9 %g @ @ ; not allowed cREVGeneral revUniqueID 1249899526246 grid 1,10 g `@ @ @ 9 cREVGeneral revUniqueID 1249899526247 grid 2,10 g @ @ @ 9 cREVGeneral revUniqueID 1249899526248 grid 3,10 %g @ @ @ ? not allowed cREVGeneral revUniqueID 1249899502156 grid 4,10 g @ @ @ ? cREVGeneral revUniqueID 1249899526249 grid 5,10 g `@ @ @ = cREVGeneral revUniqueID 1249899526250 grid 6,10 g @ @ @ = cREVGeneral revUniqueID 1249899526251 grid 7,10 %g @ @ @ ; not allowed cREVGeneral revUniqueID 1249899502157 grid 8,10 g @ @ @ ; cREVGeneral revUniqueID 1249899526252 grid 9,10 %g `@ @ @ 9 not allowed cREVGeneral revUniqueID 1249899526253 grid 10,10 g @ @ @ 9 cREVGeneral revUniqueID 1249899526254 # troop Ew on mouseUp lock screen hide me set the beginning of this stack to word 2 of the short name of the mousecontrol show me unlock screen set the loc of me to the loc of button ("grid" && the beginning of this stack) end mouseUp nn q u cREVGeneral scriptChecksum koAp4.{hhandlerList mouseUp messagebreakPoints scriptSelection char 132 to 131scripteditorvscroll 0revUniqueID 1153007503163 bookmarks scripteditorselection 223tempScript prevHandler constrainRectangularExitscript Pglobal theSource
on mouseUp
lock screen
hide me
put the short name of the mousecontrol into theSource
show me
unlock screen
set the loc of image "choose" to the loc of me
set the visible of image "choose" to true
end mouseUp
on message theMessage
put theMessage
end message