www.ClassicTW.com
https://mail.black-squirrel.com/

Parsing Dead Ends to a file
https://mail.black-squirrel.com/viewtopic.php?f=15&t=26023
Page 1 of 1

Author:  motrax [ Thu May 20, 2010 7:50 pm ]
Post subject:  Parsing Dead Ends to a file

Anyone know where I can get a twx script to parse dead ends (and unexplored dead ends) to a file?
I have "oz-unex-dend-parser" but I cannot find where it is supposed to get the info from.
TWX "$db" Gives me a list of dends. Maybe the question is how can I parse the "deepest" to a file from there?

Author:  LoneStar [ Thu May 20, 2010 7:56 pm ]
Post subject:  Re: Parsing Dead Ends to a file

Code:
setvar $File       "C:\DES.txt"
setvar $DEEPNESS   15
delete $File
setvar $idx       1
while ($idx <= sectors)
  if (sector.warpcount[$idx] = 1) and (sector.warpincount[$idx] = 1)
     if (Sector.explored[$idx] = "NO") OR (Sector.Explored[$idx] = "CALC")
         getsectorparameter $IDX "FIGSEC" $FIG
         if ($FIG = "0")
          getDistance $DIST 1 $IDX
            if ($DIST = "-1")
               send "^1*" & $IDX & "**Q"
               waiton ": ENDINTERROG"
               getDistance $DIST 1 $IDX
               if ($DIST = "-1")
                  goto :_NEXT_
               end
            end
            if ($DIST >= $DEEPNESS)
               write $File $IDX
            end
        end
    end
  end
  :_NEXT_
  add $idx 1
end

Author:  ElderProphet [ Fri May 21, 2010 6:37 am ]
Post subject:  Re: Parsing Dead Ends to a file

You don't need a script, you just need a few lines of code. In the routine below, I'm defining a deadend as a sector with only 1 warp in. If you want to define it differently, or add other criteria, then alter the IF statement.

getNearestWarps $warps STARDOCK
setVar $i $warps
while ($i > 1)
setVar $focus $warps[$i]
if (SECTOR.WARPINCOUNT[$focus] = 1)
write "DeadEnds.txt" $warps[$i]
end
subtract $i 1
end

The only lines that might need explanation are the first 2. The command getNearestWarps creates an array (named $warps[] in this case) sorted by distance (from STARDOCK in this case), from nearest to farthest. Additionally, getNearestWarps creates a variable ($warps in this case) set to the number of elements in that sorted array. So line 2 and the WHILE loop steps us through the $warps[] array from the farthest sector ($warps[$warps]) to the closest ($warps[2], because $warps[1] is the beginning sector, STARDOCK in this case).

Questions?

+EP+

Author:  LoneStar [ Fri May 21, 2010 9:16 am ]
Post subject:  Re: Parsing Dead Ends to a file

I have a question.. why don't you process the First element in the Array?

I've more questions, but I would be splitting hairs.

Author:  ElderProphet [ Fri May 21, 2010 10:41 am ]
Post subject:  Re: Parsing Dead Ends to a file

Because $warps[1] would be STARDOCK in that example.

Please, ask away. Splitting hairs if fine with me, so long as motrax doesn't mind if his thread digresses. For any questions that can be answered so that it benefits other visitors, I'm willing to take the time to answer in detail if I can.

Author:  motrax [ Fri May 21, 2010 5:25 pm ]
Post subject:  Re: Parsing Dead Ends to a file

Fire away with split hairs or whatever. I am always interested

Author:  motrax [ Fri May 21, 2010 5:31 pm ]
Post subject:  Re: Parsing Dead Ends to a file

Is it possible to sort the data from "$db" and parse to a file?. I would like to end up with a single column file with the deepest sector of dends 2 or more deep. Or am I asking the mpossible. Btw thanks for the input

Author:  Kaus [ Fri May 21, 2010 10:45 pm ]
Post subject:  Re: Parsing Dead Ends to a file

motrax wrote:
Is it possible to sort the data from "$db" and parse to a file?. I would like to end up with a single column file with the deepest sector of dends 2 or more deep. Or am I asking the mpossible. Btw thanks for the input


ElderProphet wrote:
getNearestWarps $warps STARDOCK
setVar $i $warps
while ($i > 1)
setVar $focus $warps[$i]
if (SECTOR.WARPINCOUNT[$focus] = 1)
write "DeadEnds.txt" $warps[$i]
end
subtract $i 1
end



