Ejemplo n.º 1
0
            /// <summary>
            /// Gets the difficulty of the AI in the input slot.
            /// <para>If the input slot is not an AI, returns null.
            /// If checking an AI's difficulty in the queue, it will always return easy, or null if it is a player.</para>
            /// </summary>
            /// <param name="slot">Slot to check</param>
            /// <param name="noUpdate"></param>
            /// <returns>Returns a value in the Difficulty enum if the difficulty is found. Returns null if the input slot is not an AI.</returns>
            /// <exception cref="InvalidSlotException">Thrown when slot is out of range.</exception>
            public Difficulty?GetAIDifficulty(int slot, bool noUpdate = false)
            {
                if (!cg.IsSlotValid(slot))
                {
                    throw new InvalidSlotException(string.Format("Slot {0} is out of range of possible slots to check for AI.", slot));
                }

                if (slot == 5 && cg.OpenChatIsDefault)
                {
                    cg.Chat.CloseChat();
                }

                if (!noUpdate)
                {
                    cg.updateScreen();
                }

                if (cg.IsSlotBlue(slot) || cg.IsSlotRed(slot))
                {
                    bool draw = cg.debugmode;                       // For debug mode

                    List <int>        rl = new List <int>();        // Likelyhood in percent for difficulties.
                    List <Difficulty> dl = new List <Difficulty>(); // Difficulty

                    bool foundWhite      = false;
                    int  foundWhiteIndex = 0;
                    int  maxWhite        = 3;
                    // For each check length in IsAILocations
                    for (int xi = 0; xi < DifficultyLocations[slot, 2] && foundWhiteIndex < maxWhite; xi++)
                    {
                        if (foundWhite)
                        {
                            foundWhiteIndex++;
                        }

                        Color cc = cg.GetPixelAt(DifficultyLocations[slot, 0] + xi, DifficultyLocations[slot, 1]);
                        // Check for white color of text
                        if (cg.CompareColor(DifficultyLocations[slot, 0] + xi, DifficultyLocations[slot, 1], CALData.WhiteColor, 110) &&
                            (slot > 5 || cc.B - cc.R < 20))
                        {
                            foundWhite = true;

                            // For each difficulty markup
                            for (int b = 0; b < DifficultyMarkups.Length; b++)
                            {
                                Bitmap tmp = null;
                                if (draw)
                                {
                                    tmp = cg.BmpClone(0, 0, cg.bmp.Width, cg.bmp.Height);
                                }

                                // Check if bitmap matches checking area
                                double success = 0;
                                double total   = 0;
                                for (int x = 0; x < DifficultyMarkups[b].Width; x++)
                                {
                                    for (int y = DifficultyMarkups[b].Height - 1; y >= 0; y--)
                                    {
                                        // If the color pixel of the markup is not white, check if valid.
                                        Color pc = DifficultyMarkups[b].GetPixel(x, y);
                                        if (pc != Color.FromArgb(255, 255, 255, 255))
                                        {
                                            // tc is true if the pixel is black, false if it is red.
                                            bool tc = pc == Color.FromArgb(255, 0, 0, 0);

                                            total++; // Indent the total
                                                     // If the checking color in the bmp bitmap is equal to the pc color, add to success.
                                            if (cg.CompareColor(DifficultyLocations[slot, 0] + xi + x, DifficultyLocations[slot, 1] - Extensions.InvertNumber(y, DifficultyMarkups[b].Height - 1), CALData.WhiteColor, 50) == tc)
                                            {
                                                success++;

                                                if (draw)
                                                {
                                                    if (tc)
                                                    {
                                                        tmp.SetPixel(DifficultyLocations[slot, 0] + xi + x, DifficultyLocations[slot, 1] - Extensions.InvertNumber(y, DifficultyMarkups[b].Height - 1), Color.Blue);
                                                    }
                                                    else
                                                    {
                                                        tmp.SetPixel(DifficultyLocations[slot, 0] + xi + x, DifficultyLocations[slot, 1] - Extensions.InvertNumber(y, DifficultyMarkups[b].Height - 1), Color.Lime);
                                                    }
                                                }
                                            }
                                            else if (draw)
                                            {
                                                if (tc)
                                                {
                                                    tmp.SetPixel(DifficultyLocations[slot, 0] + xi + x, DifficultyLocations[slot, 1] - Extensions.InvertNumber(y, DifficultyMarkups[b].Height - 1), Color.Red);
                                                }
                                                else
                                                {
                                                    tmp.SetPixel(DifficultyLocations[slot, 0] + xi + x, DifficultyLocations[slot, 1] - Extensions.InvertNumber(y, DifficultyMarkups[b].Height - 1), Color.Orange);
                                                }
                                            }

                                            if (draw)
                                            {
                                                tmp.SetPixel(DifficultyLocations[slot, 0] + xi + x, DifficultyLocations[slot, 1] - DifficultyMarkups[b].Height * 2 + y, DifficultyMarkups[b].GetPixel(x, y));
                                                cg.g.DrawImage(tmp, new Rectangle(0, -750, tmp.Width * 3, tmp.Height * 3));
                                                Thread.Sleep(1);
                                            }
                                        }
                                    }
                                }
                                // Get the result
                                double result = (success / total) * 100;

                                rl.Add((int)result);
                                dl.Add((Difficulty)b);

                                if (draw)
                                {
                                    tmp.SetPixel(DifficultyLocations[slot, 0] + xi, DifficultyLocations[slot, 1], Color.MediumPurple);
                                    cg.g.DrawImage(tmp, new Rectangle(0, -750, tmp.Width * 3, tmp.Height * 3));
                                    Console.WriteLine((Difficulty)b + " " + result);
                                    Thread.Sleep(1000);
                                }
                            }
                        }
                    }

                    if (slot == 5 && cg.OpenChatIsDefault)
                    {
                        cg.Chat.OpenChat();
                    }

                    // Return the difficulty that is most possible.
                    if (rl.Count > 0)
                    {
                        int max = rl.Max();
                        if (max >= 75)
                        {
                            return(dl[rl.IndexOf(max)]);
                        }
                        else
                        {
                            return(null);
                        }
                    }
                    else
                    {
                        return(null);
                    }
                }

                else if (cg.QueueCount > 0)
                {
                    int y = DifficultyLocationsQueue[slot - Queueid];
                    for (int x = DifficultyLocationQueueX; x < 150 + DifficultyLocationQueueX; x++)
                    {
                        if (cg.CompareColor(x, y, new int[] { 180, 186, 191 }, 10))
                        {
                            return(null);
                        }
                    }
                    return(Difficulty.Easy);
                }

                else
                {
                    return(null);
                }
            }
