Пример #1
0
        /// <summary>Returns a list of legal moves from all pieces this turn.</summary>
        /// <param name="optionalJumping">Overrides the game's OptionalJumping parameter for the enumeration.</param>
        /// <returns>A list of legal moves.</returns>
        public CheckersMove[] EnumLegalMoves(bool optionalJumping)
        {
            if ((!isPlaying) && (winner == 0))
            {
                throw new InvalidOperationException("Operation requires game to be playing.");
            }
            Stack     incompleteMoves = new Stack();
            ArrayList moves           = new ArrayList();

            foreach (CheckersPiece piece in EnumMovablePieces(optionalJumping))
            {
                incompleteMoves.Push(BeginMove(piece));
            }
            while (incompleteMoves.Count > 0)
            {
                CheckersMove move = (CheckersMove)incompleteMoves.Pop();
                foreach (Point location in move.EnumMoves(optionalJumping))
                {
                    CheckersMove nextMove = move.Clone();
                    if (!nextMove.Move(location))
                    {
                        continue;
                    }
                    if (nextMove.CanMove)
                    {
                        incompleteMoves.Push(nextMove);
                    }
                    if (!nextMove.MustMove)
                    {
                        moves.Add(nextMove);
                    }
                }
            }
            return((CheckersMove[])moves.ToArray(typeof(CheckersMove)));
        }
Пример #2
0
        /// <summary>Returns a list of movable pieces this turn.</summary>
        /// <param name="optionalJumping">Overrides the game's OptionalJumping parameter for the enumeration.</param>
        /// <returns>A list of pieces that can be moved this turn.</returns>
        public CheckersPiece[] EnumMovablePieces(bool optionalJumping)
        {
            if ((!isPlaying) && (winner == 0))
            {
                throw new InvalidOperationException("Operation requires game to be playing.");
            }
            ArrayList movable = new ArrayList();

            foreach (CheckersPiece piece in EnumPlayerPieces(turn))
            {
                CheckersMove move = new CheckersMove(this, piece, false);
                if (move.EnumMoves(optionalJumping).Length != 0)
                {
                    movable.Add(piece);
                }
            }
            return((CheckersPiece[])movable.ToArray(typeof(CheckersPiece)));
        }