View unanswered posts | View active topics It is currently Fri Apr 17, 2026 9:59 pm



Reply to topic  [ 37 posts ]  Go to page 1, 2, 3  Next
 Finding nearest gas. 
Author Message
Commander
User avatar

Joined: Wed May 03, 2006 2:00 am
Posts: 1722
Location: USA
Unread post 
I am seeing the same thing in script after script on this.
Code:
PORT.EXISTS[$sector]) AND (PORT.BUYFUEL[$secotor] = 0)

this needs to be screened for class0 and class9 ports
I use this instead.
Code:
(PORT.FUEL[$sector] > 0) AND (PORT.BUYFUEL[$sector] = 0)

below is a snippet for finding nearest gas / nearest figged gas port.
Code:
#set $gas variable to 0 for all gas ports..
#set higher for specific value for your needs
Setvar $gas 0
getNearestWarps $warparray currentsector
setvar $i 1
while ($i <= $warparray)
      #for figged gas port - uncomment these lines
      #getsectorparameter $warparray[$i] "FIGSEC" $checkfig
      #if ($checkfig = 1)
      if (PORT.FUEL[$warparray[$i]] > $gas) AND (PORT.BUYFUEL[$warparray[$i]] = 0)
      echo "Gas Port in " & $warparray[$i] & "*"
      #echo "Figged Gas Port in " & $warparray[$i] & "*"
      goto :ut_gasfind
      end
      #end
add $i 1
end
:ut_gasfind


easily modified for nearest 5 or 10 ports...yada yada
This has been a public service announcement from Team Kraaken.


Wed Apr 11, 2007 5:47 pm
Profile ICQ YIM
Veteran Op
User avatar

Joined: Thu Jun 02, 2005 2:00 am
Posts: 5558
Location: USA
Unread post 
Laff, I posted afew similar scripts a while back...

Code:
#  ------------------------------------------------------------ -------
# Dnyarri (Singularity)'s nearest unfigged sector finder.
# Useful little script that takes advantage of 2.04's BFS function
# to find the nearest unfigged sector in your DB. Requires ZTM.
# Uses Quickfig's FIGSEC parameter for fig tracking so you'll need
# that too.
#
# More scripts and info at http://www.navhaz.com
#  ------------------------------------------------------------ -------
# Search from where?
:get_start
getInput $start "Sector to search from (ENTER = your TA)? "
if ($start = "")
     gosub :get_current_sector
     setVar $start $current_sector
end
isNumber $result $start
if ($result < 1)
     goto :get_start
end
if ($start < 1) OR ($start > SECTORS)
     goto :get_start
end

# Do the search
echo ANSI_13 & "**Searching...*"
getNearestWarps $stack $start
setVar $idx 1
while ($idx <= $stack)
     setVar $this_sec $stack[$idx]
     getSectorParameter $this_sec "FIGSEC" $figged
     if ($figged = TRUE) AND (PORT.EXISTS[$this_sec] = TRUE) AND (PORT.BUYFUEL[$this_sec] = FALSE) AND ($this_sec <> RYLOS) AND ($this_sec <> ALPHACENTAURI)
           echo ANSI_14 & "Nearest figged fuel port to " & ANSI_11 & $start & ANSI_14 " is " & ANSI_10 & $stack[$idx] & ".*"
           if ($start = $this_sec)
                setVar $course_idx 0
                setVar $lane[1] $this_sec
           else
                getCourse $lane $start $this_sec
           end
           setVar $course_idx 1
           while ($course_idx <= ($lane+1))
                if ($course_idx = 1)
                      echo ANSI_2 & $lane[$course_idx]
                else
                      echo ANSI_9 & $lane[$course_idx]
                end
                if ($course_idx <= $lane)
                     # Print hop seperator if we should
                      echo ANSI_11 & ">"
                end
                add $course_idx 1
           end
           echo "**"
           send #145
           halt
     end
     add $idx 1
