I wish i could test kojometa's bot, but I don't know what to do with the script he posted on pastebin 🙁
Video Game Reverse Engineering
Developing Bot
Started by Antidote · Dec 5, 2014
@kojometa: Glad you got it working for so long, I never let it run continuously before lol. I'll look into what causing the problem with Giants but in the mean time if bar and archer works for you you already got a working bot for yourself 😉
@GkevinOD: very impressive work Kevin. I saw you add a variation check and creating custom function to get color instead of using pixelsearch? (don't understand all the dll call though :deadtongue:). I tested it and it's blazingly fast! Took on average ~50 millionseconds for successful match. I still have a problem with $x_default and $y_default though. Some numbers work with 53,94 and others with 52,93. I edited your code a bit and got it works with all numbers. Thanks mate I'm really happy with this. Looking forwards to your update on elixir 🙂
$x_default = $BlueStacks_XY [0] + 53
$y_default = $BlueStacks_XY [1] + 94
$tStart = TimerInit()
If getGold($x_default, $y_default) <> "" Then
$tStop = TimerDiff($tStart)
MsgBox(0, "Gold Count", "Gold: " & getGold($x_default, $y_default) & @CR & "First Pixel: 53, 94" & @CR & "Time: " & Round($tStop,3) & " milliseconds")
ElseIf getGold($x_default-1, $y_default-1) <> "" Then
$tStop = TimerDiff($tStart)
MsgBox(0, "Gold Count", "Gold: " & getGold($x_default-1, $y_default-1) & @CR & "First Pixel: 52, 93" & @CR & "Time: " & Round($tStop,3) & " milliseconds")
EndIf
@Antidote For me the $x_default and $y_default values are fine, and you are able to change that accordingly to your computer. There is probably a way to automatically set it for the user.
Also since the gold is a different shade than the everything else, you can actually find the elixir and dark elixir and trophy count by changing the the color variation to 42 and get the other values pretty well (that shade variation does also work on gold, but I haven't really tested it)
So basically, if you want to find the other values change this piece of code in the boolPixelSearch function:
If _ColorCheckVariation($Color1, $pixel1[2], 42) And _ColorCheckVariation($Color2, $pixel2[2], 42) And _ColorCheckVariation($Color3, $pixel3[2], 42) Then Return True
then you have to change the value of y for the first pixel of every value:
$y_default = $BlueStacks_XY [1] + 94 + 29 ;For Elixir
$y_default = $BlueStacks_XY [1] + 94 + 57 ;For Dark Elixir
$y_default = $BlueStacks_XY [1] + 94 + 90 ;For Trophy Count
There may be some mistakes here because the color variation is pretty high, but overall I say it can do 95% accuracy. I will work on getting the actual color of the pixels and implement it to the function.
I have found the pattern of the 1 pixel-off in the y value. When the base has no Dark Elixir Storage the y value is 1 off. I am in a higher TH and 99% of the time, they do have the storage.
man that sounds damn nice. i'm really looking forward for your method getting implemented into the script. tesseract seems to be far less successful than your script. would you mind posting your current version?
I've managed to tweak GkevinOD's code a bit to get both gold & elixir reading. It's super fast (it was nexting faster than you can read). Should've added parameters to it but I was lazy and ended up making 2 separate au3 files for gold and elixir lol. Below is the link to Bot.au3, GkevinODGoldFunction.au3 and GkevinODElixirFunction.au3. Just download all 3 to the same folder, run Bot.au3 and test for yourself. And since gold reading is much reliable now, I followed vanadium and modified ReturnHome to monitor gold change. It seems to be working but I haven't tested thoroughly yet. Also added a little extra button Keep Alive to help you guy prevent from being disconnect (what it does is send Down keyboard every 10 seconds). Enjoy!
http://www37.zippyshare.com/v/24789377/file.html
http://www37.zippyshare.com/v/92125782/file.html
http://www37.zippyshare.com/v/90677559/file.html
Hello everyone,
Once again I have modified my GetGold Function 2.0 and implemeted all 4 of the resources! Gold, Elixir, Dark Elixir, and Trophies aswell! Renamed as GetResources 3.0!
I basically got the colors of every pixel of the same location once again and for each resources, they are slightly different. This function also does not even take a second to get ALL of the resources (~30 milliSeconds for me).
Also, I implemented Antidote's code to tell the time and fix the 1 pixel off position. Now, you may need to change the values for the 1 pixel off position as it varies from computer to computer and it is basically set to my preferences.
Very easy to implement and easy replacement for Tesseract! I will also be working on trying to get the resources of your village, located to the right of the window.
P.S. @Antidote : You can use this function it is more efficient and accurate, I believe 🙂
just awesome you guys! tested out @Antidote new one and until now its working for me!
im also glad to find some of my work in the bot, like the timer 😉
added my beloved screenshots after fight-end though, so you can actually see your success when you wake up 🙂
i think its incredible what this bot has become within the last 2 days! when it runs stable, i think there are quite a few helpful features which can be added like collecting ressources or sending troops to friends. did those 2 with imagesearch already and won't be hard to add!
unfortunately autoit isnt able to run more than 1 function at the same time, this would make a lot easier^^
@Antidote BTW. you don't even need a timer-based attacking-system.
when you click on you barrack you can simply check for the Red color wich is showing at the bottom of the barrack when its full.
so you will never build troops when you are already able to fight.
=maximum time efficency 😉
hey guys,
http://pastebin.com/FyJkY8pQ
here i implemented a check if there are already maximum troops trained.
with this check it is going 2 train troops maximum 15 minutes, but it will stop training troops and start fighting as soon as there are maximum troops trained.
i think this is a lot easier and less waste of time.
the code implemented is:
;~ ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
GUICtrlSetData($Results, "PixelGetColor" & @CRLF, -1)
$Pixel = PixelGetColor(351*$x_ratio, 455*$y_ratio, $HWnD)
If $Pixel = 13645880 OR $Pixel = 13645881 OR $Pixel = 13645888 OR $Pixel = 13645889 OR $Pixel = 13645890 OR $Pixel = 13645891 Then
ControlClick ($HWnD, "","", "left", "1", 656*$x_ratio, 113*$y_ratio)
sleep(1000)
Attack()
EndIf
;~ ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
i also increased the sleep timer in the goldchange function because it was surrendering lot 2 early for me.
the game wasnt even half way over and the bot surrendered 🙁
a possible problem i recognized was the "getting out of sync" with the server during the villagesearch process.
i think it is a little 2 fast. one time it even skipped a good village cause of the incredible fast actions.
let me know what you think! 🙂
Make sense to me now since I tend to always use up all troops in battle I might overlook that. By detecting gold & elixir change, do you detect change in that screen region (pixelchecksum) or actually read gold & elixir to compare? How would it handle when you get 3 stars or battle end early (out of troops)?
Also I believe config file can be done in Autoit as well, requires very organized and flexible coding though. From what I see, your bot seems way ahead :D
This is the pseudo algorithm:
function waitForEndOfBattle() {
int delayInSeconds = config.getEndOfBattleDelay();
int resources = 0;
while(delayInSeconds > 0) {
int newResources = opponent.getGold() + opponent.getElixir();
if(newResources == resources) {
delayInSeconds--;
}
resources = newResources;
sleep(one second);
}
log.info("No resources change for "+count+" sec, Stopping battle");
surrender();
endBattle();
return image.wait(RETURN_HOME, 3000);
}
In the case the battle ends with 3 stars, the surrender() and endOfBattle() function do nothing because they did not detect either the surrender or the end of battle buttons.
This discussion is closed.
