Skip to content

Commit

Permalink
Fixed projectmesa#293. It was indeed x-y ordering issuse due to new a…
Browse files Browse the repository at this point in the history
…rgument order.
  • Loading branch information
Jeetu committed Jul 19, 2016
1 parent 81984f9 commit 24f9226
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 16 deletions.
16 changes: 8 additions & 8 deletions examples/ColorPatches/color_patches/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ def __init__(self, pos, model, initial_state):
Create a cell, in the given state, at the given row, col position.
'''
Agent.__init__(self, pos, model)
self._row = pos[1]
self._col = pos[0]
self._row = pos[0]
self._col = pos[1]
self._state = initial_state
self._next_state = None

Expand All @@ -47,7 +47,7 @@ def step(self, model):
A choice is made at random in case of a tie
The next state is stored until all cells have been polled
'''
neighbor_iter_ = model.grid.neighbor_iter((self._col, self._row), True)
neighbor_iter_ = model.grid.neighbor_iter((self._row, self._col), True)
neighbors_opinion = Counter(n.get_state() for n in neighbor_iter_)
# Following is a a tuple (attribute, occurrences)
polled_opinions = neighbors_opinion.most_common()
Expand All @@ -71,24 +71,24 @@ class ColorPatchModel(Model):
represents a 2D lattice where agents live
'''

def __init__(self, height, width):
def __init__(self, width, height):
'''
Create a 2D lattice with strict borders where agents live
The agents next state is first determined before updating the grid
'''

self._grid = Grid(height, width, torus=False)
self._grid = Grid(width, height, torus=False)
self._schedule = SimultaneousActivation(self)

# self._grid.coord_iter()
# --> should really not return content + col + row
# -->but only col & row
# for (contents, col, row) in self._grid.coord_iter():
# replaced content with _ to appease linter
for (_, col, row) in self._grid.coord_iter():
cell = ColorCell((col, row), self,
for (_, row, col) in self._grid.coord_iter():
cell = ColorCell((row, col), self,
ColorCell.OPINIONS[random.randrange(0, 16)])
self._grid.place_agent(cell, (col, row))
self._grid.place_agent(cell, (row, col))
self._schedule.add(cell)

self.running = True
Expand Down
16 changes: 8 additions & 8 deletions examples/ColorPatches/color_patches/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,11 @@
'Red', 'Silver', 'Teal', 'White', 'Yellow']


GRID_ROWS = 25
GRID_COLS = 50
GRID_ROWS = 50
GRID_COLS = 25
CELL_SIZE = 10
CANVAS_HEIGHT = GRID_ROWS * CELL_SIZE
CANVAS_WIDTH = GRID_COLS * CELL_SIZE
CANVAS_WIDTH = GRID_ROWS * CELL_SIZE
CANVAS_HEIGHT = GRID_COLS * CELL_SIZE


def color_patch_draw(cell):
Expand All @@ -33,15 +33,15 @@ def color_patch_draw(cell):
'''
assert cell is not None
portrayal = {"Shape": "rect", "w": 1, "h": 1, "Filled": "true", "Layer": 0}
portrayal["x"] = cell.get_col()
portrayal["y"] = cell.get_row()
portrayal["x"] = cell.get_row()
portrayal["y"] = cell.get_col()
portrayal["Color"] = _COLORS[cell.get_state()]
return portrayal


CANVAS_ELEMENT = CanvasGrid(color_patch_draw,
GRID_COLS, GRID_ROWS,
CANVAS_HEIGHT, CANVAS_WIDTH)
GRID_ROWS, GRID_COLS,
CANVAS_WIDTH, CANVAS_HEIGHT)

server = ModularServer(ColorPatchModel,
[CANVAS_ELEMENT], "Color Patches",
Expand Down

0 comments on commit 24f9226

Please sign in to comment.