/// <summary> /// Gets the possible moves. /// </summary> /// <param name="currentLocation">The current location.</param> /// <param name="checkerBoard">The checker board.</param> /// <returns>List of possible moves</returns> public override List <CheckersMove> GetPossibleMoves(CheckersPoint currentLocation, CheckerBoard checkerBoard) { List <CheckersMove> list = new List <CheckersMove>(); //Can we go down the board? list.AddRange(ProcessDownMoves(currentLocation, checkerBoard)); //Can we go up the board? list.AddRange(ProcessUpMoves(currentLocation, checkerBoard)); return(list); }
/// <summary> /// Processes down moves. /// </summary> /// <param name="currentLocation">The current location.</param> /// <param name="checkerBoard">The checker board.</param> /// <returns>List of down moves</returns> protected List <CheckersMove> ProcessDownMoves(CheckersPoint currentLocation, CheckerBoard checkerBoard) { List <CheckersMove> list = new List <CheckersMove>(); //Can we go up the board? int rowBelow = currentLocation.Row + 1; if (rowBelow < 8) { //can we move to the right? list.AddRange(ProcessBoardHorizontal(currentLocation, checkerBoard, rowBelow, MoveDown, MoveRight)); // can we move to the left? list.AddRange(ProcessBoardHorizontal(currentLocation, checkerBoard, rowBelow, MoveDown, MoveLeft)); } return(ProcessJumpMoves(list)); }
/// <summary> /// Gets the possible moves. /// </summary> /// <param name="currentLocation">The current location.</param> /// <param name="checkerBoard">The checker board.</param> /// <returns> /// List of possible moves for this piece /// </returns> public override List <CheckersMove> GetPossibleMoves(CheckersPoint currentLocation, CheckerBoard checkerBoard) { return(ProcessDownMoves(currentLocation, checkerBoard)); }
/// <summary> /// Gets the possible moves. Null Checker Piece has no moves /// </summary> /// <param name="currentLocation">The current location.</param> /// <param name="checkerBoard">The checker board.</param> /// <returns>List of possible moves for this checkerpiece</returns> public override List <CheckersMove> GetPossibleMoves(CheckersPoint currentLocation, CheckerBoard checkerBoard) { return(new List <CheckersMove>()); }
/// <summary> /// Gets the possible moves. /// </summary> /// <param name="currentLocation">The current location.</param> /// <param name="checkerBoard">The checker board.</param> /// <returns>List of possible moves for this piece</returns> public abstract List <CheckersMove> GetPossibleMoves(CheckersPoint currentLocation, CheckerBoard checkerBoard);
/// <summary> /// Get all of the horizontal moves. The vertical moves are dependant on the vertical modifier. The direction of the hotizontal move is dependant on the modifier /// </summary> /// <param name="currentLocation">The current location.</param> /// <param name="checkerBoard">The checker board.</param> /// <param name="oneAdjacentRow">The one adjacent row.</param> /// <param name="verticalModifier">The vertical modifier.</param> /// <param name="horizontalModifier">The horizontal modifier.</param> /// <returns>List of moves</returns> private List <CheckersMove> ProcessBoardHorizontal(CheckersPoint currentLocation, CheckerBoard checkerBoard, int oneAdjacentRow, int verticalModifier, int horizontalModifier) { List <CheckersMove> list = new List <CheckersMove>(); int adjacentCol = currentLocation.Column + (1 * horizontalModifier); //Check our bounds if (adjacentCol >= 0 && adjacentCol < 8) { CheckerPiece possibleCheckerOnPossiblePoint = checkerBoard.BoardArray[oneAdjacentRow][adjacentCol].CheckersPoint.Checker; if (possibleCheckerOnPossiblePoint == null || possibleCheckerOnPossiblePoint is NullCheckerPiece) { //we can go here list.Add(new CheckersMove(currentLocation, new CheckersPoint(oneAdjacentRow, adjacentCol))); } else { //can we jump this guy? if ((possibleCheckerOnPossiblePoint is IRedPiece && this is IBlackPiece) || (possibleCheckerOnPossiblePoint is IBlackPiece && this is IRedPiece)) { //go another row up and another column to the right int twoAdjacentRow = oneAdjacentRow + (1 * verticalModifier); int twoColAdjacent = adjacentCol + (1 * horizontalModifier); //Check bounds if (twoColAdjacent >= 0 && twoColAdjacent < 8 && twoAdjacentRow >= 0 && twoAdjacentRow < 8) { CheckerPiece possibleCheckerOnPossibleJumpPoint = checkerBoard.BoardArray[twoAdjacentRow][twoColAdjacent].CheckersPoint.Checker; if (possibleCheckerOnPossibleJumpPoint == null || possibleCheckerOnPossibleJumpPoint is NullCheckerPiece) { //we can go here CheckersMove jumpMove = new CheckersMove(currentLocation, new CheckersPoint(twoAdjacentRow, twoColAdjacent), new CheckersPoint(oneAdjacentRow, adjacentCol)); //This is a jump move //Get all possible moves for destination point //For each possible move that is a jump move, make a new move and link it //make the move on a temp clone of the board and pass that to find any more multimoves CheckerBoard clonedBoard = (CheckerBoard)checkerBoard.GetMinimaxClone(); clonedBoard.MakeMoveOnBoard((CheckersMove)jumpMove.GetMinimaxClone(), false); List <CheckersMove> movesAfterJump = this.GetPossibleMoves(jumpMove.DestinationPoint, clonedBoard); List <CheckersMove> processedList = GetJumpMoves(movesAfterJump); if (processedList.Count > 0) { foreach (CheckersMove move in processedList) { CheckersMove clonedMove = (CheckersMove)jumpMove.GetMinimaxClone(); clonedMove.NextMove = move; list.Add(clonedMove); } } else { list.Add(jumpMove); } } } } } } return(list); }