0

I'm fairly new to python and I'm having trouble passing in a Cell object through a Block init function. I am making a 9x9 grid with 81 cell objects, and every "block" is a 3x3 grid of cells. (like a sudoku board) I am trying to separate the "blocks" in order to analyze whether the block consists of all 1:9 integers. I've successfully made the "grid" (more or less) and now I need to separate the grid into blocks. any help is appreciated!

class Block:
    def __init__(self, block_coord =(0,0),block_values = (This should be a 3x3 list of cell objects):            
        self.block_coord = block_coord
        self.block_values = block_values


class Cell:  
    def __init__(self, cell_coord = (0,0), cell_value = 1.0):            
        #stores the coordinate of the cell
        self.cell_coord = cell_coord

        #stores the value of the cell
        self.cell_value = cell_value

    def __call__(self):            
        return Cell(self.cell_coord,self.cell_value)            


    def getCoordinate (self):            
        return self.cell_coord

    def getValue (self):            
        return self.cell_value

    def setValue(self,set_value = 1.0):            
        self.cell_value = set_value

    def setCoordinate(self,set_coordinate = (0,0)):            
        self.cell_coord = set_coordinate
Ekaba Bisong
  • 2,918
  • 2
  • 23
  • 38
  • Do you realise that the `get/set` methods in your `Cell` are essentially pointless because you can just edit the properties directly, and they already have defaults. Also you almost certainly don't want that `__call__` method. It creates a copy of the Cell when you call a Cell instance. – blueteeth Dec 27 '19 at 11:56
  • Does the 3x3 list of Cell objects have to increment the coordinates appropriately? Can you edit your post with what you expect this to be. – blueteeth Dec 27 '19 at 11:59
  • Read [how-to-define-a-two-dimensional-array-in-python](https://stackoverflow.com/questions/6667201/how-to-define-a-two-dimensional-array-in-python) – stovfl Dec 27 '19 at 12:17

0 Answers0