Breadth First Searchs (Anticipation Scripts)
| Author |
Message |
|
Kaus
Gameop
Joined: Tue Nov 19, 2002 3:00 am Posts: 1050 Location: USA
|
 Breadth First Searchs (Anticipation Scripts)
So after finally quitting wow I need something to do other than my C++ project. I can safly say I remember a good 70% of the scripting commands and proper syntax. I'd like to pick up where I left off and that means getting back to my TW project I was working on. Anyways to my question: BFS (Breadth First Searchs) I have allways been kinda 50/50 on. I understand most of it but just have never been able to impliment it correctly. So I am imploring you uber scripters to help put it in plain english. http://en.wikipedia.org/wiki/Breadth_first_searchI have the concept but when it comes to the newer 2.04 command provided by EP I just can't seem to connect with it. This is my understanding of it Code: # Find the closest figged sector as provided in the script package 2.04
getNearestWarps $nearArray CURRENTSECTOR #Set array for BFS based on the TWX database to variable $nearArray from Currentsector
setVar $i 1 #set i to 1 (does the 1 actually equal a numeric value or in this case does it represent true?)
while ($i <= $nearArray) #while i is less than or equal to my current sector setVar $focus $nearArray[$i] #Set a new variable called focus to current sector+1 if ($figGrid[$focus] > 0) #Lost here echo "*NearFig: " $i "*" # Return to screen results or the BFS or closest fig to my current sector return #Back to beginning if the statement hasnt completed end #end if statement
add $i 1 #add 1 to i
end #end while statement
Im interested in trying to find tunnels/deadends for fig hits. Thank you for your time. -Kaus
_________________ Dark Dominion TWGS Telnet://twgs.darkworlds.org:23 ICQ#31380757, -=English 101 pwns me=- "This one claims to have been playing since 1993 and didn't know upgrading a port would raise his alignment."
|
| Tue Sep 16, 2008 11:36 pm |
|
 |
|
LoneStar
Commander
Joined: Fri Jun 09, 2006 2:00 am Posts: 1401 Location: Canada
|
 Re: Breadth First Searchs (Anticipation Scripts)
Elder Prophet has a great example on Grimy's Code: Basic Breadth-First Search Example -- Version: 1.0 Updated: 05/04/2006 Downloads: 104 by 66 Users
Description: This is a commented breadth-first search example. If you are unfamiliar with how to do a nearfig or search routine, then study this example. There are a few tweaks on this design that can add a bit of performance boost, but that would complicate the code a bit. As always, hit me up with questions / comments. (ElderProphet @ comcast.net).
_________________ ---------------------------- -= QUANTUM Computing 101: 15 = 3 x 5 ... 48% of the time.
|
| Tue Sep 16, 2008 11:41 pm |
|
 |
|
Kaus
Gameop
Joined: Tue Nov 19, 2002 3:00 am Posts: 1050 Location: USA
|
 Re: Breadth First Searchs (Anticipation Scripts)
LoneStar wrote: Elder Prophet has a great example on Grimy's Code: Basic Breadth-First Search Example -- Version: 1.0 Updated: 05/04/2006 Downloads: 104 by 66 Users
Description: This is a commented breadth-first search example. If you are unfamiliar with how to do a nearfig or search routine, then study this example. There are a few tweaks on this design that can add a bit of performance boost, but that would complicate the code a bit. As always, hit me up with questions / comments. (ElderProphet @ comcast.net).
Thank you, I do have that .ts but I still have a hard time with it. Guess I'm just slow -I'll rebrowse it and read the M()Mbot.ts maybe ill get it if I play around somemore.
_________________ Dark Dominion TWGS Telnet://twgs.darkworlds.org:23 ICQ#31380757, -=English 101 pwns me=- "This one claims to have been playing since 1993 and didn't know upgrading a port would raise his alignment."
|
| Tue Sep 16, 2008 11:44 pm |
|
 |
|
LoneStar
Commander
Joined: Fri Jun 09, 2006 2:00 am Posts: 1401 Location: Canada
|
 Re: Breadth First Searchs (Anticipation Scripts)
