Name: Anonymous 2013-10-10 20:03
Hey /prog/rammers, I'm trying to make a Matrix of nodes in python.
so far I have a node class that reads as such:
class Node (object) :
def __init__(self, value):
self.north = None
self.east = None
self.south = None
self.west = None
self.value = value
def getNorth(self):
return self.north
def getSouth(self):
return self.south
def getEast(self):
return self.east
def getWest(self):
return self.west
def getValue(self):
return self.value
And a LinkedMatrix class that reads like this:
class LinkedMatrix(object):
def __init__(self, x, y, defaultValue):
''' create a new matrix with x columns and y rows
with default value default value'''
self._xRows = x
# x amt of rows
self._yCols = y
# y amt of columns
base_node=Node(defaultValue)
self.head = Node(defaultValue)
self.mlist = []
self.head.east=base_node
self.mlist = [self.head]
for number in range(self._yCols):
base_node.east=Node(defaultValue)
self.mlist = self.mlist + [base_node]
Im thinking I should make a list of the nodes in python and then make a list of lists, but Im having trouble wording my code so that the nodes properly connect to each other, and I also am wondering how I can make their connections (north and south) work across different lists.
Help is very needed and would be very appreciated.
so far I have a node class that reads as such:
class Node (object) :
def __init__(self, value):
self.north = None
self.east = None
self.south = None
self.west = None
self.value = value
def getNorth(self):
return self.north
def getSouth(self):
return self.south
def getEast(self):
return self.east
def getWest(self):
return self.west
def getValue(self):
return self.value
And a LinkedMatrix class that reads like this:
class LinkedMatrix(object):
def __init__(self, x, y, defaultValue):
''' create a new matrix with x columns and y rows
with default value default value'''
self._xRows = x
# x amt of rows
self._yCols = y
# y amt of columns
base_node=Node(defaultValue)
self.head = Node(defaultValue)
self.mlist = []
self.head.east=base_node
self.mlist = [self.head]
for number in range(self._yCols):
base_node.east=Node(defaultValue)
self.mlist = self.mlist + [base_node]
Im thinking I should make a list of the nodes in python and then make a list of lists, but Im having trouble wording my code so that the nodes properly connect to each other, and I also am wondering how I can make their connections (north and south) work across different lists.
Help is very needed and would be very appreciated.