View unanswered posts | View active topics It is currently Tue Apr 21, 2026 3:59 am



Reply to topic  [ 3 posts ] 
 Would anyone be interested in a Sort ? 
Author Message
Lieutenant J.G.
User avatar

Joined: Sun Mar 13, 2005 3:00 am
Posts: 387
Location: USA
Unread post 
Howdy I have been trying to figure out how to implement a sort routine in TWX Script. I really want to use the Heapsort algorithm but am having problems because under TWX every variable is "global" if you know what I mean, and I run into a problem with the lack of functions that return a value as opposed to the subroutines.

The Heapsort algorithm is relative simple and doesn't require a lot of extra space and it is a close relative to the quicksort when it comes down to O(n).

That being said and having to workaround the lack of function calls I am calling on others to share some ideas about how this could be accomplished, if the community sees a need for such an algorithm.

Here are some ideas I have ....

Straight TWX algorithm. But therefore lies my problem. I am somewhat familiar with the Heapsort algorithm but I need function calls or a way to mimic function calls while just using subroutines, and a way to designate the way the array is sorted.

Modify the source code to TWX Proxy to create a new command Sort(array,# of elements,order)
where order can be a boolean of which direction the sort should be.... ascending vs descending.

The easiest way probably would be to modify TWX Proxy's source to add this command. But without talking to EP this might be more trouble with future versions of TWX Proxy.

Also would anyone else be interested in adding a "Shell" command to TWX Proxy. I am talking like adding a way to have TWX call a command shell and sending the correct arguments to a shell. I orginally envisioned this for a SQL database where we could set up the commands to store our data in a database through TWX script much along the lines of calling SQL through TWX and having TWX scripting build the correct SQL statements and then calling the sql command to add/delete appropiate information, this could eliminate the need for TWXSync along with allowing Zoc/pure TWX users to have almost real time data from corpies, All that would be needed would be a SQL server to be available from someone on the corp.
I have just started a new job that requires a majority of my time and have no internet access except when I am home which is like <10 hours a day of which I do like to get atleast 5-6 hours of sleep my time is currently limited. I will try and communicate any ideas through icq or here. My ICQ is in profile but can't say when I will be available for chat.
The only thing I can say will be I will listen to any and all and try and respond.

_________________
Find out just what any people will quietly submit to and you have the exact measure of the injustice and wrong which will be imposed on them. Frederick Douglas


Thu Apr 26, 2007 1:54 am
Profile ICQ
Commander
User avatar

Joined: Tue Oct 07, 2003 2:00 am
Posts: 1134
Location: Augusta, GA
Unread post 
I'm not a student of algorithms. Perhaps if you gave a few examples of the sort of data and data structures you want to sort, I could provide some ideas and code examples.

I once wrote a recursive depth-first search that used a stack, and the lack of local variables was a hurdle there also. I was able to work around this somewhat gracefully using arrays. Where you would normally push something onto the stack, I would increment my pointer to the top of the $stack array and add the value there.
Code:
setVar $stacktop ($stacktop + 1)
setVar $stack[$stacktop] $someValue

And at the start of my loop, I would set a local variable to $stack[$stacktop]
Here is a snippet from the heart of that routine:
Code:
:loop
while ($stackTop > 0)
     setVar $focus $stack[$stackTop]
     add $warpIndex[$focus] 1
     setVar $warp $warpIndex[$focus]
     while ($warp <= SECTOR.WARPCOUNT[$focus])
           setVar $adjacent SECTOR.WARPS[$focus][$warp]
           if ($checked[$adjacent] = 0)
                #  Push it onto the Stack
                add  $stackTop 1
                 setVar $stack[$stackTop] $adjacent
                 setVar $checked[$adjacent] 1
                gosub  :checkAdjacents
                gosub  :loop
                #  This is the return point when we POP off the Stack
           end
           setVar $focus $stack[$stackTop]
           add $warpIndex[$focus] 1
           setVar $warp $warpIndex[$focus]
     end
     # At an end point, record path by traversing the stack
     gosub :recordPath
     gosub :clearChecked
     subtract $stackTop 1
     if ($stackTop < 1)
           echo "*StackTop=" $stackTop ", halting.*"
           pause
           halt
     end
     gosub :checkPath
end
return

The other problem that I had to overcome in that routine was keeping track of which warp I was on for a given sector. You can see that I'm tracking that with another array, due to the global variable limitation. I'm substituting $warpIndex[SECTOR] in place of what would otherwise be $warp if local variables existed.

Anyway, I know that the above is complex, but I hope it is of some help in understanding how you can overcome the lack of local variables. If there is enough interest, I could comment it up well, and post it to Grimy ( & navhaz )

+EP+

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


Thu Apr 26, 2007 3:09 am
Profile WWW
Gameop
User avatar

Joined: Thu Mar 08, 2001 3:00 am
Posts: 886
Location: USA
Unread post 
here is a good summary of sorting algorithms.

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


Thu Apr 26, 2007 1:37 pm
Profile
Display posts from previous:  Sort by  
Reply to topic   [ 3 posts ] 

Who is online

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