Kaus wrote: Thank you, I do have that .ts but I still have a hard time with it.
Guess I'm just slow
-I'll rebrowse it and read the M()Mbot.ts maybe ill get it if I play around somemore. Code: :Find_Closest_FIG setArray $checked SECTORS setVar $FIG_bottom 1 setVar $FIG_top 1 setVar $que[1] $destination while ($FIG_bottom <= $FIG_top) # Now, pull out the next sector in the que, and make it our focus setVar $FIG_Focus $que[$FIG_bottom] if ($FIGS[$FIG_Focus] <> 0) return end setVar $a 1 while ($a <= SECTOR.WARPCOUNT[$FIG_Focus]) setVar $adjacent SECTOR.WARPS[$FIG_Focus][$a] if ($checked[$adjacent] = 0) setVar $checked[$adjacent] 1 add $FIG_top 1 setVar $que[$FIG_top] $adjacent end add $a 1 end add $FIG_bottom 1 end setVar $FIG_Focus 0 return I used EP's routine in my Unexplored Sector Scout script as above (although I removed a cuple lines for ease of reading --they pertained to how far away my script would look before giving up). There's Two Array's: CHECKED and QUE. QUE is initailized to the 'current_sector' or start point. Now what helps me to undersatnd how this routine works is to imagine a STACK, the kind used in programming. Think of the QUE array as 'the stack of sectors to be looked at' The FIGBOTTOM variable points to the place in the STACK that will become the FOCUS (FIG_Focus). Now all the adjacents of the QUE[FIGBOTTOM], the FOCUS, are added to the QUE Araay and the FIG_TOP variable pointer moves up in essence increasing the size of the STACK ...so QUE at start equal our currentsector, lets say sector 1: setVar QUE[1] 1 now we add all the adjacents to the QUE: setVar QUE[1] 1 <---FIG BOTTOM AND FIG TOP setVar QUE[2] 2 setVar QUE[3] 3 setVar QUE[4] 4 setVar QUE[5] 5 setVar QUE[6] 6 setVar QUE[7] 7 <---FIG TOP ...once this is done then the FIGBOTTOM variable is incremented and now points at QUE[2], which is now sector 2, and now the QUE might looks like: setVar QUE[1] 1 setVar QUE[2] 2 <---FIG BOTTOM setVar QUE[3] 3 setVar QUE[4] 4 setVar QUE[5] 5 setVar QUE[6] 6 setVar QUE[7] 1 setVar QUE[8] 3 setVar QUE[9] 7 setVar QUE[10] 8 setVar QUE[11] 9 <---FIG TOP Now the QUE (STACK) contains adjacents of sector 1 and sector 2. This is howthe QUE is populated.. however you'll notice QUE[8] and QUE[3] both point to Sector 3. This is where the CHECKED array comes into the picture. EP's routine references the CHECKED array and would see that Sector 3 has alrady been CHECKED. As FIGBOTTOM moves 'up' the array towards the 'TOP', it is checked against a Deployed FIghter Array to determine if a Fighter is present. As soon as one is found the routine RETURNS to the calling routine where $FIG_Focus points the the Sector we're looking for. Hope this helps
_________________ ---------------------------- -= QUANTUM Computing 101: 15 = 3 x 5 ... 48% of the time.
|
| Wed Sep 17, 2008 12:30 am |
|
 |
|
Singularity
Veteran Op
Joined: Thu Jun 02, 2005 2:00 am Posts: 5558 Location: USA
|
 Re: Breadth First Searchs (Anticipation Scripts)
