Bläddra i källkod

ScriptExplore Update

Added what I think is the base concept for the stack of sectors we
didn't pick when we did our sorting... issue is if we try to move there
we might run into hazzards, so we might want to take bug-o's safe
traveling part and add that in so we can get to that random sector on
the stack or grab any new sectors along the way too.
david 5 år sedan
förälder
incheckning
af7b50104a
1 ändrade filer med 33 tillägg och 13 borttagningar
  1. 33 13
      flexible.py

+ 33 - 13
flexible.py

@@ -997,6 +997,7 @@ class ScriptExplore(object):
         self.clear = []         # Warps that we know are clear.
         self.highsector = 0     # Selected Sector to move to next!
         self.highwarp = 0       # Selected Sector's Warp Count!
+        self.stacksector = set()   # Set of sectors that we have not picked but are unexplored... even though we did a holo!
         self.oneMoveSector = False
         self.times = 0
         self.maxtimes = 0
@@ -1009,7 +1010,7 @@ class ScriptExplore(object):
         self.observer.connect("game-line", self.game_line)
 
         self.defer = None
-        self.send2player("Explorer v1.00")
+        self.send2player("Explorer v1.01")
 
         # How many times we going to go today?
         ask = PlayerInput(self.game)
@@ -1025,7 +1026,7 @@ class ScriptExplore(object):
                 self.send2game("D")
                 self.state = 1
             
-        d = ask.prompt("How many sectors would you like to explore?", 5, name="times", digits=True)
+        d = ask.prompt("How many sectors would you lick to explode?", 5, name="times", digits=True)
         #d.addCallback(ask.output)
         #d.addCallback(lambda ignore: self.settimes(ask.keep))
         d.addCallback(settimes)
@@ -1067,8 +1068,9 @@ class ScriptExplore(object):
     
     def game_line(self, line: str):
         log.msg("{0} | {1}".format(self.state, line))
-        if "Mine Control" in line:
+        if "Mine Control" in line: # If we don't have a Holo-Scanner and we attempted to do a Holo-scan, abort
             self.deactivate()
+
         if self.state == 1:
             # Density Scan, (Assume we have the Holo-Scanner)
             if not self.didScan:
@@ -1083,6 +1085,7 @@ class ScriptExplore(object):
                 work = re.split(r"\s+", work)
                 # 'Sector', '8192', '0', 'Warps', '4', 'NavHaz', '0', 'Anom', 'No'
                 # 'Sector', '(', '8192)', '0', 'Warps', '4', 'NavHaz', '0', 'Anom', 'No'
+
                 # New Sector?
                 if work[1] == '(':
                     temp1 = True
@@ -1091,6 +1094,7 @@ class ScriptExplore(object):
 
                 # Yes new sector! So we will add it!
                 if temp1:
+                    # Switch Anom into bool state
                     if(work[9] == 'No'):
                         temp = False
                     else:
@@ -1113,20 +1117,32 @@ class ScriptExplore(object):
             #    {'sector': 3, 'density': 0, 'warps': 2, 'navhaz': 0, 'anom': False},
             #]
 
-            if not self.dense:
+            # Do we have a new place to go? (That is also worth going to)
+            if not self.dense: # Dense contains no new sectors, abort
                 log.msg("No New Sectors Found!")
                 self.send2player("Find a new area for me to search in!")
+                # Attempt to resolve no new sectors!
+                if self.stacksector: # Do we have anything on the stack? (If so we set highsector with one of the randomly selected sectors)
+                    self.highsector = self.stacksector.pop()
+                    # Ok so here is were we should jump into some other way to safely get to that said sector, and safely also meaning if we see and
+                    #  new sectors along the way stop and grab them too... or just throw them onto the stack.
                 self.deactivate()
-            elif self.dense:
-                t = [] # Pre-Test
+            elif self.dense: # Dense does contain at least 1 new sector, continue on
+                t = [] # Pre-Test to check if there are just a bunch of 1 warp sectors
                 for d in self.dense:
                     if d['warps'] != 1:
                         t.append(d['sector'])
-                if not t:
+                if not t: # If there are no sectors with more that 1 warp, abort
                     log.msg("No Sectors Found except one move sector!")
                     self.send2player("Find a new area for me to look at!")
+                    # Attempt to resolve no new sectors with more than 1 warp!
+                    if self.stacksector: # Do we have anything on the stack? (If so we set highsector with one of the randomly selected sectors)
+                    self.highsector = self.stacksector.pop()
+                    # Ok so here is were we should jump into some other way to safely get to that said sector, and safely also meaning if we see and
+                    #  new sectors along the way stop and grab them too... or just throw them onto the stack.
                     self.deactivate()
 
+            # Is the sector safe to go into?
             for d in self.dense:
                 if not d['anom']:
                     # Sector does not contain a Anomoly
@@ -1138,7 +1154,7 @@ class ScriptExplore(object):
                                 # If Sector is worth checking out?
                                 self.clear.append(d['sector'])
             
-            if self.clear:
+            if self.clear: # We have sector(s) we can move to!
                 log.msg("Clear Sectors: {0}".format(len(self.clear)))
                 self.state = 5
         elif self.state == 5:
@@ -1160,10 +1176,7 @@ class ScriptExplore(object):
                         elif d['warps'] == self.highwarp:
                                 if c > self.highsector:
                                     self.highsector = c
-                                    
-            # Is this the same sector we were at a few seconds ago?
-            # If it is go for one of the other sectors
-            
+                        
             # If we found the best sector to move to and with previous test of safety we will now move to that sector!
             if self.highwarp != 0 or self.highsector != 0:
                 log.msg("Sector: {0:5d} Warps: {1}".format(self.highsector, self.highwarp))
@@ -1172,6 +1185,13 @@ class ScriptExplore(object):
                 log.msg("Oh Nose! We didn't find any Sector with higher Warps than any of the others!")
                 self.deactivate()
         elif self.state == 6:
+            # Add the dense scan of unknown sectors onto the stack of sectors
+            for d in self.dense:
+                self.stacksector.add(d['sector'])
+            
+            # Remove the sector we are just about to go to, we use discard so if the sector does not exist we don't throw a error!
+            self.stacksector.discard(self.highsector)
+
             # Ok we know the sector we want to go to now let's move it!
             self.send2game("m{0}\n\r".format(self.highsector))
 
@@ -1183,7 +1203,7 @@ class ScriptExplore(object):
             self.highsector = 0
             self.state = 1
             
-            # We are in a infinite Loop! Warning! Yes we can and will eat all the turns! :P
+            # Warning! Yes we can and will eat all the turns! :P
             self.times -= 1
             if self.times <= 0:
                 self.send2player("Completed {0}".format(self.maxtimes))