private static Constant.GameState CheckColumns(CellManager cm, IMarker m, Constant.GameState currentGameState) { Constant.GameState result = currentGameState; if (result == Constant.GameState.Win) { return(result); } for (int column = 0; column < Constant.GridSize; column++) { int cnt = 0; for (int row = 0; row < Constant.GridSize; row++) { if (cm.Grid[row, column].Marker != null && cm.Grid[row, column].Marker.Equals(m)) { cnt++; } } if (cnt == Constant.GridSize) { return(Constant.GameState.Win); } } return(result); }
public YatttgModel() { // Initialize default values. p1_ = null; p2_ = null; // Give Nort and Cross default values. Nort = new Nort(); Cross = new Cross(); cm_ = new CellManager(); // Initial state is to get player information. currentGameState_ = Constant.GameState.PlayerInfo; }
private static Constant.GameState CheckDiagonals(CellManager cm, IMarker m, Constant.GameState currentGameState) { Constant.GameState result = currentGameState; if (result == Constant.GameState.Win) { return(result); } int cnt = 0; // Check leading diagonal. for (int i = 0; i < Constant.GridSize; i++) { if (cm.Grid[i, i].Marker != null && cm.Grid[i, i].Marker.Equals(m)) { cnt++; } } if (cnt == Constant.GridSize) { return(Constant.GameState.Win); } else { // Reset the counter, check antidiagonal. cnt = 0; for (int i = 0; i < Constant.GridSize; i++) { if (cm.Grid[i, Constant.GridSize - 1 - i].Marker != null && cm.Grid[i, Constant.GridSize - 1 - i].Marker.Equals(m)) { cnt++; } } if (cnt == Constant.GridSize) { return(Constant.GameState.Win); } } // No result was found on the diagonals. return(result); }
internal static Constant.GameState CheckGridForWinner(CellManager cm, IMarker m, Constant.GameState currentGameState) { Constant.GameState result = currentGameState; // Check winning conditions for the newly created move if (cm.AllocCount == Constant.MaxOptions) result = Constant.GameState.Tie; else { // We only need to check the grid for the marker that has // just been placed down. result = CheckRows(cm, m, result); result = CheckColumns(cm, m, result); result = CheckDiagonals(cm, m, result); } return result; }
internal static Constant.GameState CheckGridForWinner(CellManager cm, IMarker m, Constant.GameState currentGameState) { Constant.GameState result = currentGameState; // Check winning conditions for the newly created move if (cm.AllocCount == Constant.MaxOptions) { result = Constant.GameState.Tie; } else { // We only need to check the grid for the marker that has // just been placed down. result = CheckRows(cm, m, result); result = CheckColumns(cm, m, result); result = CheckDiagonals(cm, m, result); } return(result); }
private static Constant.GameState CheckDiagonals(CellManager cm, IMarker m, Constant.GameState currentGameState) { Constant.GameState result = currentGameState; if (result == Constant.GameState.Win) return result; int cnt = 0; // Check leading diagonal. for (int i = 0; i < Constant.GridSize; i++) { if (cm.Grid[i, i].Marker != null && cm.Grid[i, i].Marker.Equals(m)) cnt++; } if (cnt == Constant.GridSize) return Constant.GameState.Win; else { // Reset the counter, check antidiagonal. cnt = 0; for (int i = 0; i < Constant.GridSize; i++) { if (cm.Grid[i, Constant.GridSize - 1 - i].Marker != null && cm.Grid[i, Constant.GridSize - 1 - i].Marker.Equals(m)) cnt++; } if (cnt == Constant.GridSize) return Constant.GameState.Win; } // No result was found on the diagonals. return result; }
private static Constant.GameState CheckColumns(CellManager cm, IMarker m, Constant.GameState currentGameState) { Constant.GameState result = currentGameState; if (result == Constant.GameState.Win) return result; for (int column = 0; column < Constant.GridSize; column++) { int cnt = 0; for (int row = 0; row < Constant.GridSize; row++) { if (cm.Grid[row, column].Marker != null && cm.Grid[row, column].Marker.Equals(m)) cnt++; } if (cnt == Constant.GridSize) return Constant.GameState.Win; } return result; }