/// <summary> /// Makes the move on the board. /// </summary> /// <param name="moveToMake">The move to make.</param> /// <param name="swapTurn">if set to <c>true</c> [swap turn].</param> /// <returns>true if the current turn was finished</returns> public bool MakeMoveOnBoard(CheckersMove moveToMake, bool swapTurn) { CheckersPoint moveSource = moveToMake.SourcePoint; CheckersPoint moveDestination = moveToMake.DestinationPoint; //was this a cancel? if (moveSource != moveDestination) { CheckersPoint realDestination = this.BoardArray[moveDestination.Row][moveDestination.Column].CheckersPoint; CheckersPoint realSource = this.BoardArray[moveSource.Row][moveSource.Column].CheckersPoint; realDestination.Checker = (CheckerPiece)realSource.Checker.GetMinimaxClone(); realSource.Checker = CheckerPieceFactory.GetCheckerPiece(CheckerPieceType.nullPiece); //was this a jump move? CheckersPoint jumpedPoint = moveToMake.JumpedPoint; if (jumpedPoint != null) { //delete the checker piece that was jumped CheckersSquareUserControl jumpedSquareUserControl = this.BoardArray[jumpedPoint.Row][jumpedPoint.Column]; jumpedSquareUserControl.CheckersPoint.Checker = CheckerPieceFactory.GetCheckerPiece(CheckerPieceType.nullPiece); jumpedSquareUserControl.UpdateSquare(); } //Is this piece a king now? if (!(realDestination.Checker is KingCheckerPiece) && (realDestination.Row == 7 || realDestination.Row == 0)) { //Should be a king now if (realDestination.Checker is IRedPiece) { realDestination.Checker = new RedKingCheckerPiece(); } else { realDestination.Checker = new BlackKingCheckerPiece(); } } //Is this players turn over? if (moveToMake.NextMove == null && swapTurn) { //Swap the current players turn SwapTurns(); return(true); } else { return(false); } } return(false); }
/// <summary> /// Makes a move on the User Interface. /// </summary> /// <param name="moveToMake">The move to make.</param> /// <returns>Make Move Model Return. This model has two boolean properties that represent what happened this move</returns> private MakeMoveReturnModel MakeMove(CheckersMove moveToMake) { bool moveWasMade = false; bool isTurnOver = false; CheckersPoint source = moveToMake.SourcePoint; CheckersPoint destination = moveToMake.DestinationPoint; Logger.Info("Piece1 " + source.Row + ", " + source.Column); Logger.Info("Piece2 " + destination.Row + ", " + destination.Column); //was this a cancel? if (source != destination) { isTurnOver = checkerBoard.MakeMoveOnBoard(moveToMake); CheckersSquareUserControl sourceUC = checkerBoard.BoardArray[source.Row][source.Column]; CheckersSquareUserControl destUC = checkerBoard.BoardArray[destination.Row][destination.Column]; //Use dispatcher to run the Update method on the UI thread sourceUC.UpdateSquare(); destUC.UpdateSquare(); moveWasMade = true; //check for a winner object winner = checkerBoard.GetWinner(); if (winner != null && winner is PlayerColor winnerColor && !Settings.RunningGeneticAlgo) { MessageBox.Show("Winner Winner Chicken Dinner: " + winnerColor); } } ColorBackgroundOfPoints(currentAvailableMoves, Brushes.Black); SetTitle(string.Format("Checkers! {0}'s turn!", checkerBoard.CurrentPlayerTurn)); EnableButtonsWithMove(); currentMove = null; return(new MakeMoveReturnModel() { IsTurnOver = isTurnOver, WasMoveMade = moveWasMade }); }