View unanswered posts | View active topics It is currently Tue Apr 28, 2026 11:08 am



Reply to topic  [ 20 posts ]  Go to page 1, 2  Next
 Variable/BFS Extensions 
Author Message
Gameop
User avatar

Joined: Tue Nov 19, 2002 3:00 am
Posts: 1050
Location: USA
Unread post 
Okie I admit it I'm a slow learner I'm still on the Breadth First Search's in my quest for Uber 31337 Scripts. Beyond the fact that I kinda get it and am still lost with WHILES. I'm curious if anyone has a explanation of the Syntax as well as a description of how to use the following commands.

   SECTOR.EXPLORED[sector]
   SECTOR.FIGS.OWNER[sector]
   SECTOR.LIMPETS.OWNER[sector]
   SECTOR.MINES.OWNER[sector]
   SECTOR.TRADERS[sector][index]
   SECTOR.UPDATED[sector]
   SECTOR.WARPCOUNT[sector]
   SECTOR.WARPINCOUNT[sector]
   SECTOR.WARPSIN[sector][index]
   SECTOR.WARPS[sector][index]

More specifically besides needs a SECTOR.XXX for dummies Im curious if someone could break down a While statement that uses one.

###EP Wrote this It's his code he wrote to help me grasp
## The concept.. All Credit for This tidbit is his

