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 18, 2014#111

@Antidote

Func FindPos(ByRef $Pos)
  Opt ("MouseCoordMode", 2) ;set mouse coord mode to 2
  Local $x = 1
  While $x = 1
 If _IsPressed("01") Then
$Pos = MouseGetPos()
$x = 0
 EndIf
  WEnd
  Opt ("MouseCoordMode", 0) ;set mouse coord mode back to 0
EndFunc

This worked thanks. I eliminated the last MouseCoordMode as it failed training troops correctly.

Also, I was able to attack but no troops was deployed. I'll take a look at it.

Dec 18, 2014#112

@antidote
It might not be good to discuss attacking features this early but I just want to mention this anyway. No need to comment about this. Just my thoughts.
Btw, the attack of Lazypressing is lazy lame but will work only for bully mode (as it was designed for). It does somehow get some resources outside and also 'some' in the storages inside a not well designed base that'll probably need wallbreakers, thus raiding inefficient.

However, circular or all sides attack will get all loots from the collectors outside and have a better chance of getting a star but will get zero resources inside any base. Thus circular attack or all border attacks even in straight line only need tier-1 troops. And if matched with minions, it becomes the most efficient farming ONLY for zombie bases a.k.a. dead fish.

Also, it would be nice to add feature the % or # of troops to initiate the attack as this will further increase raid efficiency. You may not be able to get all the resources outside on every raid you make but you would get better gold per minute that is only if the loot situation is good during a part of the day.. Furthermore if you have noticed, attacking less troops often times makes the loot situation more favorable.

BUT this raid strategy is also true when loot situation is BAD. As long as your raid efficiency is 1000 gold per troop, it is not hard to get 1million gold per hour even if the loot situation is bad. If the loot situation is bad, chances are bases with 80k loot are abundant. It's rather a waste to attack with full troops for only 80k resources each as we will only get an efficiency of less than 500gold/troop and clogging up the raid cycle time. In order to reach efficiency of more than 1million gold per hour, running after 80k resources with half or less the troop will do the job.

Just imagine your bot attacking and producing troops non-stop along with 5-6 barracks. And if you managed to loot just a minimum of 50k gold per attack for 20 attacks in an hour, you'll get 1million gold per hour which translates to 24 million gold per day in a bad loot situation.

I think these features aren't present in the existing bots in the market. Again just my thoughts.

Dec 18, 2014#113

@travis: Normally it has to zoom out all the way before you map your barrack, since the default position for every thing is max zoomed out. 2 possible reasons: either your village wasn't properly zoomed out before training starts (the bot send down keyboard 20 times to zoom out, I might have to increase it 30), or the bot fail to get the correct position for barrack thus it was clicking on the wrong place and then instead of clicking on close barrack to move on to the next, it click on the plus sign in gem (same location). I've experienced this before in earlier version of lazypressing. Can you make sure your village is zoomed out maximum first before you start the bot and tell me how it goes?
Also try this updated one, I edit a few things to make it more stable
http://pastebin.com/iDfJc3rZ
Bot no wait time, attack immediately: http://www60.zippyshare.com/v/46895537/file.html
Bot wait 15 mins before attack: http://www60.zippyshare.com/v/80690895/file.html
Download or compilt it in the same folder with Tesseract-OCR. Again this is unfinished and for testing only. I suggest just test run once or twice and monitor it since I cannot guarantee it won't go wrong. If anything unexpected happens, just close the program.

@AtoZ: I think I get what you mean. So you use 3 and 7 as base length and relies on the blank space in between to get left part and right part? Right part is always 3 digits and left part can be 0,1,2 or 3 digits depending on value. Very good approach I must say. Did you get that consistent pattern in tesseract's raw output? And did it work well with value < 1000? I've noticed the blank spaces before but didn't figure out what to do with it. Thanks man I'll try it out tonight.

