private void addLocationToCell(PossibleMove?i_Cell, ref List <PossibleMove?> i_ListOfPossibleMoves) { bool cellFound = false; PossibleMove?newMove; if (i_Cell != null) { // Checks if the cell is already in the possible move list foreach (PossibleMove?move in i_ListOfPossibleMoves) { if (move.Value.isEqualToPoisition(i_Cell.Value.X, i_Cell.Value.Y)) { eDirection direction = new eDirection(); direction = i_Cell.Value.Direction; direction |= move.Value.Direction; cellFound = true; newMove = new PossibleMove(i_Cell.Value.X, i_Cell.Value.Y, direction); i_ListOfPossibleMoves.Remove(move); i_ListOfPossibleMoves.Add(newMove); break; } } // If the cell is not in the list we add it. if (!cellFound) { i_ListOfPossibleMoves.Add(i_Cell); } } }
// Get a possible move from cell to direction private PossibleMove?getPossibleCellFromDirection(int i_XCoord, int i_YCoord, eDirection i_Direction, Player i_Player) { int boardRow = 0, boardCol = 0; PossibleMove?possibleMove = null; bool foundSpaceToPlaceNewMove = false; bool inBoundsOfBoard = true; getDirectionRowAndColumn(ref boardRow, ref boardCol, i_Direction); // we want to search for an empty spot because we know theres already an opponent sign near us while (!foundSpaceToPlaceNewMove && inBoundsOfBoard) { i_XCoord += boardRow; i_YCoord += boardCol; // Checks if coordinates still in bound of the board inBoundsOfBoard = m_Board.IsCoordinatesInBounds(i_XCoord, i_YCoord); if (!inBoundsOfBoard) { break; } else if (m_Board[i_XCoord, i_YCoord].Color == i_Player.Color) { break; } else if (m_Board[i_XCoord, i_YCoord].Color == Color.Empty || m_Board[i_XCoord, i_YCoord].Color == Color.Gray) { foundSpaceToPlaceNewMove = true; } } // if we found a new place, create a new coordinate array and return it if (foundSpaceToPlaceNewMove) { possibleMove = new PossibleMove(i_XCoord, i_YCoord, getOppositeDirection(i_Direction)); } return(possibleMove); }
// Draw a move of a player private void drawPossibleMove(PossibleMove? i_PossibleMove, Player i_Player) { if (i_PossibleMove != null) { // Drawing line for each direction in the possible move and update the board string[] directionsStringArray = i_PossibleMove.Value.Direction.ToString().Split(new[] { ", " }, StringSplitOptions.None); foreach (string directionStr in directionsStringArray) { eDirection direction = (eDirection)System.Enum.Parse(typeof(eDirection), directionStr); drawLineFromCellInDirection(i_PossibleMove.Value.X, i_PossibleMove.Value.Y, direction, i_Player); } } }
// Get a possible move from cell to direction private PossibleMove? getPossibleCellFromDirection(int i_XCoord, int i_YCoord, eDirection i_Direction, Player i_Player) { int boardRow = 0, boardCol = 0; PossibleMove? possibleMove = null; bool foundSpaceToPlaceNewMove = false; bool inBoundsOfBoard = true; getDirectionRowAndColumn(ref boardRow, ref boardCol, i_Direction); // we want to search for an empty spot because we know theres already an opponent sign near us while (!foundSpaceToPlaceNewMove && inBoundsOfBoard) { i_XCoord += boardRow; i_YCoord += boardCol; // Checks if coordinates still in bound of the board inBoundsOfBoard = m_Board.IsCoordinatesInBounds(i_XCoord, i_YCoord); if (!inBoundsOfBoard) { break; } else if (m_Board[i_XCoord, i_YCoord].Color == i_Player.Color) { break; } else if (m_Board[i_XCoord, i_YCoord].Color == Color.Empty || m_Board[i_XCoord, i_YCoord].Color == Color.Gray) { foundSpaceToPlaceNewMove = true; } } // if we found a new place, create a new coordinate array and return it if (foundSpaceToPlaceNewMove) { possibleMove = new PossibleMove(i_XCoord, i_YCoord, getOppositeDirection(i_Direction)); } return possibleMove; }
private void addLocationToCell(PossibleMove? i_Cell, ref List<PossibleMove?> i_ListOfPossibleMoves) { bool cellFound = false; PossibleMove? newMove; if (i_Cell != null) { // Checks if the cell is already in the possible move list foreach (PossibleMove? move in i_ListOfPossibleMoves) { if (move.Value.isEqualToPoisition(i_Cell.Value.X, i_Cell.Value.Y)) { eDirection direction = new eDirection(); direction = i_Cell.Value.Direction; direction |= move.Value.Direction; cellFound = true; newMove = new PossibleMove(i_Cell.Value.X, i_Cell.Value.Y, direction); i_ListOfPossibleMoves.Remove(move); i_ListOfPossibleMoves.Add(newMove); break; } } // If the cell is not in the list we add it. if (!cellFound) { i_ListOfPossibleMoves.Add(i_Cell); } } }