# Thread: Using SRL's SmartColors for object finding

1. ## Using SRL's SmartColors for object finding

Smart Colors!

Introduction
I am extremely happy and proud to present the SmartColors.simba include. This is an Artificial Inteligence object finding method, but no need to be scared, as it is extremely simple to use. For basic use, you only need to worry about 2 functions:
Simba Code:
procedure MakeObj(MyName: string; MyColor, MyTol: integer; MyHue, MySat: extended; MyUpTexts, MyOptions: TStringArray);function SmartColors(FindWhat: string): boolean;

All you need to do is call MakeObj once before calling SmartColors, (I'd suggest at the start of the script) and then you just call SmartColors whenever you want to find something.

Here is how I used it:
Simba Code:
{\$i SRL\Misc\SmartColors.simba}MakeObj('tree', 4689280, 9, 0.05, 0.74, ['n Tr', 'ree', 'hop', 'own'], ['hop down']);SmartColors('tree');
NOTE: The name you give the object is the name you have to call.
NOTE: SmartColors finds and clicks the tree.

History
Long story made short, a couple of years ago Tarajunky made a post about a new system he called SmartColors. It got me very interested and I learnt it straight from him and his ChickenKiller. I then developed a SmartColors function which never got into SRL, but still worked fairly well and I used it in the first version of RM Chopper. I then made a few threads about it and it caught EvilChicken's attention. EC then used his own version in his agility script. Since then, we've often enough attempted to develop a propper include for SRL with SmartColors. Here it finally is.

The SmartColors 'Algorithm'
SmartColors, as the name suggests, is smart and therefore learns and becomes better the more often it is called. The first time it is called, it will do a normal TPA finding and it will gather colors which are similar and close to the color you provided it with.
It will then scan the MainScreen to see how unique these colors are. If they are rare enough, it will add them to an array of colors.
Once added to this array of colors, it chooses the rarest of them to pass it on to a final array. You now have your SCArray ready (SmartColorsArray).

Being done with picking all the best colors, you will now see the big difference between this system and previous ones. You will search for one color at a time from the SCArray with no tolerance. Usually, searching for even just the first color with 0 tol will be enough to find your object, making search times as low as 0 ms.

If it does not find your object without tolerance, it will then go through all the colors again, this time with tolerance. This rarely happens.

The speed is a big factor, but even more than that, SmartColors updates the SCArray as it runs; When it finds your object by a certain color, it will move that color up in the SCArray, meaning that next time it will search with this color sooner. What this means is that the best colors will eventually be the first ones to be searched for.

And finally, when searching with tolerance and it finds the object, it analyses the new color, and if the color is unique enough and within tolerance range it will add it to the SCArray, meaning that SmartColors also learns about new colors to use.

SmartColors if not setup will use the default SC_ constants values, however, you can set these up yourself if you wish.
Simba Code:
type{Type TSCDetails   Description: Extra Object details; Can set them up or leave it to default values }  TSCDetails = record    IsSCSetup           : boolean; //do not touch, let SC know if you are using custom or default values    UNIQUE_COLOR_MIN    : integer; //the mininum amount of color for it to join the SC array    UNIQUE_COLOR_MAX    : integer; //same as above for maximum    MAX_COLORS_IN_ARRAY : integer; //max length of SC Array    HALF_BOX_SIZE       : integer; //half box size of object you are searching    USE_TOL             : integer; //tolerance for your object    TPA_DIST            : integer; //max distanc between points    CLICK_STYLE         : integer; //how to click your object. Check consts    RANDOM_RL_CHANCE    : integer; // x/100 to do R Click instead of L click  end;

It is extremely simple to set them up as all you have to do is call one single function:
Simba Code:
procedure SetupSmartColorsDetails(Name: string; ColorMin, ColorMax, MaxColors, BoxSize, Tol, Dist, ClickStyle, R_RL_Chance: integer);

And here are the default values:
Simba Code:
SC_UNIQUE_COLOR_MIN      =  5;SC_UNIQUE_COLOR_MAX      = 20;SC_MAX_COLORS_IN_ARRAY   =  7;SC_HALF_BOX_SIZE         = 25;SC_USE_TOL               =  5;SC_TPA_DIST              =  5;SC_CLICK_STYLE           = 3;SC_RANDOM_RL_CHANCE      = 20; // x / 100 for R click

So finally, for an advanced use of SmartColors here is your code:
Simba Code:
MakeObj('clay', 5215677, 17, 0.01, 1.01, ['ine', 'ock'], ['ine']);SetupSmartColorsDetails('clay', 3, 15, 7, 15, 5, 5, 3, 15);SmartColors('clay');

And so, I hope to see people using this new system as it is extremely fast, accurate and very easy to use.

Lots o' Love,
The Dev Team
Last edited by Coh3n; 03-25-2012 at 08:47 AM.

2. Wow, when I read the include, I didn't think it would be that easy to use. Very nice!

3. Very nice RM.

I may mess with this once I update my 99 mage script

4. Senior SRL Member
Join Date
Jan 2008
Location
NC, USA.
Posts
4,430
Mentioned
0 Post(s)
Quoted
4 Post(s)
Simply Beautiful. Lovely code.

Good job RM

5. Amazing, will definitely use this !
Thanks.

6. Sounds nice, but disappointed at string identifiers. Constant integers would've been nicer imo and made it easier for scripters as the slight differences in string names may cause problems (haven't read through, but I assume at the least it will give a runtime writeln saying that it doesn't exist or at worst cause a crash of some kind).

7. Originally Posted by mixster
Sounds nice, but disappointed at string identifiers. Constant integers would've been nicer imo and made it easier for scripters as the slight differences in string names may cause problems (haven't read through, but I assume at the least it will give a runtime writeln saying that it doesn't exist or at worst cause a crash of some kind).
I recon it would crash. Constant identifiers weren't really the best option in my opinion, as I was aiming for ease of use Also, there was very little point in constants, as there are no actually pre-made records, the scripter has to construct them themselves.

edit: Added failsafe, no longer crashes, sends an SRL_warning and exits smart colors

~RM
Last edited by Sir R. M8gic1an; 11-21-2009 at 06:50 PM.

8. Wonderful job RM! I can't wait to use this.

9. It just means that the scripter has to remember which string he is using or setup a const for it, which means that an integer one would have been just as easy.

10. Originally Posted by mixster
It just means that the scripter has to remember which string he is using or setup a const for it, which means that an integer one would have been just as easy.
easier to remember 'mithril' rather than 10 I recon. Also, 'mithril' is more reader-friendly than 10.

~RM

11. Originally Posted by Rasta Magician
easier to remember 'mithril' rather than 10 I recon. Also, 'mithril' is more reader-friendly than 10.

~RM
Don't we use player[].integers[] as numbers? I honestly don't think that it would be that user unfriendly...

Nice job.

12. const mithril = 10;

or, even better, sc_mithril = 10; sc_coal = 11; sc_ *ctrl+space* => all the smart colours defined.

13. Originally Posted by mixster
const mithril = 10;

or, even better, sc_mithril = 10; sc_coal = 11; sc_ *ctrl+space* => all the smart colours defined.
Well, you can do constant strings too, if you're dead set on using constants.

14. You're too sexy.
Just watching this makes me wanna go create a script :I
Rep++ for this, awesome.

(I don't go like this everyday, so you better be proud >;I )

15. you could do constant strings, but then the whole point of using strings to be user friendly kind of goes down the drain.

16. Amazing piece of art right there! Great job RM!
I love how it works, I'll test it asap
(I ran scar on my friends computer today and stupid avarst antivirus deleted scar.exe... <_<)

17. I just tested this out and it works wonderfully.

18. VERY sexy
I would have done:
SCAR Code:
I:=MakeObj(4689280, 9, 0.05, 0.74, ['n Tr', 'ree', 'hop', 'own'], ['hop down']);
But what ever

19. Ok guys, I have added an advanced setup to the include and explained it in the tutorial This should be the finalized version of Smartcolors

~RM

20. Originally Posted by Rasta Magician
Ok guys, I have added an advanced setup to the include and explained it in the tutorial This should be the finalized version of Smartcolors

~RM
Good job
Nicely explained and it seems extremely easy to use :O <3 your work RM

21. Very nice, always good to see some innovation in SRL!

22. Tremendous work. I'm proud of designing the strategy, but you've really made it shine.

23. Perhaps it should just return an x, y and not click..

24. Isn't one of the great things about SRL that it is open sauce? Go in and alter it to return a point