Пример #1
0
        /// <summary>
        /// Remembers the given move as a move that has to be added to the last "normal" move of the same player.
        /// This is supposed to be used for capture moves or "final" moves.
        /// </summary>
        /// <param name="move">The move to remember</param>
        /// <param name="currentPlayer">The player who made the move</param>
        public void RememberFollowUpMove(Move move, Player currentPlayer)
        {
            // We need an existing player list:
            if (_playerList.Count == 0)
            {
                throw new PSTException("UndoManager.RememberFollowUpMove: player list is empty.");
            }

            // We need an existing move list:
            if (_moveList.Count == 0)
            {
                throw new PSTException("UndoManager.RememberFollowUpMove: move list is empty.");
            }

            // We can only add a follow-up move for the same player as exists as the first entry in the list of players:
            if (_playerList[0] != currentPlayer)
            {
                throw new PSTException("UndoManager.RememberFollowUpMove: Unexpected player: " + currentPlayer + ". Expected " + _playerList[0] + ".");
            }

            // Get the move's backward move:
            Move backMove = move.GetBackwardMove();

            // Integrate the backward move into the move that is the first in the already existing list of "undo moves":
            _moveList[0].IntegrateMove(backMove);
        }
Пример #2
0
        /// <summary>
        /// Remembers the given move as a "normal" by the given player.
        /// </summary>
        /// <param name="move">The move to remember</param>
        /// <param name="currentPlayer">The player who made the move</param>
        public void RememberNormalNove(Move move, Player currentPlayer)
        {
            // A "normal" move is quite easy to remember: We store a new list entry with the move's "backward move".

            // Get the move's backward move:
            Move backMove = move.GetBackwardMove();

            // Add the backward move and the current player at the beginnings of the respecive lists:
            _moveList.Insert(0, backMove);
            _playerList.Insert(0, currentPlayer);
        }