Logo Search packages:      
Sourcecode: jack version File versions  Download package

def lifedemo::LifeBoard::display (   self,
  update_board = 1 
)

Display the whole board, optionally computing one generation

Definition at line 78 of file lifedemo.py.

00078                                      :
      """Display the whole board, optionally computing one generation"""
      M,N = self.M, self.N 
      if not update_board:
          for i in range(0, M):
            for j in range(0, N):
                  if self.state.has_key( (i,j) ): 
                      self.scr.addch(j+1, i+1, self.char)
                  else:
                      self.scr.addch(j+1, i+1, ' ')
          self.scr.refresh()
          return

      d={} ; self.boring=1
      for i in range(0, M):
          L=range( max(0, i-1), min(M, i+2) )
          for j in range(0, N):
            s=0
            live=self.state.has_key( (i,j) )
            for k in range( max(0, j-1), min(N, j+2) ):
                for l in L:
                  if self.state.has_key( (l,k) ):
                      s=s+1
            s=s-live
            if s==3: 
                # Birth
                d[i,j]=1 
                self.scr.addch(j+1, i+1, self.char)
                if not live: self.boring=0  
            elif s==2 and live: d[i,j]=1       # Survival
            elif live: 
                # Death
                self.scr.addch(j+1, i+1, ' ')
                self.boring=0
      self.state=d
      self.scr.refresh()
    def makeRandom(self):


Generated by  Doxygen 1.6.0   Back to index