Skip to content

Commit

Permalink
Engine Converted
Browse files Browse the repository at this point in the history
  • Loading branch information
ClayDowling committed Apr 15, 2017
1 parent 1943147 commit 535b901
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 3 deletions.
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
8 changes: 7 additions & 1 deletion src/main/java/Engine.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/LifeBoard.java
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
2 changes: 1 addition & 1 deletion src/test/java/EngineTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ public class EngineTest {

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

board.clear();
}
Expand Down

0 comments on commit 535b901

Please sign in to comment.