private int countSequenceOfEatableOpponentPieces(int i_BoardRow, int i_BoardColumn, Direction.eVertical i_VerticalDirection, Direction.eHorizontal i_HorizontalDirection) { int numberOfEatenOpponentPieces = 0; int nextRow = i_BoardRow; int nextColumn = i_BoardColumn; Player.ePlayerNumber opponentPlayer = m_CurrentGameState.CurrentPlayer.getOpponentPlayer(); while (isLocationInBoardRange(nextRow, nextColumn) && opponentPlayer == m_CurrentGameState.GameBoard[nextRow, nextColumn].OccupyingPlayer) { numberOfEatenOpponentPieces++; nextRow = nextRow + (int)i_VerticalDirection; nextColumn = nextColumn + (int)i_HorizontalDirection; } if (!isLocationInBoardRange(nextRow, nextColumn) || m_CurrentGameState.GameBoard[nextRow, nextColumn].OccupyingPlayer == Player.ePlayerNumber.None) { numberOfEatenOpponentPieces = 0; } return(numberOfEatenOpponentPieces); }
private void flipSurroundedOpponentPieces(int i_BoardRow, int i_BoardColumn, Direction.eVertical i_VerticalDirection, Direction.eHorizontal i_HorizontalDirection) { int nextRow = i_BoardRow + (int)i_VerticalDirection; int nextColumn = i_BoardColumn + (int)i_HorizontalDirection; Player.ePlayerNumber opponentPlayerNumber = m_CurrentGameState.CurrentPlayer.getOpponentPlayer(); // Check if move is valid in this direction int opponentPiecesSurroundedInDirection = getMoveValueInDirection(i_BoardRow, i_BoardColumn, i_VerticalDirection, i_HorizontalDirection); if (opponentPiecesSurroundedInDirection > 0) { while (m_CurrentGameState.GameBoard[nextRow, nextColumn].OccupyingPlayer == opponentPlayerNumber) { m_CurrentGameState.GameBoard.FlipCell(nextRow, nextColumn); nextRow = nextRow + (int)i_VerticalDirection; nextColumn = nextColumn + (int)i_HorizontalDirection; } } }
private int getMoveValueInDirection(int i_BoardRow, int i_BoardColumn, Direction.eVertical i_VerticalDirection, Direction.eHorizontal i_HorizontalDirection) { int moveValue = 0; int nextRow = i_BoardRow + (int)i_VerticalDirection; int nextColumn = i_BoardColumn + (int)i_HorizontalDirection; if (isLocationInBoardRange(nextRow, nextColumn)) { if (isLocationOccupiedByAnOpponent(nextRow, nextColumn)) { moveValue = countSequenceOfEatableOpponentPieces(nextRow, nextColumn, i_VerticalDirection, i_HorizontalDirection); } } return(moveValue); }