Ejemplo n.º 1
0
Archivo: Game.cs Proyecto: vgichar/shah
 /// <summary>
 /// Raises the GoingBack event.
 /// </summary>
 /// <param name="e"></param>
 protected virtual void OnGoingBack(CancelMoveEventArgs e)
 {
     if (GoingBack != null)
     {
         GoingBack(this, e);
     }
 }
Ejemplo n.º 2
0
Archivo: Game.cs Proyecto: vgichar/shah
 /// <summary>
 /// Raises the Moving event.
 /// </summary>
 /// <param name="e"></param>
 protected virtual void OnMoving(CancelMoveEventArgs e)
 {
     if (Moving != null)
     {
         Moving(this, e);
     }
 }
Ejemplo n.º 3
0
Archivo: Game.cs Proyecto: vgichar/shah
 /// <summary>
 /// Raises the GoingForward event.
 /// </summary>
 /// <param name="e"></param>
 protected virtual void OnGoingForward(CancelMoveEventArgs e)
 {
     if (GoingForward != null)
     {
         GoingForward(this, e);
     }
 }
Ejemplo n.º 4
0
        private void model_Moving(object sender, CancelMoveEventArgs e)
        {
            // set the index information
            tempIndex = Utils.GetSANIndex(model);

            // set the SAN information before the move is made
            tempSAN = Utils.GetSANBegin(model, e.Move);
        }
Ejemplo n.º 5
0
Archivo: Game.cs Proyecto: vgichar/shah
        /// <summary>
        /// Go to the previous board configuration in history.
        /// </summary>
        public void Previous()
        {
            // if the game is not at the begining
            if (!IsFirst)
            {
                Move move = moveHistory[currentBoardIndex - 1];

                // build the event args
                CancelMoveEventArgs moveEventArgs = new CancelMoveEventArgs(move, currentBoardIndex - 1);

                // raise the GoingBack event
                OnGoingBack(moveEventArgs);

                // if the operation was cancelled
                if (moveEventArgs.Cancel)
                {
                    return;
                }

                // remove the current board hash from the history
                RemoveHistoryHash();

                // take back the move
                move.TakeBack(currentBoard);

                // generate the possible moves
                GenerateMoves();

                // set the status of the game
                SetStatus();

                // decrement the current board index
                currentBoardIndex--;

                // raise the GoneBack event
                OnGoneBack(new MoveEventArgs(move, currentBoardIndex - 1));
            }
        }
Ejemplo n.º 6
0
Archivo: Game.cs Proyecto: vgichar/shah
        /// <summary>
        /// Go to the next board configuration in history.
        /// </summary>
        public void Next()
        {
            // if the game is not the at the end
            if (!IsLast)
            {
                Move move = moveHistory[currentBoardIndex];

                // build the event args
                CancelMoveEventArgs moveEventArgs = new CancelMoveEventArgs(move, currentBoardIndex - 1);

                // raise the GoingForward event
                OnGoingForward(moveEventArgs);

                // if the operation was cancelled
                if (moveEventArgs.Cancel)
                {
                    return;
                }

                // make the move
                move.Make(currentBoard);

                // add the current board hash to the history
                AddHistoryHash();

                // generate the possible moves
                GenerateMoves();

                // set the status of the game
                SetStatus();

                // increment the current board index
                currentBoardIndex++;

                // raise the GoneForward event
                OnGoneForward(new MoveEventArgs(move, currentBoardIndex - 1));
            }
        }
Ejemplo n.º 7
0
Archivo: Game.cs Proyecto: vgichar/shah
        /// <summary>
        /// Makes a move.
        /// If the move is illegal or it's null, throws an Argument(Null)Exception.
        /// </summary>
        /// <param name="move">The move</param>
        public void Make(Move move)
        {
            // check to see if the move it's not null and it's valid
            if (move == null)
            {
                throw new ArgumentNullException("move", Resources.NullMoveMsg);
            }
            bool findMove = false;

            foreach (Move m in PossibleMoves)
            {
                if (move.From == m.From && move.To == m.To)
                {
                    findMove = true;
                    break;
                }
            }
            if (!findMove)
            {
                throw new ArgumentException(Resources.IllegalMoveMsg, "move");
            }

            // build the event args
            CancelMoveEventArgs moveEventArgs = new CancelMoveEventArgs(move, currentBoardIndex - 1);

            // raise the Moving event
            OnMoving(moveEventArgs);

            // if the move was cancelled
            if (moveEventArgs.Cancel)
            {
                return;
            }

            // remove the moves after current board index (if any)
            if (!IsLast)
            {
                moveHistory.RemoveRange(currentBoardIndex, moveHistory.Count - currentBoardIndex);
            }

            // if this is a promotion, the promotion is not set and the promotion delegate is not null, call the promotion delegate
            if (move is PromotionMove && (move as PromotionMove).PromotionType == null && Promote != null)
            {
                (move as PromotionMove).PromotionType = Promote();
            }

            // make the move
            move.Make(currentBoard);

            // add the current hash to the history
            AddHistoryHash();

            // generate the possible moves
            GenerateMoves();

            // set the status of the game
            SetStatus();

            // increment the current board index
            currentBoardIndex++;

            // add move to history
            moveHistory.Add(move);

            // raise the Moved event
            OnMoved(new MoveEventArgs(move, currentBoardIndex - 1));
        }
