I am trying to put a custom object into a 2d list and I'm getting very confused. Here's what I have:
Here's the cell class:
class Cell(object):
def __init__(self, what, cost):
self.what = what
self.parentx = -1
self.parenty = -1
self.f = 0
self.g = 0
self.h = 0
self.cost = cost
and my insertion object (where I take a grid/ maze and put the data into objects):
def insertion (r, c, grid):
cellGrid = []
for x in range(0, r):
for y in range(0, c):
if (grid[x][y] == '%'):
what = 0
cost = 100000000
elif(grid[x][y] == '-'):
what = 1
cost = 1
elif (grid[x][y] == '.'):
what = 2
cost = 0
else:
what = 3
cellGrid.append(Cell(what, cost))
return cellGrid
This does work, but what I really want is cellGrid to be a 2d list, just like grid, except that it will contain cell objects intstead of a string. I would like to be able to acceess it as cellGrid[0][0].what for example. How should I accomplish this?