end

echo ANSI_14 & "No figged fuel ports found!**"
send #145

#  ------------------------------------------------------------ -------
halt
#  ------------------------------------------------------------ -------
# Get current sector - I'd use CURRENTSECTOR but it's wrong a lot.
:get_current_sector
setVar $current_sector 0

:current_sector_loop
isNumber $result $current_sector
if ($result < 1)
     send "/"
     waitFor #179
     setVar $line CURRENTLINE
     replacetext $line #179 " "
     getWord $line $current_sector 2
     goto :current_sector_loop
end
if ($current_sector < 1) OR ($current_sector > SECTORS)
     send "/"
     waitFor #179
     setVar $line CURRENTLINE
     replacetext $line #179 " "
     getWord $line $current_sector 2
     goto :current_sector_loop
end
return
#  ------------------------------------------------------------ -------

_________________
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 Apr 11, 2007 5:52 pm
Profile ICQ WWW
Commander
User avatar

Joined: Wed May 03, 2006 2:00 am
Posts: 1722
Location: USA
Unread post 
I know you did Sing...mine is shorter. I was looking at a resently posted TS and saw the( port exists ) error that seems to be following peeps around like a bad penny so I thought I would mention it again.
PORT.FUEL[$sector]  for class0 is always Zero.
I know you dont like Currentssector but I have a error checking subroutine for that so it helps simplify the code.


Wed Apr 11, 2007 5:58 pm
Profile ICQ YIM
Veteran Op
User avatar

Joined: Thu Jun 02, 2005 2:00 am
Posts: 5558
Location: USA
Unread post 
Quote:
I know you did Sing...mine is shorter.


Well, take out the any-sector code, remove the currentsector check, remove the getCourse echo (which is really handy) and it'd be about as short as yours... .

Quote:
PORT.FUEL[$sector] for class0 is always Zero.


*nod* That is a good point, a good way to distinguish between class 0s and other ports.

Quote:
I know you dont like Currentssector but I have a error checking subroutine for that so it helps simplify the code.


I've been thinking about that a bit but haven't gotten very far with it. I'm considering a prompt and stats follow like I do w/ my keepalive, keeping a seperate variable. When currentsector is used it'll check it, if it's not usable (normally it's blank or a strange snippet, non-numeric) then revert back to the follow variable, and if that fails, check slashstats. But uhm... if I do that, why use currentsector at all?

Oh and stocky's trollery... poof. No trollery allowed on the scripts forum. Danke.

_________________
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 Apr 11, 2007 7:32 pm
Profile ICQ WWW
Commander
User avatar

Joined: Wed May 03, 2006 2:00 am
Posts: 1722
Location: USA
Unread post 
good piont on the getcourse echo...does look handy...i think ill color code it based on "FIGSEC".


Wed Apr 11, 2007 8:57 pm
Profile ICQ YIM
Commander
User avatar

Joined: Fri Jun 09, 2006 2:00 am
Posts: 1401
Location: Canada
Unread post 
Parrothead wrote:
I am seeing the same thing in script after script on this.
Code:
PORT.EXISTS[$sector]) AND (PORT.BUYFUEL[$secotor] = 0)



Thanks for poitning that out. Though I should have stuck with my original idea:

Code:
if ((PORT.CLASS[$Gas_adjSector] = 3) OR (PORT.CLASS[$Gas_adjSector] = 4) OR (PORT.CLASS[$Gas_adjSector] = 5) OR (PORT.CLASS[$Gas_adjSector] = 7))

# .... whatever ...
end



btw. I can say that, on my machine, using getAllCourses and/or getNearestWarps.. is not only hideously slow but also appears to suffer from Memory-leaks. My first version utilized these 'new' commands, after running the script for about 5mins, TWX's memory allocation shot up beyond 70MBs. I believe, E.P.'s breadth first routine is the fastest. Again. this is based on results from running the script on my machine.

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


