Skip to content
Permalink
Browse files
Engine Converted
  • Loading branch information
ClayDowling committed Apr 15, 2017
1 parent 1943147 commit 535b90189c23df4c3a71bd78a3639cf6a35133ba
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 3 deletions.
@@ -21,3 +21,9 @@ I have partially transitions to using the new interface, in the tests for LifeBo
## Engine Tests Converted

The engine tests have been converted. Notice that they still take advantage of the fact that the board implementation is static. This is because the engine itself hasn't been converted.

## Engine Converted

Engine is the last class which was using the internal representation of the LifeBoard. Now it's converted to use only the defined interfaces.

By passing the LifeBoard to the constructor of the engine, I'm also removing the dependency on the static implementation of the board's storage. I verified that by removing the static storage class in LifeBoard.
@@ -3,13 +3,19 @@
*/
public class Engine {

private LifeBoard board;

public Engine(LifeBoard board) {
this.board = board;
}

int neighbors(int x, int y) {
int count = 0;

for(int i=-1; i < 2; ++i) {
for(int j=-1; j < 2; ++j) {
if (!(0 == i && 0 == j))
if (LifeBoard.value[x + i][y + j]) {
if (board.at(x + i, y + j) != 0) {
++count;
}
}
@@ -4,7 +4,7 @@
public class LifeBoard implements Board {
public static final int X_MAX = 50;
public static final int Y_MAX = 50;
static public boolean[][] value = new boolean[X_MAX][Y_MAX];
public boolean[][] value = new boolean[X_MAX][Y_MAX];


public void clear() {
@@ -17,8 +17,8 @@ public class EngineTest {

@Before
public void setUp() {
engine = new Engine();
board = new LifeBoard();
engine = new Engine(board);

board.clear();
}

0 comments on commit 535b901

Please sign in to comment.