Quote: Im interested in trying to find tunnels/deadends for fig hits. Okay, let's boil this down. Anticipation scripts just try to figure out a probable sector you'll hit next in a grid. It's used whenever you have lag to deal w/, either because your ping blows goats or because you're using tpad/twarp to photon or drop. Mostly all they do is find an adj sector and use that. Classic anticipation does nothing more than wait for you to hit a 2-way and torp the other side, it can be expanded to hit 3-ways w/o a lot of additional problems, but that's why ram's gridder has a flex grid mode... to avoid those kind of classic anticipation shots. Why? Because more complex stuff isn't all that neccessary, and the more work you try to do after the fighit the slower your response will be. You can't really use a BFS on-the-fly after a fighit, it's just not fast enough. But you can pre-calculate courses and do a number of things that are saved as parms. That's why I have NearestTun and NearestDE sector parms, my data miner finds the nearest of both for each sector and attaches them as parms. If that's basically what you're trying to do you'll need to pre-cache all of it, what you're trying to do won't work directly for grid defense.
_________________ May the unholy fires of corbomite ignite deep within the depths of your soul...
1. TWGS server @ twgs.navhaz.com 2. The NavHaz Junction - Tradewars 2002 Scripts, Resources and Downloads 3. Open IRC chat @ irc.freenode.net:6667 #twchan 4. Parrothead wrote: Jesus wouldn't Subspace Crawl.
*** SG memorial donations via paypal to: dpocky68@booinc.com
|
| Wed Sep 17, 2008 12:44 am |
|
 |
|
Kaus
Gameop
Joined: Tue Nov 19, 2002 3:00 am Posts: 1050 Location: USA
|
 Re: Breadth First Searchs (Anticipation Scripts)
Singularity wrote: Quote: Im interested in trying to find tunnels/deadends for fig hits. Okay, let's boil this down. Anticipation scripts just try to figure out a probable sector you'll hit next in a grid. It's used whenever you have lag to deal w/, either because your ping blows goats or because you're using tpad/twarp to photon or drop. Mostly all they do is find an adj sector and use that. Classic anticipation does nothing more than wait for you to hit a 2-way and torp the other side, it can be expanded to hit 3-ways w/o a lot of additional problems, but that's why ram's gridder has a flex grid mode... to avoid those kind of classic anticipation shots. Why? Because more complex stuff isn't all that neccessary, and the more work you try to do after the fighit the slower your response will be. You can't really use a BFS on-the-fly after a fighit, it's just not fast enough. But you can pre-calculate courses and do a number of things that are saved as parms. That's why I have NearestTun and NearestDE sector parms, my data miner finds the nearest of both for each sector and attaches them as parms. If that's basically what you're trying to do you'll need to pre-cache all of it, what you're trying to do won't work directly for grid defense. Ok, makes sense ---------------------------------------------------------------------------------------------- setVar $i 1 #set i to 1 (does the 1 actually equal a numeric value or in this case does it represent true?) if ($figGrid[$focus] > 0) #Lost here add $i 1 #add 1 to i --------------------------------------------------------------------------------------------- Does "i" actually equal a numeric number in the above example or is it a perverbial true or false statement. For your near tun/de your pre caching all the data you use correct? Doesnt that slow you down? I guess I'm confused why the BFS isnt the best approach? I have to assume the BFS is slower due to the size of the array but I can't think of another way to load the data so you can find said deadends.
_________________ Dark Dominion TWGS Telnet://twgs.darkworlds.org:23 ICQ#31380757, -=English 101 pwns me=- "This one claims to have been playing since 1993 and didn't know upgrading a port would raise his alignment."
|
| Wed Sep 17, 2008 11:18 am |
|
 |
|
Kaus
Gameop
Joined: Tue Nov 19, 2002 3:00 am Posts: 1050 Location: USA
|
 Re: Breadth First Searchs (Anticipation Scripts)
