# Cell.py -- Cell and Total classes for k1.py, a kakuro solver. # Copyright (C) 2010 Collin Park # # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation, either version 2 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # See for full license text. """ # A Cell has: # designator: row 1..99, column A..Z # Type: gray, sums, 1-9, 0 (for unknown) # possible values (list) # 2 possible totals: # across, down. Each one has: # backpointer to cell # what kind am i (down or across) # required sum # list of cells # "live" list of possible combos # array of 2 possible "totals": # across, down. Each one has: # backpointer to the 'total' structure GRAY = 'gray' SUMS = 'sums' ACROSS = 'across' DOWN = 'down' col_name = "ABCDEFGHIJKLMNOPQRSTUVWXYZ" # no more than 26 class Cell: def __init__(self, myrow, mycol, mytype=GRAY, dtotal=0, atotal=0): self.row = myrow self.col = mycol self.type = mytype self.above = None self.below = None self.left = None self.right = None self.dtotal = None self.atotal = None if dtotal != 0: self.dtotal = Total(self, DOWN, dtotal) if atotal != 0: self.atotal = Total(self, ACROSS, atotal) self.possibles = None if mytype not in (GRAY, SUMS): self.possibles = range(1,10) # 1..9 def name(self): return `self.row` + col_name[self.col] class Total: def __init__(self, mycell, mykind, mysum): self.cell = mycell self.kind = mykind self.sum = mysum # Fill these two in later. Names here so I don't forget. self.cells = list() self.combos = list() self.permutes = None def has_undecided(self): for acell in self.cells: if acell.type == 0: return True return False