public void MovePiecesWithinBoardLarge() { int width = 4; int height = 4; int[] boardConnection = new int[] { 0, 1, 1, 0, 1, 0, 0, 1, 0, 1, 0, 1, 1, 0, 1, 0 }; int[] expectedBoard = new int[] { 0, 1, 1, 0, 0, 1, 0, 1, 0, 1, 0, 1, 1, 0, 1, 0 }; BoardLogic boardLogic = new BoardLogic(width, height); boardLogic.SetBoard(boardConnection, width, height); bool canMove = boardLogic.CanMove(0, 1, 1, 0).canMove; Assert.AreEqual(true, canMove); if (canMove) { boardLogic.MovePiece(0, 1, 1, 0); } Assert.AreEqual(expectedBoard, boardLogic.GetBoard()); }
public void BecomesNegativeOnMovePieceAndClear() { int width = 4; int height = 4; int[] boardConnection = new int[] { 2, 1, 1, 0, 1, 2, 0, 0, 2, 1, 0, 0, 2, 1, 0, 0 }; int[] moveExpectedBoard = new int[] { 2, 1, 1, 0, 2, 1, 0, 0, 2, 1, 0, 0, 2, 1, 0, 0 }; int[] clearExpectedBoard = new int[] { -1, -1, -1, 0, -1, -1, 0, 0, -1, -1, 0, 0, -1, -1, 0, 0 }; BoardLogic boardLogic = new BoardLogic(width, height); boardLogic.SetBoard(boardConnection, width, height); int orginX = 0; int orginY = 1; int dirX = 1; int dirY = 0; int orginType = boardLogic.GetBoard()[orginX + orginY * width]; bool canMove = boardLogic.CanMove(orginX, orginY, dirX, dirY).canMove; Assert.AreEqual(true, canMove); if (canMove) { int destinationX = orginX + dirX; int destinationY = orginY + dirY; int oldType = boardLogic.GetBoard()[destinationX + destinationY * width]; boardLogic.MovePiece(orginX, orginY, dirX, dirY); Assert.AreEqual(moveExpectedBoard, boardLogic.GetBoard()); boardLogic.ClearConnectedType(oldType, orginX, orginY); boardLogic.ClearConnectedType(orginType, destinationX, destinationY); } Assert.AreEqual(clearExpectedBoard, boardLogic.GetBoard()); }
public void ClearConnectedType() { int width = 3; int height = 3; int[] boardConnection = new int[] { 0, 1, 1, 1, 0, 0, 0, 0, 0 }; BoardLogic boardLogic = new BoardLogic(width, height); boardLogic.SetBoard(boardConnection, width, height); bool canMove = boardLogic.CanMove(0, 1, 0, -1).canMove; Assert.AreEqual(true, canMove); if (canMove) { boardLogic.MovePiece(0, 1, 0, -1); boardLogic.ClearConnectedType(1, 0, 0); } Assert.AreEqual(new int[] { -1, -1, -1, 0, 0, 0, 0, 0, 0 }, boardLogic.GetBoard()); }
private void StateReducer() { switch (boardState) { case END_GAME_DELAY: if (Time.time - startDelayCounter > endDelay) { ActionDispatcher.DispatchEndGame(totdalPoints); boardState = "-"; } break; case START_DELAY: if (Time.time - startDelayCounter > startDelay) { boardState = INITIAL; } break; case INITIAL: canMove = true; time -= Time.deltaTime; timeDisplay.text = time.ToString(TIME_SCHEME); if (time <= 0) { canMove = false; boardState = "-"; donePanel.gameObject.SetActive(true); fadeChanger.gameObject.SetActive(true); if (onTimeDone != null) { onTimeDone(); } startDelayCounter = Time.time; boardState = END_GAME_DELAY; } break; case FAKE_MOVE: if (tweeningPiece.Count == 0) { boardState = INITIAL; } break; case FIRST_PIECE_TWEEN: if (tweeningPiece.Count == 0) { boardState = CLEAR_BOARD; } break; case CLEAR_BOARD: boardLogic.MovePiece(boardClearSolution.orgX, boardClearSolution.orgY, boardClearSolution.dirX, boardClearSolution.dirY); if (boardLogic.CanMove(boardClearSolution.orgX, boardClearSolution.orgY, 0, 0).canMove) { boardLogic.ClearConnectedType(boardClearSolution.oldType, boardClearSolution.orgX, boardClearSolution.orgY); } boardLogic.ClearConnectedType(boardClearSolution.orginType, boardClearSolution.destiX, boardClearSolution.destiY); boardState = CLEAR_BOARD_TWEEN; delayer = Time.time + waitDelay; int[] board = boardLogic.GetBoard(); int pointsToAdd = 0; for (int i = 0; i < board.Length; i++) { if (board[i] == -1) { int y = Mathf.FloorToInt(i / width); int x = i - (y * width); ShrinkPiece(x, y); pointsToAdd += i * 23; } } totdalPoints += pointsToAdd; break; case CLEAR_BOARD_TWEEN: if (tweeningPiece.Count == 0) { if (delayer - Time.time < 0) { boardState = SHIFT_DOWN; pointsDisplay.text = totdalPoints.ToString(); } } break; case SHIFT_DOWN: ShiftPiecesDown(); boardLogic.ShiftPiecesDown(); boardState = SHIFT_DOWN_TWEEN; delayer = Time.time + waitDelay; break; case SHIFT_DOWN_TWEEN: if (tweeningPiece.Count == 0) { if (delayer - Time.time < 0) { boardState = FILL_BOARD; } } break; case FILL_BOARD: RefillBoard(); boardState = STAY_DROPDOWN_ANIMATION; delayer = Time.time + waitDelay; break; case STAY_DROPDOWN_ANIMATION: if (tweeningPiece.Count == 0) { if (delayer - Time.time < 0) { boardState = INITIAL; } } break; } }
public void TestFullPieceMoveToRefillCycle() { int width = 4; int height = 4; int[] boardConnection = new int[] { 0, 0, 0, 0, 0, 0, 0, 0, 2, 1, 1, 1, 1, 2, 2, 2 }; int[] moveExpectedBoard = new int[] { 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 2, 2, 2, 2 }; int[] clearExpectedBoard = new int[] { 0, 0, 0, 0, 0, 0, 0, 0, -1, -1, -1, -1, -1, -1, -1, -1 }; int[] shiftBoardExpected = new int[] { -1, -1, -1, -1, -1, -1, -1, -1, 0, 0, 0, 0, 0, 0, 0, 0 }; BoardLogic boardLogic = new BoardLogic(width, height); boardLogic.SetBoard(boardConnection, width, height); int orginX = 0; int orginY = 2; int dirX = 0; int dirY = 1; int orginType = boardLogic.GetBoard()[orginX + orginY * width]; bool canMove = boardLogic.CanMove(orginX, orginY, dirX, dirY).canMove; Assert.AreEqual(true, canMove); if (canMove) { int destinationX = orginX + dirX; int destinationY = orginY + dirY; int oldType = boardLogic.GetBoard()[destinationX + destinationY * width]; boardLogic.MovePiece(orginX, orginY, dirX, dirY); Assert.AreEqual(moveExpectedBoard, boardLogic.GetBoard()); boardLogic.ClearConnectedType(oldType, orginX, orginY); boardLogic.ClearConnectedType(orginType, destinationX, destinationY); Assert.AreEqual(clearExpectedBoard, boardLogic.GetBoard()); boardLogic.ShiftPiecesDown(); Assert.AreEqual(shiftBoardExpected, boardLogic.GetBoard()); boardLogic.RefillBoard(); int[] board = boardLogic.GetBoard(); bool hasNegative = false; for (int i = 0; i < board.Length; i++) { if (board[i] < 0) { hasNegative = true; } } Assert.AreEqual(false, hasNegative); } }