Singularity wrote: Quote: Im interested in trying to find tunnels/deadends for fig hits. Okay, let's boil this down. Anticipation scripts just try to figure out a probable sector you'll hit next in a grid. It's used whenever you have lag to deal w/, either because your ping blows goats or because you're using tpad/twarp to photon or drop. Mostly all they do is find an adj sector and use that. Classic anticipation does nothing more than wait for you to hit a 2-way and torp the other side, it can be expanded to hit 3-ways w/o a lot of additional problems, but that's why ram's gridder has a flex grid mode... to avoid those kind of classic anticipation shots. Why? Because more complex stuff isn't all that neccessary, and the more work you try to do after the fighit the slower your response will be. You can't really use a BFS on-the-fly after a fighit, it's just not fast enough. But you can pre-calculate courses and do a number of things that are saved as parms. That's why I have NearestTun and NearestDE sector parms, my data miner finds the nearest of both for each sector and attaches them as parms. If that's basically what you're trying to do you'll need to pre-cache all of it, what you're trying to do won't work directly for grid defense. Ok, makes sense ---------------------------------------------------------------------------------------------- setVar $i 1 #set i to 1 (does the 1 actually equal a numeric value or in this case does it represent true?) if ($figGrid[$focus] > 0) #Lost here add $i 1 #add 1 to i --------------------------------------------------------------------------------------------- Does "i" actually equal a numeric number in the above example or is it a perverbial true or false statement. For your near tun/de your pre caching all the data you use correct? Doesnt that slow you down? I guess I'm confused why the BFS isnt the best approach? I have to assume the BFS is slower due to the size of the array but I can't think of another way to load the data so you can find said deadends.
_________________ Dark Dominion TWGS Telnet://twgs.darkworlds.org:23 ICQ#31380757, -=English 101 pwns me=- "This one claims to have been playing since 1993 and didn't know upgrading a port would raise his alignment."
|
| Wed Sep 17, 2008 11:18 am |
|
 |
|
Singularity
Veteran Op
Joined: Thu Jun 02, 2005 2:00 am Posts: 5558 Location: USA
|
 Re: Breadth First Searchs (Anticipation Scripts)
Quote: Does "i" actually equal a numeric number in the above example or is it a perverbial true or false statement. For your near tun/de your pre caching all the data you use correct? Doesnt that slow you down? I guess I'm confused why the BFS isnt the best approach? I have to assume the BFS is slower due to the size of the array but I can't think of another way to load the data so you can find said deadends. Consider the size of the arrays and the amount of work that has to be done in order to run a BFS for each fighit versus the amount of data that has to be stored just to remember the nearest DE and nearest tunnel, and the amount of time it takes to just load that. That's why BFS is too slow for on-the-fly grid defense, it takes 200+ ms to do the task, which more than doubles your reaction time. It turns an otherwise effective torper/dropper into a complete miss-fest. Anyway... So it's all just a stack. Think of it as a bunch of boxes stacked up. That's all an array is, and in this case there's 20000 boxes, each w/ a sector number. So let's use the new BFS routines to do this beast. GetNearestWarps, beautiful thing, altho I wish there was a termination criteria. Code: setVar $init_idx 1 while ($init_idx <= SECTORS) setSectorParameter $init_idx "NEARESTDE" 0 add $init_idx 1 end setVar $sector_to_check 1 while ($sector_to_check <= SECTORS) if (SECTOR.WARPCOUNT[$sector_to_check] = 1) setSectorParameter $sector_to_check "NEARESTDE" $sector_to_check goto :next_sector else getNearestWarps $stack $sector_to_check setVar $searchy 1 while ($searchy <= $stack) setVar $focus $stack[$searchy] if (SECTOR.WARPCOUNT[$focus] = 1) setSectorParameter $sector_to_check "NEARESTDE" $focus goto :next_sector end add $searchy 1 end end :next_sector add $sector_to_check 1 end
Anyway... I think that'd work. I just wrote it, so I haven't tested it, but you get the concept. You crunch all the data ahead of time and store it a parm.
_________________ May the unholy fires of corbomite ignite deep within the depths of your soul...
1. TWGS server @ twgs.navhaz.com 2. The NavHaz Junction - Tradewars 2002 Scripts, Resources and Downloads 3. Open IRC chat @ irc.freenode.net:6667 #twchan 4. Parrothead wrote: Jesus wouldn't Subspace Crawl.
*** SG memorial donations via paypal to: dpocky68@booinc.com
|
| Wed Sep 17, 2008 1:01 pm |
|
 |
