예제 #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)]);
        }
예제 #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);
        }