Ejemplo n.º 8
0
Archivo: Game.cs Proyecto: vgichar/shah
        /// <summary>
        /// Go to the next board configuration in history.
        /// </summary>
        public void Next()
        {
            // if the game is not the at the end
            if (!IsLast)
            {
                Move move = moveHistory[currentBoardIndex];

                // build the event args
                CancelMoveEventArgs moveEventArgs = new CancelMoveEventArgs(move, currentBoardIndex - 1);

                // raise the GoingForward event
                OnGoingForward(moveEventArgs);

                // if the operation was cancelled
                if (moveEventArgs.Cancel) { return; }

                // make the move
                move.Make(currentBoard);

                // add the current board hash to the history
                AddHistoryHash();

                // generate the possible moves
                GenerateMoves();

                // set the status of the game
                SetStatus();

                // increment the current board index
                currentBoardIndex++;

                // raise the GoneForward event
                OnGoneForward(new MoveEventArgs(move, currentBoardIndex - 1));
            }
        }
Ejemplo n.º 9
0
Archivo: Game.cs Proyecto: vgichar/shah
        /// <summary>
        /// Go to the previous board configuration in history.
        /// </summary>
        public void Previous()
        {
            // if the game is not at the begining
            if (!IsFirst)
            {
                Move move = moveHistory[currentBoardIndex - 1];

                // build the event args
                CancelMoveEventArgs moveEventArgs = new CancelMoveEventArgs(move, currentBoardIndex - 1);

                // raise the GoingBack event
                OnGoingBack(moveEventArgs);

                // if the operation was cancelled
                if (moveEventArgs.Cancel) { return; }

                // remove the current board hash from the history
                RemoveHistoryHash();

                // take back the move
                move.TakeBack(currentBoard);

                // generate the possible moves
                GenerateMoves();

                // set the status of the game
                SetStatus();

                // decrement the current board index
                currentBoardIndex--;

                // raise the GoneBack event
                OnGoneBack(new MoveEventArgs(move, currentBoardIndex - 1));
            }
        }
Ejemplo n.º 10
0
Archivo: Game.cs Proyecto: vgichar/shah
        /// <summary>
        /// Makes a move.
        /// If the move is illegal or it's null, throws an Argument(Null)Exception.
        /// </summary>
        /// <param name="move">The move</param>
        public void Make(Move move)
        {
            // check to see if the move it's not null and it's valid
            if (move == null) { throw new ArgumentNullException("move", Resources.NullMoveMsg); }
            bool findMove = false;
            foreach (Move m in PossibleMoves)
            {
                if (move.From == m.From && move.To == m.To)
                {
                    findMove = true;
                    break;
                }
            }
            if (!findMove) { throw new ArgumentException(Resources.IllegalMoveMsg, "move"); }

            // build the event args
            CancelMoveEventArgs moveEventArgs = new CancelMoveEventArgs(move, currentBoardIndex - 1);

            // raise the Moving event
            OnMoving(moveEventArgs);

            // if the move was cancelled
            if (moveEventArgs.Cancel) { return; }

            // remove the moves after current board index (if any)
            if (!IsLast)
            {
                moveHistory.RemoveRange(currentBoardIndex, moveHistory.Count - currentBoardIndex);
            }

            // if this is a promotion, the promotion is not set and the promotion delegate is not null, call the promotion delegate
            if (move is PromotionMove && (move as PromotionMove).PromotionType == null && Promote != null)
            {
                (move as PromotionMove).PromotionType = Promote();
            }

            // make the move
            move.Make(currentBoard);

            // add the current hash to the history
            AddHistoryHash();

            // generate the possible moves
            GenerateMoves();

            // set the status of the game
            SetStatus();

            // increment the current board index
            currentBoardIndex++;

            // add move to history
            moveHistory.Add(move);

            // raise the Moved event
            OnMoved(new MoveEventArgs(move, currentBoardIndex - 1));
        }
Ejemplo n.º 11
0
Archivo: Game.cs Proyecto: vgichar/shah
 /// <summary>
 /// Raises the GoingBack event.
 /// </summary>
 /// <param name="e"></param>
 protected virtual void OnGoingBack(CancelMoveEventArgs e)
 {
     if (GoingBack != null) { GoingBack(this, e); }
 }
Ejemplo n.º 12
0
Archivo: Game.cs Proyecto: vgichar/shah
 /// <summary>
 /// Raises the GoingForward event.
 /// </summary>
 /// <param name="e"></param>
 protected virtual void OnGoingForward(CancelMoveEventArgs e)
 {
     if (GoingForward != null) { GoingForward(this, e); }
 }
Ejemplo n.º 13
0
Archivo: Game.cs Proyecto: vgichar/shah
 /// <summary>
 /// Raises the Moving event.
 /// </summary>
 /// <param name="e"></param>
 protected virtual void OnMoving(CancelMoveEventArgs e)
 {
     if (Moving != null) { Moving(this, e); }
 }
Ejemplo n.º 14
0
        private void model_Moving(object sender, CancelMoveEventArgs e)
        {
            // set the index information
            tempIndex = Utils.GetSANIndex(model);

            // set the SAN information before the move is made
            tempSAN = Utils.GetSANBegin(model, e.Move);
        }