package hu.supercluster.gameoflife.game.transformer;

import hu.supercluster.gameoflife.game.cell.Cell;
import hu.supercluster.gameoflife.game.grid.Grid;

public class SimpleGridTransformer<T extends Cell> implements GridTransformer<T> {
    int stateChanges[][];

    @Override
    public final void transform(Grid<T> grid, Rule<T> rule) {
        stateChanges = new int[grid.getSizeY()][grid.getSizeX()];

        for (int j = 0; j < grid.getSizeY(); j++) {
            for (int i = 0; i < grid.getSizeY(); i++) {
                stateChanges[j][i] = rule.apply(grid, i, j);
            }
        }

        for (int j = 0; j < grid.getSizeY(); j++) {
            for (int i = 0; i < grid.getSizeY(); i++) {
                grid.getCell(i, j).setState(stateChanges[j][i]);
            }
        }
    }
}

@@ -235,35 +235,8 @@
 %3E %7B%0A
-    int stateChanges%5B%5D%5B%5D;%0A%0A
     
@@ -307,32 +307,36 @@
 rule) %7B%0A        
+int 
 stateChanges = n
@@ -331,16 +331,20 @@
 eChanges
+%5B%5D%5B%5D
  = new i
@@ -470,33 +470,33 @@
 i %3C grid.getSize
-Y
+X
 (); i++) %7B%0A     
@@ -668,25 +668,25 @@
 grid.getSize
-Y
+X
 (); i++) %7B%0A 

Fix SimpleGridTransformer working only when grid is square sized