For the attack I think it was because of the co-ord I use. I'm using 860x720 now but keep the base co-ord at 800x600 since all previous co-ord was in 800x600 when I first started. I get the x,y value then multiply with 800/860 and 600/720 to get the final number so it might not be exact. Also it relies on MouseCoordMode 0 (relative mode to active window) instead of 2 (relative mode of client area in active window) so if you keep it at 2 after barrack location it might not work well. I'll have to redo all co-ord when I have time. Can you try 860x720 see if it works?

I'm still lost at image search, it can easily detect static window image but fails hard in game. I tried the ones in coc-en folder (images are just .bmp renamed to .coc) but to no success. Only when I zoom in maximum, print screen, crop an image with a tree and search for it, it can finds easily. But with maximum zoom out it's a mess lol

Dec 18, 2014#114

For the attack strategy, you are right. I still think each method has its own up and down. I personally used both lp and lf, in my experience bruteforce approach used by lp or attack 'em all in lf is inconsistence in loot for each attack but in the long run can be more rewarding (for ex. 2 raids with < 30k loot followed by 3 raids with > 200k. Bully mode & dead fish is more consistent and less risky but might not give you as much in the long run.

But that is just pure in-game strategy. Talking about the code, right now I just use the default giant, 2 x barbarian, archer combo for testing. I need to make sure it can properly assign and drop troop unit first before moving on to other strategies, additional checks,.. Also many features rely on image recognition (which we both stuck on) so I guess I'll have to find a way for it to work. For the % of troops before attack, I believe lf currently set it at 90%. It's easy to implement if you can accurately read troop number from army camp. Thanks for your input, I'll take note of everything but in the mean time just work on core structure first. One thing at a time man :shadesup:

Dec 18, 2014#115

@Antidote
Your script stopped/got stuck at Checksearch() where the pixel searches are.

Bot Started..
Waiting for Clash of Clans to load...
Barracks' position loaded successfully
Barrack 01: 450, 485
Barrack 02: 193, 323
Barrack 03: 421, 154
Barrack 04: 684, 308
Zoom Out
initiate ATTACK() function
AssignTroop()
Initiate PrepareAttack()
Button($Attack)
Button($FindAMatch)
initiated VillageSearch()
Bot Stopped -by user

I used 860x720 BS Resolution. I'm not yet adept at pixel search but will try to find out what's wrong.

Dec 18, 2014#116

Amazing team work, glad to see everyone working towards one goal.

Dec 18, 2014#117

The pixelsearch is just looking for a specific shade of red from the End Battle button so it knows when to start reading. I cannot reproduce your error but I do notice sometimes the bot cannot detect a specific shade when battle finish to click return home. For CheckSearch you can use this old function instead.

Func CheckSearch()
   Local $Check = ""
   While $Check = ""
  $Check = StringStripWS(_TesseractWinCapture($HWnD,"",0,"",1,2,$Left*$x_ratio,$Top*$y_ratio,$Right*$x_ratio,$Bottom*$y_ratio,0), 8)
  Sleep(500)
   WEnd
EndFunc
Dec 18, 2014#118

@konloch: thanks, didn't expect so many people contribute :D

Dec 18, 2014#119

The pixelsearch is just looking for a specific shade of red from the End Battle button so it knows when to start reading. I cannot reproduce your error but I do notice sometimes the bot cannot detect a specific shade when battle finish to click return home. For CheckSearch you can use this old function instead.

Func CheckSearch()
   Local $Check = ""
   While $Check = ""
  $Check = StringStripWS(_TesseractWinCapture($HWnD,"",0,"",1,2,$Left*$x_ratio,$Top*$y_ratio,$Right*$x_ratio,$Bottom*$y_ratio,0), 8)
  Sleep(500)
   WEnd
EndFunc

0x0D355B = Midnight blue?

Dec 18, 2014#120

shit I just look up the hex. It's really midnight blue.. I think my pixel get color script fails to get the correct co-ord. I just printscreen and check again in photoshop. Can you change the value to 0xc00000? I use replace color and it's indeed the only spot on the screen with this color value. I will try to do the same to return home.

This discussion is closed.