while ($i <= SECTOR.WARPCOUNT[$focus])
           setVar $adjacent [SECTOR.WARPS[$focus][$i]
           if ($figlist[$adjacent] = 1)
                if ($adjacent <> $figHit)
                     setVar $Drop $adjacent
                     Return
                end

-=- The obvious question is why not bug EP. However he is a busy person what with writing 2.04Final And I am hopeing for multiple answers from people who understand the concepts better than I.

Thank you,
-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 Dec 05, 2006 9:09 pm
Profile ICQ
Veteran Op
User avatar

Joined: Thu Jun 02, 2005 2:00 am
Posts: 5558
Location: USA
Unread post 
Quote:
SECTOR.EXPLORED[sector]
SECTOR.FIGS.OWNER[sector]
SECTOR.LIMPETS.OWNER[sector]
SECTOR.MINES.OWNER[sector]
SECTOR.TRADERS[sector][index]
SECTOR.UPDATED[sector]
SECTOR.WARPCOUNT[sector]
SECTOR.WARPINCOUNT[sector]
SECTOR.WARPSIN[sector][index]
SECTOR.WARPS[sector][index]


That's the database. Much of the database is stored in a set of arrays.

You can get complete information about them in the script.html file. What more info do you need?

Code:
echo "The warps ADJ to " & $this_sector & " are:*"
setVar $idx 1
while ($idx <= SECTOR.WARPCOUNT[$this_sector])
     setVar $adj_sector SECTOR.WARPS[$this_sector][$idx]
     echo $adj_sector & "*"
     add $idx 1
end


As for adjacent fighits you don't want to use a BFS for that. Far too slow to initalize all of those variables for something so straight-forward. See my code above for a tip to finding an adj fig.

_________________
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
Image


Tue Dec 05, 2006 9:37 pm
Profile ICQ WWW
Commander
User avatar

Joined: Fri Jun 09, 2006 2:00 am
Posts: 1402
Location: Canada
Unread post 
Kaus wrote:
###EP Wrote this It's his code he wrote to help me grasp
## The concept.. All Credit for This tidbit is his

while ($i <= SECTOR.WARPCOUNT[$focus])
           setVar $adjacent [SECTOR.WARPS[$focus][$i]
           if ($figlist[$adjacent] = 1)
                if ($adjacent <> $figHit)
                     setVar $Drop $adjacent
                      Return
                end 
          end 
end

The WHILE Loop. A method of tightening up a loop or sequence of actions into a small package. The lines of code between "While ( ... )" and the "end" are repeated until the While condition becomes fales. In Some circumstances you could use "While (TRUE)" a.k.a. "While (1)", as the while-condition, causing the Loop to run forever. You can break out of a while loop at any point (such as a detected Error, or Triggered Event), by simply using the Goto command.
If you were to 'unroll' the above routine it might look something like:
:GetAdjSector
if ($figlist[SECTOR.WARPS[$focus][1]] = 1)
   setVar $adj SECTOR.WARPS[$focus][1]
   return
end
if ($figlist[SECTOR.WARPS[$focus][2]] = 1)
   setVar $adj SECTOR.WARPS[$focus][2]
   return
end
if ($figlist[SECTOR.WARPS[$focus][3]] = 1)
   setVar $adj SECTOR.WARPS[$focus][3]
   return
end
if ($figlist[SECTOR.WARPS[$focus][4]] = 1)
   setVar $adj SECTOR.WARPS[$focus][4]
   return
end
if ($figlist[SECTOR.WARPS[$focus][5]] = 1)
   setVar $adj SECTOR.WARPS[$focus][5]
   return
end
if ($figlist[SECTOR.WARPS[$focus][6]] = 1)
   setVar $adj SECTOR.WARPS[$focus][6]
   return
end
setVar $adj 0
return
#------END------
Hopefully you noticed the above 'unrolled' loop takes up alot of lines and would be difficult to debug/manage. Imagine you want to cycle through an array of 20k Sectors....  using a straight top-down approach would require at least 100,000 lines of code.
So, one of the best methods to compress 100k lines down to a managable segment would be to Roll it up into a Loop. Whether you're cycling through the adjacent sectors of a fighit, or, scanning all 20k Sectors in the Dbase you have the essential boundaries for a Loop: Starting point and Finish.
Scan through all sectors in a Dbase. We have the starting point (Sector 1), and the End Point (system value: SECTORS)
setVar $Pointer 1
while ($Pointer <= SECTORS)
   add $Pointer 1
end

the above is a 'tight-loop' ...that does the exact same thing as:
setVar $Pointer 1
add $Pointer 1
add $Pointer 1
add $Pointer 1
#  insert 19,995 more lines of 'add $Pointer 1'
add $Pointer 1
Or, you could achieve the same result thusly:
setVar $Pointer 1
:LetsGoAgain
if ($Pointer < SECTORS)
    add $Pointer 1
    goto :LetsGoAgain
end

 
Hope this helped.
 

_________________
----------------------------
-= QUANTUM Computing 101: 15 = 3 x 5 ... 48% of the time.


Wed Dec 06, 2006 2:45 am
Profile ICQ YIM
Gameop
User avatar

Joined: Tue Nov 19, 2002 3:00 am
Posts: 1050
Location: USA
Unread post 
Singularity wrote:
Quote:
SECTOR.EXPLORED[sector]
SECTOR.FIGS.OWNER[sector]
SECTOR.LIMPETS.OWNER[sector]
SECTOR.MINES.OWNER[sector]
SECTOR.TRADERS[sector][index]
SECTOR.UPDATED[sector]
SECTOR.WARPCOUNT[sector]
SECTOR.WARPINCOUNT[sector]
SECTOR.WARPSIN[sector][index]
SECTOR.WARPS[sector][index]


That's the database. Much of the database is stored in a set of arrays.

You can get complete information about them in the script.html file. What more info do you need?

.


Okay guilty as charged it is pretty straight forward however I was more curious fo examples of use. As for Script.html it does not have good descriptions for the database extentions/usage which is what i was looking for.

_________________
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 Dec 06, 2006 8:24 pm
Profile ICQ
Gameop
User avatar

Joined: Tue Nov 19, 2002 3:00 am
Posts: 1050
Location: USA
Unread post 
LoneStar wrote:
Kaus wrote:
###EP Wrote this It's his code he wrote to help me grasp ## The concept.. All Credit for This tidbit is his while ($i <= SECTOR.WARPCOUNT[$focus] )           ;  setVar $adjacent [SECTOR.WARPS[$focus][$i]                if ($figlist[$adjacent] = 1)                     if ($adjacent <> $figHit)                   &nbs p;  setVar $Drop $adjacent        &nb sp;         &nb sp;     Return     & nbsp;            end &nb sp;         end  end

The WHILE Loop. A method of tightening up a loop or sequence of actions into a small package. The lines of code between "While ( ... )" and the "end" are repeated until the While condition becomes fales. In Some circumstances you could use "While (TRUE)" a.k.a. "While (1)", as the while-condition, causing the Loop to run forever. You can break out of a while loop at any point (such as a detected Error, or Triggered Event), by simply using the Goto command.
If you were to 'unroll' the above routine it might look something like:
:GetAdjSectorif ($figlist[SECTOR.WARPS[$focus][1]] = 1)   setVar $adj SECTOR.WARPS[$focus][1]   returnendif ($figlist[SECTOR.WARPS[$focus][2]] = 1)   setVar $adj SECTOR.WARPS[$focus][2]   returnendif ($figlist[SECTOR.WARPS[$focus][3]] = 1)   setVar $adj SECTOR.WARPS[$focus][3]   returnendif ($figlist[SECTOR.WARPS[$focus][4]] = 1)   setVar $adj SECTOR.WARPS[$focus][4]   returnendif ($figlist[SECTOR.WARPS[$focus][5]] = 1)   setVar $adj SECTOR.WARPS[$focus][5]   returnendif ($figlist[SECTOR.WARPS[$focus][6]] = 1)   setVar $adj SECTOR.WARPS[$focus][6]   returnendsetVar $adj 0return#------END------
Hopefully you noticed the above 'unrolled' loop takes up alot of lines and would be difficult to debug/manage. Imagine you want to cycle through an array of 20k Sectors....  using a straight top-down approach would require at least 100,000 lines of code.
So, one of the best methods to compress 100k lines down to a managable segment would be to Roll it up into a Loop. Whether you're cycling through the adjacent sectors of a fighit, or, scanning all 20k Sectors in the Dbase you have the essential boundaries for a Loop: Starting point and Finish.
Scan through all sectors in a Dbase. We have the starting point (Sector 1), and the End Point (system value: SECTORS)
setVar $Pointer 1while ($Pointer <= SECTORS)   add $Pointer 1endthe above is a 'tight-loop' ...that does the exact same thing as:
setVar $Pointer 1add $Pointer 1add $Pointer 1add $Pointer 1#  insert 19,995 more lines of 'add $Pointer 1'add $Pointer 1
Or, you could achieve the same result thusly:
setVar $Pointer 1:LetsGoAgainif ($Pointer < SECTORS)    add $Pointer 1    goto :LetsGoAgainend
 
Hope this helped.
 


Thank you lonestar that is of much help and brings me abit closer to my ultimate goal of dominating the universe
I was lost to as what the 1 meant, not being really great at boolen logic I didnt think it could mean TRUE. It makes allot more sense now.
-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."


Wed Dec 06, 2006 8:25 pm
Profile ICQ
Gameop
User avatar

Joined: Tue Nov 19, 2002 3:00 am
Posts: 1050
Location: USA
Unread post 
Singularity wrote:
Quote:
Code:
echo "The warps ADJ to " & $this_sector & " are:*"
setVar $idx 1
while ($idx <= SECTOR.WARPCOUNT[$this_sector])
     setVar $adj_sector SECTOR.WARPS[$this_sector][$idx]
     echo $adj_sector & "*"
     add $idx 1
end


As for adjacent fighits you don't want to use a BFS for that. Far too slow to initalize all of those variables for something so straight-forward. See my code above for a tip to finding an adj fig.


While the above code I posted was more for While loops I may not have been specific enough in my question so therefor sorry. So the question to follow would be more of a practical one. BFS's intrigue me that said what type of script's do they fit well into and what type of functions outside of finding say the nearest XXX port from X location. Specifically in datamining and implication of said information.

-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."


Wed Dec 06, 2006 8:32 pm
Profile ICQ
Veteran Op
User avatar

Joined: Thu Jun 02, 2005 2:00 am
Posts: 5558
Location: USA
Unread post 
Database stuff... I already gave you a WARPS and WARPCOUNT example. Go to grimy and get a copy of my holokilla to see what the SECTOR.TRADERS and SECTOR.TRADERCOUNT can do for you.

I use SECTOR.PLANETCOUNT extensively in holoscanning scripts as well to avoid getting stuck in an IG. For instance you just torped someone, you want to know: Are they still there? Did they callsaveme? Was it a trader saveme or a planet saveme? What kind of figs do they have? Etc, etc, before making the jump into the sector for the kill. Last thing you want to do is charge into a shielded planet and get blasted for your trouble.

Altho in reality you'll never have someone else as the limpet owner... you couldn't actually see them to get them in your DB. The mine owner is useful if you're looking for, say, enemy sectors w/ mines. Think of people that drop mines near their base... you might have missed them there, but now you want to go thru and re-find them. This allows you to do that. That's only one of a billion possible applications. Use your imagination.

A BFS is a breadth-first search. The term "search" should point out that you're looking for a particular criteria amongst something else. In this case you are looking for a particular sector that fits a set of defined criteria. There are a lot of ways to do these kind of searches.

Linear - What most scripters do. They loop from 1 to SECTORS, looking for whatever criteria. Say for instance you're looking for sectors w/ ports outside of fedspace.

Code:
setVar $i 11
while ($i <= SECTORS)
     if (PORT.EXISTS[$i] = TRUE)
               echo $i & "*"
     end
     add $i 1
end


That's a linear search. It goes from 11 to SECTORS, every time looking for if the port exists... and echoing it out if it does. That'll flood your screen, probably, but you do get something for the trouble. You could just as easily write it to a file.

You can of course get more specific than this.

Code:
setVar $i 11
while ($i <= SECTORS)
     if (PORT.EXISTS[$i] = TRUE) AND (SECTOR.WARPCOUNT[$i] = 1)
               echo $i & "*"
     end
     add $i 1
end


Deadends with known ports. That's just the beginning. You could do deads, tunnels, a combination, that have mines and ports and figs and anything that the DB holds.

That's a linear search. It orders by simple sector number. You can reverse a linear search and go in reverse order...

Code:
setVar $i SECTORS
while ($i > 10)
     # your code here
     subtract $i 1
end


Which simply goes in reverse order.

Is that useful? Well yea, if you're looking up something by sector number it definately makes it easier to scroll a list that's in order.

But it doesn't tell you how far away something is.

For that you have the "first" searches. Breadth and Depth. With a breadth first search you "spiral out" adding each unsearched, unvisited, adjacent to the previous node to a growing list. Depth first is similar except it adds the first one, then visits that first one, before adding another... always taking you deeper down the node (sector) list before going wider along the node (sector) list.

Now there are a dozen complications for compsci geeks to consider, but you don't need to know them unless you just want to. All you need to know is: "use a breadth first search whenever you're trying to find stuff by distance" and you'll be fine.

For instance what if you wanted the nearest fuel selling port to your TA? That'd be a perfect BFS project. Infact that's one I challenge you to write. =)

Now you can do a linear search, combined with a bunch of getdistance checks looking for the smallest that way. I've seen some pretty famous scripters do that exact thing. But it's clunky... and not efficient in terms of time. If you have hours to run a script, great, by all means. But if you need to get it done within a second then don't do that. Do it the smart way.

I use a BFS to pre-cache distances and courses to and from a particular sector. Since I know where say, my base is, I can then predict the path from your fighit to my base... or from your fighit to any given sector of my choice. For instance, stardock or terra. If you're mowing to dock I can easily anticipate your next sector and have something nasty waiting. There is a lot of room for growth here, the applications for a BFS have only been touched on by script writers.

_________________
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
Image


Wed Dec 06, 2006 9:55 pm
Profile ICQ WWW
Commander
User avatar

Joined: Tue Oct 07, 2003 2:00 am
Posts: 1134
Location: Augusta, GA
Unread post 
I'd love to address this in more depth, but I only have enough time to plug the upcoming TWX release

Sing, you laff at a sequential getDistance search, but I have some results to share. With the new highly optimized getCourse / getDistance routines, here is a comparison between a one-complete-pass BFS vs. a full sweep of getDistances:

5,000 Sectors:
BFS: .336 Seconds
getDist: .526 Seconds

10,000 Sectors:
BFS: .689 Seconds
getDis: 2.062 Seconds

Now, in the current 2.04b and previous versions, BFS is 18x to 70x faster than a getDistance sweep, but in the upcoming release, it's only 1.5x to 6x faster for 5K to 20K sectors, respectively.

And who knows, in a future release, I may make that getCourse / getDistance routine so fast, it beats BFS

+EP+

_________________
Claim to Fame: only guy to ever crack the TW haggle algorithm, and fig/shield/hold price formula, twice.


Thu Dec 07, 2006 12:48 am
Profile WWW
Commander
User avatar

Joined: Tue Oct 07, 2003 2:00 am
Posts: 1134
Location: Augusta, GA
Unread post 
And Lonestar, I appreciate you adding the missing "end"s where you quoted Kaus quoting me, but you forgot to add the "add $i 1" before the last "end".

So, the code snippet should look like this:
while ($i <= SECTOR.WARPCOUNT[$focus])
     setVar $adjacent [SECTOR.WARPS[$focus][$i]
     if ($figlist[$adjacent] = 1)
           if ($adjacent <> $figHit)
                setVar $Drop $adjacent
                Return
           end
     end
     add $i 1
end

+EP+

_________________
Claim to Fame: only guy to ever crack the TW haggle algorithm, and fig/shield/hold price formula, twice.


Thu Dec 07, 2006 12:58 am
Profile WWW
Veteran Op
User avatar

Joined: Thu Jun 02, 2005 2:00 am
Posts: 5558
Location: USA
Unread post 
Yes but the new version isn't out yet... . Prior to your improvements it was painfully slow.

Even then, that assumes 1 getdistance per loop... which may not be the case if you're also looking for 1-ways.

I would like to get access to pointers in twx proxy scripting. I bet I could make a BFS that would still outpace getcourse.

Here's another nifty thing... hehe, internal access to the getCourse data structures. Run it once, copy it's data to a set of variables, then access as needed. Best of both worlds. That's the kind of stuff I'd do if I could find a way to get ahold of those pointers. 10ms, whole universe cached. Mmmm.

_________________
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
Image


Thu Dec 07, 2006 1:00 am
Profile ICQ WWW
Commander
User avatar

Joined: Fri Jun 09, 2006 2:00 am
Posts: 1402
Location: Canada
Unread post 
ElderProphet wrote:
And Lonestar, I appreciate you adding the missing "end"s where you quoted Kaus quoting me, but you forgot to add the "add $i 1" before the last "end".

lol, I have forgotten to add that 'add $i 1' so many times, that it's the very first thing I look for when debugging.
btw, I've studied your BF routine and after some customizing, have been able to scan and populate a fig list with deployed fighters (with an adj fig), within 1 to 15hops of a TA in less than 2 seconds. I love this BF
 

_________________
----------------------------
-= QUANTUM Computing 101: 15 = 3 x 5 ... 48% of the time.


Thu Dec 07, 2006 2:02 am
Profile ICQ YIM
Gameop
User avatar

Joined: Tue Nov 19, 2002 3:00 am
Posts: 1050
Location: USA
Unread post 
How do you guys time the commands? How fast GETDISTANCE vs. BFS etc. etc. etc.

_________________
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."


Thu Dec 07, 2006 2:42 am
Profile ICQ
Gameop
User avatar

Joined: Tue Nov 19, 2002 3:00 am
Posts: 1050
Location: USA
Unread post 
Singularity wrote:

For instance what if you wanted the nearest fuel selling port to your TA? That'd be a perfect BFS project. Infact that's one I challenge you to write. =)
.


Fair enough ill earn my knowledge; Accepted. And will be posted in the future when I get there. Appreciate you guys taking the time to respond.

-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."


Thu Dec 07, 2006 2:44 am
Profile ICQ
Commander
User avatar

Joined: Tue Oct 07, 2003 2:00 am
Posts: 1134
Location: Augusta, GA
Unread post 
In 2.04, I added a new getTimer command. It's the most accurate timer possible... down to about 5 microsecs on my pc.

# My PC is a 2.4 GHz dual core, but TWX uses only one
setVar $CPU_Hz 2400000000
getTimer $start
# do some routine
getTimer $stop
setVar $elapsed ($stop - $start)
setPrecision 10
setVar $timeInSecs ($elapsed / $CPU_Hz)
echo "*That routine took " $timeInSecs " seconds."

Good luck with that,
+EP+

_________________
Claim to Fame: only guy to ever crack the TW haggle algorithm, and fig/shield/hold price formula, twice.


Thu Dec 07, 2006 10:56 am
Profile WWW
Gameop
User avatar

Joined: Tue Nov 19, 2002 3:00 am
Posts: 1050
Location: USA
Unread post 
ElderProphet wrote:
In 2.04, I added a new getTimer command. It's the most accurate timer possible... down to about 5 microsecs on my pc.

# My PC is a 2.4 GHz dual core, but TWX uses only one
setVar $CPU_Hz 2400000000
getTimer $start
# do some routine
getTimer $stop
setVar $elapsed ($stop - $start)
setPrecision 10
setVar $timeInSecs ($elapsed / $CPU_Hz)
echo "*That routine took " $timeInSecs " seconds."

Good luck with that,
+EP+


Thanks EP.. All sorts of goodies in 2.04

_________________
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."


Thu Dec 07, 2006 6:40 pm
Profile ICQ
Display posts from previous:  Sort by  
Reply to topic   [ 20 posts ]  Go to page 1, 2  Next

Who is online

Users browsing this forum: No registered users and 34 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

Search for:
Jump to:  
cron
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group.
Designed by wSTSoftware.