private void checkDiagnol( ref int io_CountFourInDiagnol, ref bool io_FoundFour, ref eGameSigns io_VictorySign, int i_IndexI, int i_IndexJ, eGameSigns i_CurrentDiagnolSign, bool i_IsDownDiagnol) { int rowToCheck = 0; for (int k = 1; k < 4; k++) { rowToCheck = i_IndexI + (i_IsDownDiagnol ? k : -k); /// Check if out of bounds if (rowToCheck > m_Board.GetLength(0) - 1 || i_IndexJ + k > m_Board.GetLength(1) - 1 || rowToCheck < 0) { io_CountFourInDiagnol = 0; break; } else if (m_Board[rowToCheck, i_IndexJ + k] == i_CurrentDiagnolSign && i_CurrentDiagnolSign != eGameSigns.Empty) { io_CountFourInDiagnol++; } else { io_CountFourInDiagnol = 0; } if (checkIfFourAndUpdateVictorySign(io_CountFourInDiagnol, ref io_FoundFour, ref io_VictorySign, i_CurrentDiagnolSign)) { break; } } }
private bool isFourInColumn() { int countFourInAColumn = 0; bool foundFour = false; eGameSigns victorySign = eGameSigns.Empty; for (int i = 0; i < m_Board.GetLength(1); i++) { for (int j = 0; j < m_Board.GetLength(0) - 1; j++) { if (m_Board[j, i] == m_Board[j + 1, i] && m_Board[j, i] != eGameSigns.Empty) { countFourInAColumn++; } else { countFourInAColumn = 0; } if (checkIfFourAndUpdateVictorySign(countFourInAColumn, ref foundFour, ref victorySign, m_Board[j, i])) { break; } } if (foundFour) { break; } countFourInAColumn = 0; } return(updateWinnerIfFound(foundFour, victorySign)); }
private bool isFourInDiagnol() { int countFourInDiagnol = 0; bool foundFour = false; const bool v_IsDownward = true; eGameSigns victorySign = eGameSigns.Empty; for (int i = 0; i < m_Board.GetLength(0); i++) { for (int j = 0; j < m_Board.GetLength(1); j++) { /// Down Diagnol eGameSigns currentDiagnolSign = m_Board[i, j]; checkDiagnol(ref countFourInDiagnol, ref foundFour, ref victorySign, i, j, currentDiagnolSign, v_IsDownward); /// Up Diagnol checkDiagnol(ref countFourInDiagnol, ref foundFour, ref victorySign, i, j, currentDiagnolSign, !v_IsDownward); if (foundFour) { break; } } if (foundFour) { break; } } return(updateWinnerIfFound(foundFour, victorySign)); }
private bool updateWinnerIfFound(bool i_FoundFour, eGameSigns i_VictorySign) { if (i_FoundFour) { m_LastWinner = i_VictorySign == eGameSigns.FirstPlayer ? eWinner.FirstPlayer : eWinner.SecondPlayer; } return(i_FoundFour); }
private bool checkIfFourAndUpdateVictorySign( int i_CountFourInARow, ref bool io_FoundFour, ref eGameSigns io_VictorySign, eGameSigns i_CurrentSign) { /// Means we have 3 pairs if (i_CountFourInARow == 3) { io_FoundFour = true; io_VictorySign = i_CurrentSign; } return(io_FoundFour); }
public Player(bool i_IsHumanPlayer) { s_Score = k_Zero; isHumanPlayer = i_IsHumanPlayer; m_PlayerSign = (eGameSigns)k_CurrentPlayerNumber; if (isHumanPlayer) { m_PlayerName = UserInterface.AssignPlayerName(k_CurrentPlayerNumber); } else { m_PlayerName = "The Mighty PC"; } k_CurrentPlayerNumber++; }
private char parseEnumToPlayerSign(eGameSigns i_EGameSign) { char toReturn = ' '; switch (i_EGameSign) { case eGameSigns.FirstPlayer: toReturn = r_FirstPlayerSign; break; case eGameSigns.SecondPlayer: toReturn = r_SecondPlayerSign; break; } return(toReturn); }
public Cell() { eCellContent = eGameSigns.Empty; }
private string getBoardSymbol(int i_Row, int i_Col) { string symbol; eGameSigns sign = new eGameSigns(); sign = m_BoardMatrix[i_Row, i_Col].Content; if (sign.Equals(eGameSigns.Empty)) { symbol = " "; } else { symbol = sign.ToString(); } return symbol; }