docs: def choose_best_mask(self):
          """This method returns the index of the "best" mask as defined by
          having the lowest total penalty score. The penalty rules are defined
          by the standard. The mask with the lowest total score should be the
          easiest to read by optical scanners.
          """
          self.scores = []
          for n in range(len(self.masks)):
              self.scores.append([0,0,0,0])
  
          #Score penalty rule number 1
          #Look for five consecutive squares with the same color.
          #Each one found gets a penalty of 3 + 1 for every
          #same color square after the first five in the row.
          for (n, mask) in enumerate(self.masks):
              current = mask[0][0]
              counter = 0
              total = 0
  
              #Examine the mask row wise
              for row in range(0,len(mask)):
                  counter = 0
                  for col  in range(0,len(mask)):
                      bit = mask[row][col]
  
                      if bit == current:
                          counter += 1
                      else:
                          if counter >= 5:
                              total += (counter - 5) + 3
                          counter = 1
                          current = bit
                  if counter >= 5:
                      total += (counter - 5) + 3
  
              #Examine the mask column wise
              for col in range(0,len(mask)):
                  counter = 0
                  for row in range(0,len(mask)):
                      bit = mask[row][col]
  
                      if bit == current:
                          counter += 1
                      else:
                          if counter >= 5:
                              total += (counter - 5) + 3
                          counter = 1
                          current = bit
                  if counter >= 5:
                      total += (counter - 5) + 3
  
              self.scores[n][0] = total
  
          #Score penalty rule 2
          #This rule will add 3 to the score for each 2x2 block of the same
          #colored pixels there are.
          for (n, mask) in enumerate(self.masks):
              count = 0
              #Don't examine the 0th and Nth row/column
              for i in range(0, len(mask)-1):
                  for j in range(0, len(mask)-1):
                      if mask[i][j] == mask[i+1][j]   and \
                         mask[i][j] == mask[i][j+1]   and \
                         mask[i][j] == mask[i+1][j+1]:
                          count += 1
  
              self.scores[n][1] = count * 3
  
          #Score penalty rule 3
          #This rule looks for 1011101 within the mask prefixed
          #and/or suffixed by four zeros.
          patterns = [[0,0,0,0,1,0,1,1,1,0,1],
                      [1,0,1,1,1,0,1,0,0,0,0],]
                      #[0,0,0,0,1,0,1,1,1,0,1,0,0,0,0]]
  
          for (n, mask) in enumerate(self.masks):
              nmatches = 0
  
              for i in range(len(mask)):
                  for j in range(len(mask)):
                      for pattern in patterns:
                          match = True
                          k = j
                          #Look for row matches
                          for p in pattern:
                              if k >= len(mask) or mask[i][k] != p:
                                  match = False
                                  break
                              k += 1
                          if match:
                              nmatches += 1
  
                          match = True
                          k = j
                          #Look for column matches
                          for p in pattern:
                              if k >= len(mask) or mask[k][i] != p:
                                  match = False
                                  break
                              k += 1
                          if match:
                              nmatches += 1
  
  
              self.scores[n][2] = nmatches * 40
  
          #Score the last rule, penalty rule 4. This rule measures how close
          #the pattern is to being 50% black. The further it deviates from
          #this this ideal the higher the penalty.
          for (n, mask) in enumerate(self.masks):
              nblack = 0
              for row in mask:
                  nblack += sum(row)
  
              total_pixels = len(mask)**2
              ratio = nblack / total_pixels
              percent = (ratio * 100) - 50
              self.scores[n][3] = int((abs(int(percent)) / 5) * 10)
  
  
          #Calculate the total for each score
          totals = [0] * len(self.scores)
          for i in range(len(self.scores)):
              for j in range(len(self.scores[i])):
                  totals[i] +=  self.scores[i][j]
  
          #DEBUG CODE!!!
          #Prints out a table of scores
          #print('Rule Scores\n      1     2     3     4    Total')
          #for i in range(len(self.scores)):
          #    print(i, end='')
          #    for s in self.scores[i]:
          #        print('{0: >6}'.format(s), end='')
          #    print('{0: >7}'.format(totals[i]))
          #print('Mask Chosen: {0}'.format(totals.index(min(totals))))
  
          #The lowest total wins
          return totals.index(min(totals))