Ejemplo n.º 2
0
        /// <summary>
        /// Gets the difficulty of the AI in the input slot.
        /// </summary>
        /// <remarks>
        /// If the input slot is not an AI, returns null.
        /// If checking an AI's difficulty in the queue, it will always return easy, or null if it is a player.
        /// </remarks>
        /// <param name="slot">Slot to check</param>
        /// <param name="noUpdate"></param>
        /// <returns>Returns the if the difficulty is found. Returns null if the input slot is not an AI.</returns>
        /// <include file='docs.xml' path='doc/exceptions/invalidslot/exception'/>
        public Difficulty?GetAIDifficulty(int slot, bool noUpdate = false)
        {
            using (cg.LockHandler.Passive)
            {
                if (!CustomGame.IsSlotValid(slot))
                {
                    throw new InvalidSlotException(slot);
                }

                if (slot == 5 && cg.OpenChatIsDefault)
                {
                    cg.Chat.CloseChat();
                }

                if (!noUpdate)
                {
                    cg.UpdateScreen();
                }

                if (CustomGame.IsSlotBlue(slot) || CustomGame.IsSlotRed(slot))
                {
                    List <int>        rl = new List <int>();        // Likelyhood in percent for difficulties.
                    List <Difficulty> dl = new List <Difficulty>(); // Difficulty

                    int checkDistance = CustomGame.IsSlotBlue(slot) ? 100 : 25;

                    bool foundWhite      = false;
                    int  foundWhiteIndex = 0;
                    int  maxWhite        = 3;
                    // For each check length in IsAILocations
                    for (int xi = Points.DIFFICULTY_LOCATIONS[slot].X; xi < Points.DIFFICULTY_LOCATIONS[slot].X + checkDistance && foundWhiteIndex < maxWhite; xi++)
                    {
                        if (foundWhite)
                        {
                            foundWhiteIndex++;
                        }

                        Color cc = Capture.GetPixel(xi, Points.DIFFICULTY_LOCATIONS[slot].Y);
                        // Check for white color of text
                        if (Capture.CompareColor(xi, Points.DIFFICULTY_LOCATIONS[slot].Y, Colors.WHITE, 110) &&
                            (slot > 5 || cc.B - cc.R < 20))
                        {
                            foundWhite = true;

                            // For each difficulty markup
                            for (int b = 0; b < Markups.DIFFICULTY_MARKUPS.Length; b++)
                            {
                                // Check if bitmap matches checking area
                                double success = 0;
                                double total   = 0;
                                for (int x = 0; x < Markups.DIFFICULTY_MARKUPS[b].Width; x++)
                                {
                                    for (int y = Markups.DIFFICULTY_MARKUPS[b].Height - 1; y >= 0; y--)
                                    {
                                        // If the color pixel of the markup is not white, check if valid.
                                        Color pc = Markups.DIFFICULTY_MARKUPS[b].GetPixel(x, y);
                                        if (pc != Color.FromArgb(255, 255, 255, 255))
                                        {
                                            // tc is true if the pixel is black, false if it is red.
                                            bool tc = pc == Color.FromArgb(255, 0, 0, 0);

                                            total++; // Indent the total
                                                     // If the checking color in the bmp bitmap is equal to the pc color, add to success.
                                            if (Capture.CompareColor(xi + x, Points.DIFFICULTY_LOCATIONS[slot].Y - Extensions.InvertNumber(y, Markups.DIFFICULTY_MARKUPS[b].Height - 1), Colors.WHITE, 50) == tc)
                                            {
                                                success++;
                                            }
                                        }
                                    }
                                }
                                // Get the result
                                double result = (success / total) * 100;

                                rl.Add((int)result);
                                dl.Add((Difficulty)b);
                            }
                        }
                    }

                    if (slot == 5 && cg.OpenChatIsDefault)
                    {
                        cg.Chat.OpenChat();
                    }

                    // Return the difficulty that is most possible.
                    if (rl.Count > 0)
                    {
                        int max = rl.Max();
                        if (max >= 75)
                        {
                            return(dl[rl.IndexOf(max)]);
                        }
                        else
                        {
                            return(null);
                        }
                    }
                    else
                    {
                        return(null);
                    }
                }

                else if (cg.QueueCount > 0)
                {
                    int y = Points.DIFFICULTY_QUEUE_LOCATIONS[slot - CustomGame.QueueID];
                    for (int x = Points.DIFFICULTY_QUEUE_X; x < 150 + Points.DIFFICULTY_QUEUE_X; x++)
                    {
                        if (Capture.CompareColor(x, y, new int[] { 180, 186, 191 }, 10))
                        {
                            return(null);
                        }
                    }
                    return(Difficulty.Easy);
                }

                else
                {
                    return(null);
                }
            }
        }