public int GetTurnOverList(int row, int column, bool playerOne, ref SquareList squareList) { var totalCnt = 0; if (!IsCanSelect(row, column)) { return(totalCnt); } var state = GetOpposingPlayerState(playerOne); if (PlayExistUp(row, column, playerOne)) { totalCnt += SearchUp(row, column, state, ref squareList); } if (PlayExistDown(row, column, playerOne)) { totalCnt += SearchDown(row, column, state, ref squareList); } if (PlayExistLeft(row, column, playerOne)) { totalCnt += SearchLeft(row, column, state, ref squareList); } if (PlayExistRight(row, column, playerOne)) { totalCnt += SearchRight(row, column, state, ref squareList); } if (PlayExistUpLeft(row, column, playerOne)) { totalCnt += SearchUpLeft(row, column, state, ref squareList); } if (PlayExistDownRight(row, column, playerOne)) { totalCnt += SearchDownRight(row, column, state, ref squareList); } if (PlayExistUpRight(row, column, playerOne)) { totalCnt += SearchUpRight(row, column, state, ref squareList); } if (PlayExistDownLeft(row, column, playerOne)) { totalCnt += SearchDownLeft(row, column, state, ref squareList); } return(totalCnt); }
public int SearchRight(int row, int column, int state, ref SquareList squareList) { int cnt, totalCnt = 0; for (cnt = column + 1; cnt < MaxSide; cnt++) { if (GetSquareState(row, cnt) == state) { squareList.AddNewSquare(row, cnt); totalCnt++; } else { break; } } return(totalCnt); }
public int SearchLeft(int row, int column, int state, ref SquareList squareList) { int cnt, totalCnt = 0; for (cnt = column - 1; cnt >= 0; cnt--) { if (GetSquareState(row, cnt) == state) { squareList.AddNewSquare(row, cnt); totalCnt++; } else { break; } } return(totalCnt); }
public int SearchDownLeft(int row, int column, int state, ref SquareList squareList) { int localRow, localColumn, totalCnt = 0; for (localRow = row + 1, localColumn = column - 1; (localRow > 0) && (localColumn > 0); localRow++, localColumn--) { if (GetSquareState(localRow, localColumn) == state) { squareList.AddNewSquare(localRow, localColumn); totalCnt++; } else { break; } } return(totalCnt); }
public bool SelectSquare(int row, int column, bool playerOne) { var squareList = new SquareList(); if (!IsCanSelect(row, column)) { return(false); } if (GetTurnOverList(row, column, playerOne, ref squareList) == 0) { return(false); } if (!ShowTurnOver) { SetSquareToPlayer(row, column, playerOne); } while (!squareList.AtEndOfList()) { squareList.GetSquare(out var localRow, out var localColumn); if (!ShowTurnOver) { SetSquareToPlayer(localRow, localColumn, playerOne); } else { if (GetSquareState(localRow, localColumn) != GetCurrentPlayerState(playerOne)) { SetSquareState(localRow, localColumn, StateTurnOver); } } squareList.GoToNextSquare(); } return(true); }