Both EP's and Lonestars process to a file using the Write command. Looking specifically for 2deep deadends or larger would require somemore lines to Ep's code.

getNearestWarps $warps STARDOCK
setVar $i $warps
while ($i > 1)
setVar $focus $warps[$i]
if (SECTOR.WARPINCOUNT[$focus] = 2)
SetVar $Index 1
While ($Index < Sector.Warpcount[$focus])
Setvar $TestSector Sector.Warps[$focus][$Index]
If (Sector.Warpcount[$TestSector] = 1)
Echo ANSI_12 "*2 Deep Deadend at " & $TestSector
write "DeadEnds.txt" $TestSector
end
add $Index 1
end
end
subtract $i 1
end


One more which starts at 1 and goes to Sectors instead of farthest to closest as you requested. I'm posting it because awhile back I wrote this for a corpie and commented in my logic to help make it easier to read. May give you a better idea of what Lone and EP are doing in the above code. Figured since you asked for a 2 deep Deadend searcher it might be relevant. The script looks for unfigged deadends 2 deep.

#Setvar a variable named $file with the GAMENAME and "targettedde.txt" 
setVar $file GAMENAME & "_TargettedDe.txt"

#delete any previous written .txt documents
delete $file

#----Main Code 2 Deep Searcher
#Set a index variable to 1
Setvar $idx 1
#While 1 is less than total sectors
While ($idx <= Sectors)

#if the warpcount, (number of warps is 2)
If (SECTOR.WARPCOUNT[$idx] = 2)

#set a new variable to 1
Setvar $idxc 1

#while the new variable is less than the total warps out which we set to 2 above
While ($idxc <= SECTOR.WARPCOUNT[$idx])

#set a variable named $test that holds the adjacent warp to the current sector
Setvar $test SECTOR.WARPS[$idx][$idxc]

#get the sectors FIGSEC parameter and assign it to $figged variable
GetSectorParameter $test "FIGSEC" $Figged

#If the warp adjacent to our $test variable only has 1 warp out and is not $figged
If ((SECTOR.WARPCOUNT[$test] = 1) AND ($Figged = FALSE))

#write to our $file variable which also writes it out as a .txt
Write $file $test

#end our if arguement
end

#add +1 to the $idxc variable we set to incriment the while loop and allow it to exit normally
add $idxc 1

#end our second while loop
end

#end out first if statement
end

#increment our first while loop that cycles through sectors
add $idx 1

#end our first while loop
end


And you go from there with other if statements to test how back you want to go in the Deadend. Of course I am prolly missing something in my logic above, so I'll defer any mistakes to my newness :-)

Author:  ElderProphet [ Sat May 22, 2010 10:11 am ]
Post subject:  Re: Parsing Dead Ends to a file

Motrax, what do you mean by "deepest" and "2 or more deep"? To me, the deepest are the ones farthest from Stardock, and that is how the output from my code sorts them, from farthest to nearest. "2 or more deep" sounds like you mean a tunnel or bubble, which is more complex. To do that, you'd first do a bubble search, then look for deadends within the list of bubble sectors. I could post code for that, but first you should completely understand the 9-line routine I posted earlier. All of you guys can own 9 lines of code. Ask questions if you don't, and read script.html in your TWX folder.

"$db" is not part of TWX, that is something specific to Oz's script.

Kaus, your code snippets will find a 2-deep deadend (or 1-deep, depending on how you count it), or a deadend at the end of a tunnel, but not necessarily deadends within a bubble. Also, I think you are doing it the hard way, by looking for a sector with 2 waps and iterating through it's adjacents to check for a deadend. It would be more simple (and with one less iterator) to check for deadends, and see if the adjacent sector has 2 warps.
if (SECTOR.WARPINCOUNT[$focus] = 1)
setVar $adjacent SECTOR.WARPSIN[$focus][1]
if (SECTOR.WARPCOUNT[$adjacent] = 2)

+EP+

Author:  Kaus [ Sat May 22, 2010 10:38 pm ]
Post subject:  Re: Parsing Dead Ends to a file

