The Bytecode Club
Log inJoin the club
Video Game Reverse Engineering

Developing Bot

Started by Antidote · Dec 5, 2014

1,033 replies21,297,466 viewsLocked
Dec 20, 2014#161

@GkevinOD: just tested out your script. It won't work with all numbers for me but for certain numbers it get 100% accuracy consistently. I noticed numbers starting with 1,2,9 are more likely to match, while 6 or 4 is a bit tricky. After reading your script I figured this is how you do it?
Set x and y as base starting point then traverse through digits by specifying width.
Identify 3 distinctive pixels for each number
Check for that 3 pixels for each number, varies x to account for different width for certain set of number. If match return the number.
Get gold by concenating all returned values.
Such a simple idea but requires extremely meticulous work. Can't imagine how you mange to determine pixel by pixel. Even after getting it I'm having a hard time tweaking it lol. It looks like certain sets of digits get different width in between. I'll look into it and update you when there's any new finding.
Also it took around 2 to 3 seconds on average if there's a match (around ~6 for non-match) so it shouldn't be a problem. Tesseract takes a bit over 1 sec for each call, currently I'm using 3 calls and get minimum which takes around ~4 seconds. If we can optimize your script to read gold, elixir & dark in less than 5 seconds it'd be perfect.

Dec 20, 2014#162

What resolution required for this bot?

I've always having an error when i started the bot it always clicking the main menu of bluestacks and using other application.

Dec 20, 2014#163

@kitsaboy: might be because you use a different resolution. change BlueStacks resolution to 860x720 and launch the game first
@GkevinOD: I found that for numbers the script cannot match, changing x and y to +52, +93 helps it to match. And accuracy is always 100%. By alternating between 52,93 and 53,94 it can almost match any numbers. I will try to find a pattern and see if I can do the same for elixir

Dec 20, 2014#164

The bot is working but after dropping all the troops the bot does not do anything.

Dec 20, 2014#165

It got stuck in function ReturnHome() I think. For now I can't figure out how to determine when battle ends so the bot just wait for a specific amount of time before click Return Home. I will try to fix that

Dec 20, 2014#166

@Antidote I'll release the faster function which can search the gold in less than a second (100 mS for me), there are some complications on trying to get it to work the way I want it to though.

Also, the script I made previously does fail occasionally because sometimes the pixels may be 1 off. I made the script so most of the time it succeeds and once I finish making the functions faster, I'll post it and work on getting it 100% all the time.

To get the values of the elixir and the other resources, you just need to change the hex Color which looks somethings like "0x989579". To do that, you can print screen each number and change the values hex. You do not need to change the locations of the pixel because the only thing that changes that separates gold from the rest is the color.

Dec 20, 2014#167

It got stuck in function ReturnHome() I think. For now I can't figure out how to determine when battle ends so the bot just wait for a specific amount of time before click Return Home. I will try to fix that

Perhaps monitor the gold/elixer counts, when they're unchanged for a set period of time, return home.

Dec 21, 2014#168

@Antidote if you got time soon you maybe could have a look at the ReadValue function. i tried it for hours now and still dont understand why its stuck for me in this function.
its just not giving out any results. it opens tesseract.exe a few times but nothing happens. autoit is not receiving anything to work with.

maybe you can tell me how to test it out where exactly i can locate the problem?

the functions working:

Attack started. Begin searching..
Openig ComputeValue
Opening ReadValue

From this point on nothing more is happening. =/

Dec 21, 2014#169

@Antidote First of all I'm really impressed with the amount of work you are putting into this and I want to thank you for the effort and time. You are definitely gaining ground quickly from what I can see.

With the latest version it recognizes clash of clans immediately which is a definite improvement. It then trains the troops fine and clicks the Attack and Find a Match buttons without issue. However it just sits at the first village idle, it doesn't click Next when the village is unsuitable and it doesn't start the attack when it is. If I click village search alone while already looking at a village it clicks next regardless of whether the village is suitable or not and then sits at the following village idle. I assume clicking the attack button on the bot only clicks Attack and Find a Match in CoC because that is what it seems to do on my end.

Dec 21, 2014#170

@Antidote
I've been using Pixelcoordmode=2 and Mousecoordmode=2 to fix the pixel and barrack issues.

0 = relative coords to the defined window
1 = (default) absolute screen coordinates
2 = relative coords to the client area of the defined window

Setting mode to '2' would mean the client area of bluestacks window w/c means values will be inside BS resolution 860x720 whereas mode 1 would mean the defined window INCLUDING borders.. so if we get pixel of BS with coordinates (1,1) using mouse coordinate=0, then the pixel will be off the BS resolution of 860x720. Correct me if I'm wrong.. And that is probably I had a difference of around (0,20) when I calculated it days ago. Also, that may be the reason why the color you got was midnight blue for the search.

I've used pixelgetcolor with success in your zoomout function to determine if the screen is completely zoomedout.

Btw, I tried to loop tesseract making sure reading[2] and [3] will have maximum string length of 7 and a blank space in the first 4 digits. There was instances that it was having a hard time getting the right shot to the extent it took 20seconds. I'm still learning the basics of AutoIt, so I'm having hard time making it work with the while loop. I always get errors so I used for loop.

Currently I'm now getting an accurate reading with tesseract. I also updated my string manipulation code.

If StringLen($Read[2])>4 Then
$x=StringLeft($Read[2],3-7+_Min(7,StringLen($Read[2]))+3-StringLen(StringRegExpReplace(StringLeft($Read[2],4)," ",""))) & StringRight( StringLeft($Read[2],7-7+_Min(7,StringLen($Read[2]))) ,3)
EndIf

@GKevinOD
I tried your code but reading is always zero. Maybe you could also put it in a while loop to make sure you get a result. I would like to test you approach as it might be faster than tesseract.

This discussion is closed.