Esempio n. 1
0
        public override CheckersMove NextMove(CheckersGame game)
        {
            int maxJumps = 0;

            CheckersPiece[] movables      = game.EnumMovablePieces();
            ArrayList       possibleMoves = new ArrayList(movables.Length);

            foreach (CheckersPiece movable in movables)
            {
                possibleMoves.Add(game.BeginMove(movable));
            }
            // Get all possible jump combos
            ArrayList finishedMoves = new ArrayList();

            while (possibleMoves.Count > 0)
            {
                CheckersMove move = (CheckersMove)possibleMoves[0];
                possibleMoves.RemoveAt(0);
                Point[] points = move.EnumMoves();
                if (points.Length == 0)
                {
                    // Move is complete; add to finished moves and test for current max jumps
                    finishedMoves.Add(move);
                    if (maxJumps < move.Jumped.Length)
                    {
                        maxJumps = move.Jumped.Length;
                    }
                    continue;
                }
                // Enumerate all moves from this point and append them to the possible moves array
                foreach (Point p in points)
                {
                    CheckersMove next = move.Clone();
                    next.Move(p);
                    possibleMoves.Add(next);
                }
            }
            // Get list of max jumps
            ArrayList moveList = new ArrayList();

            foreach (CheckersMove move in finishedMoves)
            {
                if (move.Jumped.Length != maxJumps)
                {
                    continue;
                }
                moveList.Add(move);
            }
            // Choose at random between any path with same number of jumps
            if (moveList.Count == 0)
            {
                return(null);
            }
            return((CheckersMove)moveList[rand.Next(moveList.Count)]);
        }
Esempio n. 2
0
        public override CheckersMove NextMove(CheckersGame game)
        {
            CheckersPiece[] movable = game.EnumMovablePieces();
            CheckersMove    move    = game.BeginMove(movable[rand.Next(movable.Length)]);

            while (move.MustMove)
            {
                Point[] moves = move.EnumMoves();
                move.Move(moves[rand.Next(moves.Length)]);
            }
            return(move);
        }
Esempio n. 3
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));
 }