Thu Apr 12, 2007 1:13 am
Profile ICQ YIM
Commander
User avatar

Joined: Wed May 03, 2006 2:00 am
Posts: 1722
Location: USA
Unread post 
Time lapse in Seconds: 0.0171744498 was my average time after 3000 cycles. No memory leaks....I had ICQ ..2 twx sessions ...2 swath sessions yahoo messenger Teamspeak and a web Browser going. Your memory leaks are probably Microsoft issues (no big surprise there)..I use Windows 2000 software.


Thu Apr 12, 2007 1:45 am
Profile ICQ YIM
Commander
User avatar

Joined: Wed May 03, 2006 2:00 am
Posts: 1722
Location: USA
Unread post 
How bout that Haggle EP?


Thu Apr 12, 2007 2:06 am
Profile ICQ YIM
Commander
User avatar

Joined: Tue Oct 07, 2003 2:00 am
Posts: 1134
Location: Augusta, GA
Unread post 
It isn't memory leaks, it's several arrays of size SECTORS that are used in the getAllCourses and getNearestWarps routines. These will be much more noticeable in a 20k vs. a 5K... which just from the last 2 posts I can guess that PH is a 5K player and LS is a 20K player. Still, a subsequent release might be able to improve memory useage.

LoneStar, I imagine that getNearestWarps is fast on even your machine, though I can understand getAllCourses being slow, especially for a 20K. The getAllCourses routine has a little ways to go before being completely optimized. And remember, many of these calculations take 16X as long for a 20K vs. a 5K.

