예제 #1
0
 /// <summary>
 /// Initializes a new instance of the <see cref="CheckersMove"/> class.
 /// </summary>
 /// <param name="sourcePoint">The source point.</param>
 /// <param name="destinationPoint">The destination point.</param>
 /// <param name="jumpedPoint">The jumped point.</param>
 /// <param name="nextMove">The next move.</param>
 public CheckersMove(CheckersPoint sourcePoint, CheckersPoint destinationPoint, CheckersPoint jumpedPoint, CheckersMove nextMove)
 {
     SourcePoint      = sourcePoint;
     DestinationPoint = destinationPoint;
     JumpedPoint      = jumpedPoint;
     NextMove         = nextMove;
 }
예제 #2
0
 /// <summary>
 /// Initializes a new instance of the <see cref="CheckersMove"/> class.
 /// </summary>
 /// <param name="sourcePoint">The source point.</param>
 /// <param name="destinationPoint">The destination point.</param>
 public CheckersMove(CheckersPoint sourcePoint, CheckersPoint destinationPoint)
 {
     SourcePoint      = sourcePoint;
     DestinationPoint = destinationPoint;
     JumpedPoint      = null;
     NextMove         = null;
 }
예제 #3
0
        /// <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);
        }
예제 #4
0
        /// <summary>
        /// Gets the minimax clone. For this class it is essentially a deep copy
        /// </summary>
        /// <returns>Minimax Clone of this class</returns>
        public object GetMinimaxClone()
        {
            CheckersPoint deepClone = new CheckersPoint()
            {
                Checker = (CheckerPiece)this.Checker.GetMinimaxClone(),
                Column  = this.Column,
                Row     = this.Row
            };

            return(deepClone);
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="CheckersSquareUserControl"/> class.
        /// </summary>
        /// <param name="backgroundColor">Color of the background.</param>
        /// <param name="checkersPoint">The checkers point.</param>
        /// <param name="routedEventHandler">The routed event handler.</param>
        public CheckersSquareUserControl(Brush backgroundColor, CheckersPoint checkersPoint, RoutedEventHandler routedEventHandler)
        {
            InitializeComponent();
            this.Background    = backgroundColor;
            this.CheckersPoint = checkersPoint;
            this.button.Click += routedEventHandler;

            UpdateSquare();

            //Debug TODO: Delete this when not needed anymore
            button.Content = "row: " + checkersPoint.Row + " , col: " + checkersPoint.Column;
        }
예제 #6
0
        /// <summary>
        /// Gets a move from the currently available moves list. This is important for user interaction.
        /// Todo: look into possible bug here if two moves have same destination. Might not matter
        /// </summary>
        /// <param name="checkersPoint">The destination</param>
        /// <returns>The detailed checkers move for this destination</returns>
        private CheckersMove GetMoveFromList(CheckersPoint checkersPoint)
        {
            foreach (CheckersMove move in currentAvailableMoves)
            {
                if (move.DestinationPoint.Equals(checkersPoint))
                {
                    return(move);
                }
            }

            return(null);
        }
예제 #7
0
        /// <summary>
        /// Enables the buttons with a valid move.
        /// </summary>
        private void EnableButtonsWithMove()
        {
            List <CheckersMove> totalPossibleMoves = checkerBoard.GetMovesForPlayer();

            foreach (CheckersMove move in totalPossibleMoves)
            {
                CheckersPoint source = move.SourcePoint;
                int           col    = source.Column;
                int           row    = source.Row;

                CheckersSquareUserControl sourceUserControl = checkerBoard.BoardArray[row][col];

                Application.Current.Dispatcher.BeginInvoke(
                    DispatcherPriority.Background,
                    new Action(() => sourceUserControl.button.IsEnabled = true));
            }
        }
예제 #8
0
        /// <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
            });
        }