//Checks a board state. Give it string parameters of "Row", "Column", "Diagonal", or "Draw". Dimension only matters for row and column checks //If Draw return a false, then something achieved victory private bool CheckBoardState(string check, int dimension) { if (check != "Row" && check != "Column" && check != "Diagonal" && check != "Draw") { Debug.LogError("Invalid board state to check"); return(false); } if (check == "Row") { if (BoardState.CheckRow(dimension, (int)GameManager.CurrentPlayer)) { return(true); } return(false); } else if (check == "Column") { if (BoardState.CheckColumn(dimension, (int)GameManager.CurrentPlayer)) { return(true); } return(false); } else if (check == "Diagonal") { if (BoardState.CheckBackDiagonal((int)GameManager.CurrentPlayer)) { return(true); } if (BoardState.CheckFrontDiagonal((int)GameManager.CurrentPlayer)) { return(true); } return(false); } else if (check == "Draw") { for (int i = 0; i < BoardState.BoardDimension; i++) { if (BoardState.CheckColumn(i, (int)GameManager.Player.P1) || BoardState.CheckRow(i, (int)GameManager.Player.P1) || BoardState.CheckColumn(i, (int)GameManager.Player.P2) || BoardState.CheckRow(i, (int)GameManager.Player.P2)) { return(false); } } if (BoardState.CheckBackDiagonal((int)GameManager.CurrentPlayer) || BoardState.CheckFrontDiagonal((int)GameManager.CurrentPlayer)) { return(false); } else { return(true); } } return(false); }
//Check both diagonals. Pass an int (from an Enum in Debugger) to determine which diagonal to select IEnumerator DiagonalTester(int diag) { //store the player we're measuring. The current player should be set to the one we want to check when pressing the button in Debugger. int playerCheck = (int)GameManager.CurrentPlayer; if (diag == (int)Debugger.DiagSelect.Front) { for (int col = 0; col < BoardState.BoardDimension; col++) { //wait yield return(new WaitForSeconds(timeBetweenMoves)); //get a row position int row = BoardState.BoardDimension - 1 - col; //set new position in diagonal AddTestPosition(row, col); //checks if we reached the end of the row and if so, checks diagonal if (BoardState.CheckFrontDiagonal((int)GameManager.CurrentPlayer)) { Debug.Log("Successfully logged a Front Diagonal Victory for Player :" + (int)GameManager.CurrentPlayer); GameManager.instance.GameFinishDebug(); yield break; } //switch player GameManager.instance.SwitchCurrentPlayer(); //wait yield return(new WaitForSeconds(timeBetweenMoves)); //set a position and tile for the other player right next the target player. Since this player goes second, they should never win int otherRow = (row - 1 >= 0) ? row - 1 : row + 1; AddTestPosition(otherRow, col); //switch GameManager.instance.SwitchCurrentPlayer(); } Debug.LogError("Failed to register a Front Diagonal victory for player " + playerCheck); GameManager.instance.DebugWindow("ERROR: \n No Diagonal Victory registered."); } if (diag == (int)Debugger.DiagSelect.Back) { for (int i = 0; i < BoardState.BoardDimension; i++) { yield return(new WaitForSeconds(timeBetweenMoves)); //set new position in diagonal AddTestPosition(i, i); //checks if we reached the end of the row and if so, checks diagonal if (BoardState.CheckBackDiagonal((int)GameManager.CurrentPlayer)) { Debug.Log("Successfully logged a Back Diagonal Victory for Player :" + (int)GameManager.CurrentPlayer); GameManager.instance.GameFinishDebug(); yield break; } //switch player GameManager.instance.SwitchCurrentPlayer(); //wait yield return(new WaitForSeconds(timeBetweenMoves)); //set a position and tile for the other player right next the target player. Since this player goes second, they should never win int otherI = (i + 1 >= BoardState.BoardDimension) ? i - 1 : i + 1; AddTestPosition(otherI, i); //switch player GameManager.instance.SwitchCurrentPlayer(); } Debug.LogError("Failed to register a Back Diagonal victory for player " + playerCheck); GameManager.instance.DebugWindow("ERROR: \n No Diagonal Victory registered."); } Debug.LogError("Invalid Diagonal Input" + playerCheck); GameManager.instance.DebugWindow("ERROR: \n Invalid Diagonal Input."); }