changeset 14:1e961cf10f88

10a is losing at 1R
author Henry S. Thompson <ht@inf.ed.ac.uk>
date Sat, 21 Mar 2020 21:15:52 +0000
parents 70993b538ddb
children 22b0894c0f4c
files nono.py
diffstat 1 files changed, 24 insertions(+), 14 deletions(-) [+]
line wrap: on
line diff
--- a/nono.py	Fri Mar 20 19:15:42 2020 +0000
+++ b/nono.py	Sat Mar 21 21:15:52 2020 +0000
@@ -82,9 +82,9 @@
       if self.onepass(self.margin0,self.marginN+1,scratch,runs.copy()):
         wins+=1
     dprint(wins, scratch)
-    dprint('r40',self.m.rows[4])
     maybeSeq=None
     inSeq=None
+    j=None
     for i in range(self.n):
       if scratch[i]>=wins:
         # If blobby in _every_ pass, then must be a blob
@@ -93,27 +93,28 @@
           dprint('s1',inSeq)
           maybeSeq=None
         if self[i].val is None:
+          dprint('s1a',i)
           self.newBlob(i,True)         # Check cross-vector
+          j=i
           changed=1
         elif self[i].val is True:
-          # already there
           pass
         else:
-          print("Shouldn't happen: attempt to blob where x already present! %s at %s"%(self,i),file=sys.stderr)
-          exit(101)
+          eprint("Shouldn't happen: attempt to blob where x already present! %s at %s"%(self,i),err=101)
       elif inSeq is not None:
         if self[i].val is not True:
           inSeq=None
           maybeSeq=None
-          dprint('s2',i-1)
-          self.checkNew(i-1)
+          dprint('s2',i-1,j)
+          if j is not None:
+            # Only if we actually added a blob at some point
+            self.checkNew(i-1)
       elif self[i].val is True and maybeSeq is None:
         dprint('s3',i)
         maybeSeq=i
     dprint('s4',inSeq,i)
     if inSeq is not None:
       self.checkNew(i)
-    dprint('r41',self.m.rows[4])
     return changed
 
   def onepass(self,i0,iBound,scratch,stack):
@@ -184,13 +185,12 @@
       for k in range(iBound):
         scratch[k]+=maybe[k]
       return True
-    print("Shouldn't happen? - fell through",stack,i,iBound)
+    eprint("Shouldn't happen? - fell through",stack,i,iBound,err=102)
 
   def checkX(self,pos,crosspos):
     # New x at pos, are there others that can be xed out now?
     # Overkill as is?
     dprint('cx',self.cLet+str(crosspos),pos)
-    dprint('cxr1',self.m.rows[4])
     if self.runs:
       start0=0 if self.margin0==0 else self.margin0+1
       if self.marginal(range(start0,pos+1),self.runs[0]):
@@ -203,7 +203,6 @@
         dprint('cx2a')
       else:
         dprint('cx2b')
-    dprint('cxr2',self.m.rows[4])
 
   def checkNew(self,pos):
     # New blob at pos, can we complete anything?
@@ -271,7 +270,7 @@
     g=0 # length of a gap
     for i in rng:
       if self[i].val is True:
-        # Shouldn't be possible?
+        # Should//n't be possible?
         dprint('mx0')
         return False
       if self[i].val is False:
@@ -284,6 +283,7 @@
         # None
         g+=1
         if g==l:
+          # run could fit here, so no go
           dprint('mx1')
           return False
     if g>0:
@@ -423,14 +423,14 @@
   def setVal(self,v):
     if v is True:
       if self.val is False:
-        print("Warning: x -> * at %s,%s"%(self.x,self.y),file=sys.stderr)
+        wprint("Warning: x -> * at %s,%s"%(self.x,self.y))
       elif self.val is True:
         # No-op
         return
       self.val=v
     else:
       if self.val is not None:
-        print("Warning: %s -> %s at %s,%s"%(self.val,v,self.x,self.y),file=sys.stderr)
+        wprint("Warning: %s -> %s at %s,%s"%(self.val,v,self.x,self.y))
       self.val=v
         
 
@@ -481,7 +481,17 @@
       print(self)
 
 def dprint(*args):
-  pass # print(*args)
+  print(*args)
+  sys.stdout.flush()
+
+def eprint(*args,**kw):
+  print(*args,file=sys.stderr)
+  sys.stderr.flush()
+  exit(kw['err'])
+
+def wprint(*args):
+  print(*args,file=sys.stderr)
+  sys.stderr.flush()
 
 if __name__ == '__main__':
   if len(sys.argv)>1: