Apr-24-2022, 10:45 PM
(Apr-24-2022, 07:14 PM)deanhystad Wrote: Is this correct?
Node_Start = Node(S, [6, 3, 1, 1]) Node_3 = Node(3, [7, 4, 1, S])It think your board is still riddled with errors. You would be better off making the wall programmatically. You make too many mistakes when doing it by hand.
This is how I make my board. I use dictionaries instead of arrays
class Action(Enum): """Enumeration for movements (actions). Value is (row, column) steps to make move""" UP = (1, 0) RIGHT = (0, 1) DOWN = (-1, 0) LEFT = (0, -1) def __str__(self): """Return arrow associated with action"""" if self is self.LEFT: return '\u2190' elif self is self.UP: return '\u2191' elif self is self.RIGHT: return '\u2192' elif self is self.DOWN: return '\u2193' return " " class Board: def __init__(self, goals, traps, walls, rows=4, columns=4): """Initialize the board""" # Make all the tiles self.rows = rows self.columns = columns self.tiles = {x:Tile(x, x in goals, x in traps, x in walls) for x in range(1, rows*columns+1)} # Tell open tiles about their neighbors for label in set(self.tiles) - set(goals + traps + walls): tile = self.tiles[label] for action in Action: r, c = action.value neighbor = self.tile(r + (label-1) // columns, c + (label-1) % columns) # Make a list of neighboring tiles tile.neighbor[action] = neighbor if neighbor and not neighbor.wall tile.values[action] = 1 if neighbor and neighbor.wall else 0 def tile(self, label, column): """Return tile at intersection of row and column. Return None if row or column out of range""" if 0 <= label < self.rows and 0 <= column < self.columns: return self.tiles[label * self.columns + column + 1] return None
Node_Start = Node(S, [6, 3, 1, 1])
Node_3 = Node(3, [7, 4, 1, S])
This is correct. However, does the new Board print out according to the outputs? Thank you!