|
ElderProphet
Commander
Joined: Tue Oct 07, 2003 2:00 am Posts: 1134 Location: Augusta, GA
|
 Re: Breadth First Searchs (Anticipation Scripts)
Kaus, I think it helps to imagine warps in a cone, like this: 1 <- Starting sector 2 3 4 5 6 7 <- Sectors adjacent to former level (distance of 1) 8 9 10 19 24 28 55 74 100 <- Sectors adjacent to that level (distance of 2) etc... The queue is built exactly like this. Once a sector has been added to the queue, it is not to be added again. To build the queue, you take your starting sector, add all of it's adjacent sectors to the queue. Then you work through each of those new adjacents, and add their adjacents, always observing the rule where a sector can't be added a second time. Then you work through those new adjacents, and so on. When you have a queue, you have to keep track of 2 places: which item you are working on, and where did you last add an item. I represent the current working item with $bottom, and the last add as $top, because you step through a queue from bottom to top. When you create your queue, the only thing in your queue is the starting sector, and your current and last add are both 1. As code... setVar $que[1] $startingSector setVar $top 1 setVar $bottom 1 What you do next is the loop, where you grab the next item to work on ($bottom) and add its adjacents to the top of the queue ($top), always observing the rule of only adding a sector once. The complete code, with comments, is as follows: Code: setVar $startingSector 1 // start at Terra for this search setVar $que[1] $startingSector setVar $top 1 setVar $bottom 1 while ($bottom <= $top) setVar $focus $que[$bottom] // focus on the next working item # Note: This is the clearest point to implement your search criteria # Let's say I'm looking for any sector with anyone's fig in it if (SECTOR.FIGS.QUANTITY[$focus] > 0) # Many scripts would jump out here, like "goto :figFound" echo "*Figs in sector " $focus end // That's it for the search portion # $focus is the working item, let's add its adjacents setVar $i 1 // $i is an iterator, a variable to track which warp of $focus we are currently working on while ($i <= SECTOR.WARPCOUNT[$focus]) setVar $adjacent SECTOR.WARPS[$focus][$i] // so when $i is 1, we're checking if the 1st warp has been seen before if ($previouslyQueued[$adjacent] = FALSE) # An unqueued adjacent has just been found, it goes on top, to be tested later add $top 1 // We have to increment $top so we know where to stick this unseen sector setVar $que[$top] $adjacent // now, in due course, this sector will be the focus setVar $previouslyQueued[$adjacent] = TRUE // haha, I bet you forgot this step, very important, grasshoppa end add $i 1 // now the next warp/adjacent of $focus will be tested end // all of that working sector's adjacents have been queued add $bottom 1 // now the next sector will be made the focus, so it's warps/adjacents will be tested end I've used TRUE and FALSE respectively, so you can know that 1 is numeric. Oh, and in the next TWX, in-line comments like that are supported. The getNearestWarps version that does the same thing is 8 lines, but I'll wait to post that until you understand this, which is as simple and clear as I can write it. Questions? +EP+
_________________ Claim to Fame: only guy to ever crack the TW haggle algorithm, and fig/shield/hold price formula, twice.
|
| Sat Sep 20, 2008 12:14 am |
|
 |
|
Crosby
Lieutenant Commander
Joined: Sun Jan 29, 2006 3:00 am Posts: 800 Location: Iowa
|
 Re: Breadth First Searchs (Anticipation Scripts)
thanks ep! cool read.
_________________ #+++ The early bird may get the worm, but the second mouse gets the cheese. #---
|
| Sat Sep 20, 2008 1:15 am |
|
 |
|
Kaus
Gameop
Joined: Tue Nov 19, 2002 3:00 am Posts: 1050 Location: USA
|
 Re: Breadth First Searchs (Anticipation Scripts)
