diff --git a/grid.py b/grid.py new file mode 100644 index 0000000..247629e --- /dev/null +++ b/grid.py @@ -0,0 +1,72 @@ +import copy + +class Grid: + grid = [] + + def constructGrid2(self): + self.constructGrid(self.x,self.y) + + def __init__(self , x ,y ): + self.x = x; + self.y = y; + self.grid = [[1, 2, 3], [4, 5, 6], [7, 8, 9]] +# self.constructGrid(x,y) + + def constructGrid(self,x,y): + grid_y = [] + for y_ in range (0 , y) : + grid_x = [] + for x_ in range (0,x): + val = input('enter element ('+str(x_) +' , '+ str(y_) +') : ') + grid_x.append(int(val)) + + grid_y.append(copy.deepcopy(grid_x)) + self.grid = copy.deepcopy(grid_y) + + def displayGrid(self): + #for y in range (0 , self.y ): + print(self.grid) + + def getAdjecentIndexForElement(self,x,y): + lst = [] + lst2 =[] + lst.append((x-1,y-1)) + lst.append((x,y-1)) + lst.append((x+1,y-1)) + lst.append((x-1,y)) + lst.append((x+1,y)) + lst.append((x-1,y+1)) + lst.append((x,y+1)) + lst.append((x+1,y+1)) + + for l in lst: + if(((l[0] >= 0) and (l[0] < self.x) and (l[1]>=0) and (l[1]