public Direction getDirection(GameBoard board) { if (!board.Equals(board.move(Direction.Up))) { return Direction.Up; } else if (!board.Equals(board.move(Direction.Left))) { return Direction.Left; } else if (!board.Equals(board.move(Direction.Right))) { return Direction.Right; } else if (!board.Equals(board.move(Direction.Down))) { return Direction.Down; } else { return Direction.None; } }
public void compressLeft() { GameBoard board = new GameBoard(new int[,]{ {2, 2, 0, 0}, {0, 2, 2 , 2}, {0, 0, 4 , 8}, {0, 0, 4 , 4} } ); GameBoard actual = board.move(Direction.Left); GameBoard expected = new GameBoard(new int[,]{ {4, 0, 0, 0}, {4, 2, 0 , 0}, {4, 8, 0 , 0}, {8, 0, 0 , 0} } ); Assert.IsTrue(expected.Equals(actual)); }
public void compressDown() { GameBoard board = new GameBoard(new int[,]{ {2, 2, 0, 0}, {0, 2, 2 , 0}, {0, 2, 4 , 8}, {0, 0, 4 , 4} } ); GameBoard actual = board.move(Direction.Down); board.print(); GameBoard expected = new GameBoard(new int[,]{ {0, 0, 0, 0}, {0, 0, 0, 0}, {0, 2, 2, 8}, {2, 4, 8, 4} } ); Assert.IsTrue(expected.Equals(actual)); }
public void compressRight() { GameBoard board = new GameBoard(new int[,]{ {2, 2, 2, 0}, {0, 2, 2 , 0}, {0, 0, 4 , 8}, {0, 0, 4 , 4} } ); GameBoard actual = board.move(Direction.Right); GameBoard expected = new GameBoard(new int[,]{ {0, 0, 2, 4}, {0, 0, 0, 4}, {0, 0, 4 , 8}, {0, 0, 0 , 8} } ); Assert.IsTrue(expected.Equals(actual)); }