ElderProphet wrote:
Motrax, what do you mean by "deepest" and "2 or more deep"? To me, the deepest are the ones farthest from Stardock, and that is how the output from my code sorts them, from farthest to nearest. "2 or more deep" sounds like you mean a tunnel or bubble, which is more complex. To do that, you'd first do a bubble search, then look for deadends within the list of bubble sectors. I could post code for that, but first you should completely understand the 9-line routine I posted earlier. All of you guys can own 9 lines of code. Ask questions if you don't, and read script.html in your TWX folder.

"$db" is not part of TWX, that is something specific to Oz's script.

Kaus, your code snippets will find a 2-deep deadend (or 1-deep, depending on how you count it), or a deadend at the end of a tunnel, but not necessarily deadends within a bubble. Also, I think you are doing it the hard way, by looking for a sector with 2 waps and iterating through it's adjacents to check for a deadend. It would be more simple (and with one less iterator) to check for deadends, and see if the adjacent sector has 2 warps.
if (SECTOR.WARPINCOUNT[$focus] = 1)
setVar $adjacent SECTOR.WARPSIN[$focus][1]
if (SECTOR.WARPCOUNT[$adjacent] = 2)

+EP+


Good point, thank you. Heh when I was writing the addition to your farthest routine I realized for the first time I could skip a step I used to do whereas I used to define my SECTOR.WARPCOUNT before the If Statement. The warpcount approach is certainly less complex and more to the point. I appreciate it :-)

Author:  LoneStar [ Mon May 24, 2010 6:42 am ]
Post subject:  Re: Parsing Dead Ends to a file

ElderProphet wrote:
Because $warps[1] would be STARDOCK in that example.

Splitting hair: if not processing STARDOCK, then similarly, why not exclude sectors adjacent Dock? :) further, why not assume that each adjacent to dock has a probable adjcent-count of 2 or more..

I might be a tad persnickety; but I wouldn't consider a sector with only 1-warpin (possibly many warps out), a True DeadEnd.

Final chop with the Finetooth-Axe. I think that Motraxs query pertained to finding 'UnExplored DeadEnd Sectors', likely Unfig'd. I believe filtering down a postentially Huge list of more than 3800 results, ameding the IF to: if (SECTOR.WARPINCOUNT[$warps[$warps]] = 1) AND (SECTOR.WARPCOUNT[$warps[$warps]] = 1) reduced the results to less than 3700, also adding if (SECTOR.EXPLORED[$warps[$warps]] <> "YES") brought the results down to just over 2k; filtering out Unfig'd Sectors brought thousands of results down to only 27. Adding conditional-tests or 'filters' is far more efficient. The real objective here is, I think, to come up with results that are pertinent and meaningful.

Code:
#  Something for Motrax to chew on :)
getNearestWarps $warps STARDOCK
delete "C:\DeadEnds.txt"
:_WHILE_LOOP_1
if (SECTOR.WARPINCOUNT[$warps[$warps]] = 1) AND (SECTOR.WARPCOUNT[$warps[$warps]] = 1) AND (SECTOR.EXPLORED[$warps[$warps] <> "YES")
    getDistance $DIST STARDOCK $warps[$warps]
    write "C:\DeadEnds.txt" $warps[$warps]
    Echo ANSI_15 & "*" & $warps[$warps] & ",   " & $DIST
end
subtract $warps 1
Branch ($warps <= 7) :_WHILE_LOOP_1

Author:  ElderProphet [ Mon May 24, 2010 9:40 am ]
Post subject:  Re: Parsing Dead Ends to a file

LoneStar wrote:
The real objective here is, I think, to come up with results that are pertinent and meaningful.

motrax's objective is exactly that. My objective is to help people learn to script. So the code snippets I post are usually over-simplified, but do 90% of what they've asked. There is merit in having them think through the other 10%. I don't say this to alter what and how you post, but so you understand where I'm coming from.

Author:  booger [ Mon May 24, 2010 10:15 am ]
Post subject:  Re: Parsing Dead Ends to a file

and i for one have to say thanks to you guys for trying to teach us!

Author:  motrax [ Mon May 24, 2010 10:51 pm ]
Post subject:  Re: Parsing Dead Ends to a file

Thanks for all the ideas.
If I send $db in TWX it gives all the deadends 2 or more deep.
It gives the entrance and the deepest sectors. That is the "deepest " that I was refering to.
I have plent of code to play with now

Page 1 of 1 All times are UTC - 5 hours
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
http://www.phpbb.com/