Very Helpful EP, thank you for posting that. Do you think a BFS is the best approach for a world ptrade script in effort to find the closest xxx ports to buydown or sell?
_________________ Dark Dominion TWGS Telnet://twgs.darkworlds.org:23 ICQ#31380757, -=English 101 pwns me=- "This one claims to have been playing since 1993 and didn't know upgrading a port would raise his alignment."
|
| Mon Sep 22, 2008 10:47 pm |
|
 |
|
Singularity
Veteran Op
Joined: Thu Jun 02, 2005 2:00 am Posts: 5558 Location: USA
|
 Re: Breadth First Searchs (Anticipation Scripts)
Quote: Very Helpful EP, thank you for posting that. Do you think a BFS is the best approach for a world ptrade script in effort to find the closest xxx ports to buydown or sell? Yes, if you use it for each port you'd get something called a "A* search" which is considered one of the best searches for this type of data (non-weighted linked lists). It's an NP-difficult problem, similar to the "traveling salesman" problem. Getting a more accurate (in terms of distance) solution takes exponentially more computing power, and while there are some people that need that level of accuracy for other applications... Tradewars isn't one of them. This line of solutions isn't 100% perfect, since a quantum computer could theoretically solve it in a lot less time, but we're still 100 years out from that. Altho it would be entertaining to play TW w/ quantum computers... I'd love to see what we could do.
_________________ May the unholy fires of corbomite ignite deep within the depths of your soul...
1. TWGS server @ twgs.navhaz.com 2. The NavHaz Junction - Tradewars 2002 Scripts, Resources and Downloads 3. Open IRC chat @ irc.freenode.net:6667 #twchan 4. Parrothead wrote: Jesus wouldn't Subspace Crawl.
*** SG memorial donations via paypal to: dpocky68@booinc.com
|
| Mon Sep 22, 2008 11:17 pm |
|
 |
|
the reverend
Gameop
Joined: Thu Mar 08, 2001 3:00 am Posts: 886 Location: USA
|
 Re: Breadth First Searchs (Anticipation Scripts)
Kaus wrote: So after finally quitting wow I need something to do other than my C++ project. I can safly say I remember a good 70% of the scripting commands and proper syntax. I'd like to pick up where I left off and that means getting back to my TW project I was working on. welcome back from WOW. now if we can just resist the expansion this november...
_________________ twgs : telnet://twgs.thereverend.org:5023 web : http://www.thereverend.org games : http://www.thestardock.com/twgssearch/i ... verend.org helper : http://svn.thereverend.org:8080/revhelper/
|
| Tue Sep 23, 2008 11:17 am |
|
 |
|
NjoY
Ensign
Joined: Mon Jul 23, 2007 6:20 pm Posts: 288 Location: United Kingdom
|
 Re: Breadth First Searchs (Anticipation Scripts)
I've been following this thread for a while. Very interesting and informative. Thanx to all involved.
[OT] No one think this forum should be split into two separate forums? Scripting Forum and TW Helpers Forum? There is a goldmine of scripting info here. It would be a lot easier to search too.
i'd love to see a scripting 101 and/or a projects sub forum/thread. Also love to see some of the older scripters come and give there 2 pence/cents worth. Ram, Alex, Supg etc... Guess i might be hopin for 2 much there. Who knows.
_________________ Gul D'Tek (The Cardassian Hitman) ICQ - 446445340
I'm a TW and #SD# ing you was my idea!
Very funny, Scotty. Now beam down my clothes.~ J.T.Kirk
|
| Mon Sep 29, 2008 7:12 pm |
|
 |
|
Kaus
Gameop
Joined: Tue Nov 19, 2002 3:00 am Posts: 1050 Location: USA
|
 Re: Breadth First Searchs (Anticipation Scripts)
Thank you EP it helped me get the concept of the BFS
_________________ Dark Dominion TWGS Telnet://twgs.darkworlds.org:23 ICQ#31380757, -=English 101 pwns me=- "This one claims to have been playing since 1993 and didn't know upgrading a port would raise his alignment."
|
| Tue Oct 28, 2008 10:32 am |
|
 |
|
Who is online |
Users browsing this forum: No registered users and 35 guests |
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot post attachments in this forum
|
|