About ports... just remember that there are scenarios where a Bxx port might still report a qty of zero... like if the sector display has been seen, but not a Port Report or CIM download showing it. So to be comprehensive, LoneStar's approach is best, though it could be sped up some. One significant way would be to set the value of PORT.CLASS[$sector] to a variable and use that variable in the IF comparisons. Another would be to create a static boolean array of size 10 and check the value of PORT.CLASS against it... though they would have to be offset by one to account for Class 0 ports, since static arrays in TWX are 1-based.
Eg. if ($Buyers[PORT.CLASS[$sector] + 1)

That looks like one DB query, one Add, and one static array lookup... all very quick.

+EP+

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


Thu Apr 12, 2007 2:36 am
Profile WWW
Veteran Op
User avatar

Joined: Thu Jun 02, 2005 2:00 am
Posts: 5558
Location: USA
Unread post 
Is there a reason you don't just do what I did and compare to Rylos, AlphaCentuari, 1 and stardock? It would seem that 4 defined constants would be as fast, if not faster than, the internal translation of arrays.

Didn't I also report this as a bug? Because most class 0s buy fuel, so the buy fuel report should turn up TRUE... but for some reason it doesn't. If the port class was changed to sell fuel, shouldn't that reflect in the DB all the same?

_________________
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 Apr 12, 2007 2:49 am
Profile ICQ WWW
Commander
User avatar

Joined: Fri Jun 09, 2006 2:00 am
Posts: 1401
Location: Canada
Unread post 
ElderProphet wrote:
... LoneStar, I imagine that getNearestWarps is fast on even your machine, though I can understand getAllCourses being slow, especially for a 20K. The getAllCourses routine has a little ways to go before being completely optimized. And remember, many of these calculations take 16X as long for a 20K vs. a 5K.

About ports... just remember that there are scenarios where a Bxx port might still report a qty of zero... like if the sector display has been seen, but not a Port Report or CIM download showing it. So to be comprehensive, LoneStar's approach is best, though it could be sped up some. One significant way would be to set the value of PORT.CLASS[$sector] to a variable and use that variable in the IF comparisons. Another would be to create a static boolean array of size 10 and check the value of PORT.CLASS against it... though they would have to be offset by one to account for Class 0 ports, since static arrays in TWX are 1-based.
Eg. if ($Buyers[PORT.CLASS[$sector] + 1)

That looks like one DB query, one Add, and one static array lookup... all very quick.
+EP+


I messed around and experimented, and eventually realized that for the purposes of the script, all I really needed was specific criteria within a very short range, if not found, move on. At best -without using a timer- I think the average times involved in getting the results from getNearestWarps/getAllCourses averaged about 1 second. Though, using your breadth-first routine to search a finite depth was so much faster that there was no perceivable pause in execution.

Incidently. My computer has 256MB's of RAM ... so you can imagine the amount of page-swapping that would take place if any program gobbled up 70Megs... hehe

And I like your idea of the static boolean array.

Thanks

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


Thu Apr 12, 2007 3:51 am
Profile ICQ YIM
Commander
User avatar

Joined: Wed May 03, 2006 2:00 am
Posts: 1722
Location: USA
Unread post 
EP wrote:
like if the sector display has been seen, but not a Port Report or CIM download showing it.

Good point but not an issue if figged ports are wanted. I play mostly 10k games these days however Sector sized arrays only come into play in 20k games after a Ztm with getNearestWarps routines. In my bot I will use one possible sector size array and I always use the same $varspec so it will get overwritten anything that needs multiple arrays to work like duplicate screening and timestamp sorting I do thru a seperate script so the memory gets freed up after the work is done. Usually easy enough to use readtoarray from a temp file then delete it to store the data for later use post screening.


Thu Apr 12, 2007 4:48 am
Profile ICQ YIM
Veteran Op
User avatar

Joined: Thu Jun 02, 2005 2:00 am
Posts: 5558
Location: USA
Unread post 
If you take a look at bucket and radix sorts you'll find there are a few in-place (or partially in-place) algorithms you can use to keep temp array usage down. Once sorted it's fairly easy to write an in-place duplicate filter, just maintain a seperate read and write pointer along with the last known value.

If it next value is the same, scan down to find the next unique value and move the read ptr accordingly (keeping the write pointer the same). If not, no reposition is needed. Once positioned, do the op. Once the read ptr reaches the end of the array, clear out the remaining write spaces with 0s. I don't think TWX has a "destroy element" ability (would be nice) but you can simulate it by simply making 0 a null element.

There is a also trick tho where you can use:
Quote:
setArray $temparray 0


To destroy temp arrays when you're done. Readtoarray is fast, but writing the file still isn't. So you get the usual swap file issues multiplied by several.

_________________
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 Apr 12, 2007 5:53 am
Profile ICQ WWW
Commander
User avatar

Joined: Fri Jun 09, 2006 2:00 am
Posts: 1401
Location: Canada
Unread post 
Parrothead wrote:
EP wrote:
like if the sector display has been seen, but not a Port Report or CIM download showing it.

Good point but not an issue if figged ports are wanted. I play mostly 10k games these days however Sector sized arrays only come into play in 20k games after a Ztm with getNearestWarps routines. In my bot I will use one possible sector size array and I always use the same $varspec so it will get overwritten anything that needs multiple arrays to work like duplicate screening and timestamp sorting I do thru a seperate script so the memory gets freed up after the work is done. Usually easy enough to use readtoarray from a temp file then delete it to store the data for later use post screening.



I think a Bubble-Sort would alleviate the need for multiple arrays.

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


Thu Apr 12, 2007 6:19 am
Profile ICQ YIM
Veteran Op
User avatar

Joined: Thu Jun 02, 2005 2:00 am
Posts: 5558
Location: USA
Unread post 
A bubble sort is a horrible, horrible algorithm. It is taught in college only because the professor is a newb, or merely addicted to bad first-year algorithms. Use a radix or bucket sort, it is far far faster, n*log(n) as opposed to n^2.

_________________
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 Apr 12, 2007 6:24 am
Profile ICQ WWW
Display posts from previous:  Sort by  
Reply to topic   [ 37 posts ]  Go to page 1, 2, 3  Next

Who is online

Users browsing this forum: Adept and 7 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.