示例#1
0
        public void UndoLastMove()
        {
            TicTacToeMove m = MoveHistory.Last() as TicTacToeMove;

            SetPosition(m.Position, 0);
            MoveHistory.RemoveAt(MoveHistory.Count - 1);
        }
示例#2
0
        private void UndoButton_Click(object sender, RoutedEventArgs e)
        {
            if (MoveHistory.Count < 1)
            {
                return;
            }

            Untrack();

            Move lastMove = MoveHistory.Last();

            Cell target = BoardGrid.GetCellAt(lastMove.Target);

            target.Filled = false;
            Cell source = BoardGrid.GetCellAt(lastMove.Source);
            Cell middle = BoardGrid.GetMiddleCell(source, target);

            middle.Selected = false;
            middle.Filled   = true;
            source.Selected = false;
            source.Filled   = true;

            UndoHistory.Add(lastMove);
            MoveHistory.RemoveAt(MoveHistory.Count - 1);
        }
示例#3
0
        public void UndoLastMove()
        {
            TicTacToeMove m = MoveHistory.Last() as TicTacToeMove;

            SetPosition(m.Position, 0);
            Value    = 0;
            mWeight += mPlayer * mWeights[m.Position.Row, m.Position.Col];
            mPlayer  = -mPlayer;
            MoveHistory.RemoveAt(MoveHistory.Count - 1);
        }
示例#4
0
        /// <summary>
        /// Undoes the last move, restoring the game to its state before the move was applied.
        /// </summary>
        public void UndoLastMove()
        {
            OthelloMove m = MoveHistory[MoveHistory.Count - 1] as OthelloMove;

            // Note: there is a bug in this code.
            if (!m.IsPass)
            {
                // Reset the board at the move's position.
                mBoard[m.Position.Row, m.Position.Col] = 0;
                Value  += mCurrentPlayer;
                Weight += mCurrentPlayer * mWeights[m.Position.Row, m.Position.Col];

                // Iterate through the move's recorded flipsets.
                foreach (var flipSet in m.FlipSets)
                {
                    BoardPosition pos = m.Position;
                    // For each flipset, walk along the flipset's direction resetting pieces.
                    for (int i = 1; i <= flipSet.Count; i++)
                    {
                        pos = pos.Translate(flipSet.RowDelta, flipSet.ColDelta);
                        mBoard[pos.Row, pos.Col] = (sbyte)mCurrentPlayer;
                        Value  += 2 * mCurrentPlayer;
                        Weight += 2 * mCurrentPlayer * mWeights[pos.Row, pos.Col];
                    }
                }

                // Check to see if the second-to-last move was a pass; if so, set PassCount.
                if (MoveHistory.Count > 1 && (MoveHistory[MoveHistory.Count - 2] as OthelloMove).IsPass)
                {
                    PassCount = 1;
                }
            }
            else
            {
                PassCount--;
            }
            // Reset the remaining game state.
            mCurrentPlayer = -mCurrentPlayer;
            MoveHistory.RemoveAt(MoveHistory.Count - 1);
        }