I Coded an AI that Plays Clash Royale

Sdílet
Vložit
  • čas přidán 23. 02. 2020
  • This was made when Clan Wars first started and you only needed clanmates to farm crowns.
    Watch how I setup Clash Royale on my PC with Bluestacks to create a Python Bot that plays Clash Royale for me.
    My other video about Eve Online : • How I coded an AI to m...
    Follow me and support me, check out these links :
    Support me on Patreon ► / ombarus
    Join the discussion on Discord ► / discord
    Twitter ► @Ombarus1
    Instagram ► / ombarus1
    Website ► www.ombarus.com
    Email ► ombarus.dev@gmail.com
    Github ► github.com/Ombarus
    Music ► www.bensound.com
    My name is Ombarus and I'm a programmer / game developer from Canada who moved to Japan and decided to try my own luck with game dev.
    Attribution :
    Extract from Serral vs AlphaStar Game 2 : • AlphaStar vs Serral - ...

Komentáře • 149

  • @Manrija17
    @Manrija17 Před 4 lety +77

    As for the timer you can make your own and look to match the game timer. I didn't play a game so it's just an idea that can work. :D

    • @Manrija17
      @Manrija17 Před 4 lety +1

      One more thing as for the health of the tower you can use the same thing as you already did (check the color of the pixels at the place of the health bar). You ca check every few sec a few pixel and base of the color have a ruff estimate of the health.

    • @Ombarus
      @Ombarus  Před 4 lety +13

      I could start a timer as soon as I detect I'm in the action phase but I would probably be off by a few seconds depending on when I updated the screen. If I want more precision I still need to read the clock at least once. Though using my own timer after that would be a good optimization!

    • @Manrija17
      @Manrija17 Před 4 lety +2

      @@Ombarus OK then then check the pixel on the timer spot until it register the right one and then start your own timer and stop the checking process.

    • @sebsbot402
      @sebsbot402 Před 2 lety

      @@Ombarus can u make a bot for subway surfers

    • @confusedwheat4600
      @confusedwheat4600 Před rokem +1

      Genius, I'm gonna use this in my clash royale bot

  • @PizzoLab
    @PizzoLab Před 2 lety +61

    I was expecting something more complex (with reinforcement learning), but I loved the video and how you explained the whole process with all the problems you got and the way you solved them... comprised the reason you haven't done something more complex! 😂
    Really a good job!

  • @gilbertobizzo8191
    @gilbertobizzo8191 Před 2 lety +11

    I really enjoyed your video, the problems you encountered and how you solved them, I would love it if you continue it.
    Here are some ideas / solutions I've found that might help you:
    -Each troop has its own sound when placed, so you may identify too many of the opponent
    -you could understand what kind of troop the opponent has positioned besides the sound also from the speed
    -You can keep track of the time with an internal timer that starts at the beginning of the game
    -you could get a personal database of which cards are the strongest against others like arrows and minions

    • @mahamaslam2596
      @mahamaslam2596 Před 2 lety

      Where can I contact you? I have an idea about game

  • @TheLomotion
    @TheLomotion Před 3 lety +9

    I really enjoy that u are saying mana instead of elixir x)

  • @alongv3459
    @alongv3459 Před 2 lety +7

    You can use the lenght health bar to at least know the class of the card (tank or suport) and for the towers you now when they changed from full to damage, so after that you assumed that if it doesn't have any heath it is because is down. You can mix the health bar technique for trops and the spaw clock to imrpve the chances of knowing the card. Other way to know the tower heath is to calculate how much dameage has to recive with x card for y secons. There is an optimization for finding the cars in your deck once they do a complete cicle you can predict then.

  • @J4D3_UwU
    @J4D3_UwU Před 3 lety +3

    yeah ive been working on one and it can actually defend and decide what to do depending on what the enemy does ive been working on it for a while and ive been having the same problem with not being able to know what enemies are in the screen, i used the same thing with using the little box to see where enemies are and i had a pretty good player make me a deck and he also helped me decide what to do depending on where the enemies are on the screen, for that i split the game area up into 12 places 6 on the enemies side and 6 on mine so i had a general idea of where the enemies are and i then made 5 choices from best to worst so it knew what to do in every situation, my idea of seeing if the towers are broken was to take a picture of what there is when the tower is broken and look on either side for that and when is sees it it knows the towers are gone, i have some questions about this and i would love some help with trying to make mine better, thank you and great video!

  • @jordirivero
    @jordirivero Před 4 lety +1

    awesome, good job!

  • @rishabhgarodia410
    @rishabhgarodia410 Před 3 lety +8

    You can further improve your pattern matching time by resizing you images to lower sizes...maybe like 80*80 pixels or even lower. Maybe you can convert the crops to B/W and then do pattern matching, thereby reducing one channel altogether from the image. It will make you images blur or B/W and loose on details, but I think that the characters in Clash Royale look very different and small blur images or B/W images would give good accuracy nonetheless...

  • @nwl.0
    @nwl.0 Před 3 lety +11

    I don’t understand why this guy doesn’t have 1 million subscribers he deserves it

  • @claudioricciardiello9601
    @claudioricciardiello9601 Před 3 lety +1

    Instantly subscribed! Keep up the great work with Clash Royale, I am thinking to do something with the informations available in Royale API. basically I would like to make a program who learns from the games of the PROs and helps me understand what's the best answer to specific enemy attacks.

  • @noobsunleashed9703
    @noobsunleashed9703 Před 2 lety +3

    i wish deepmind or some other big ai company made a machine learning version of this, seeing as they made one for chess (alphazero) especially seeing as clash royale is essentially real time chess

  • @TheCubicLog
    @TheCubicLog Před 2 lety +2

    It would be pretty easy to figure out how much time is left
    there's this framework called tesseract - it does a pretty good job at extracting text from images if you parse the image a bit to make it black and white
    you could also maybe look at how much health the units have left based on how long the span of red pixels above them are

  • @evilmurlock
    @evilmurlock Před rokem

    this was very interesting. Woud love more AI videos

  • @checkcommentsfirst3335

    so much work wow !

  • @Ryuuken24
    @Ryuuken24 Před 2 lety +1

    This was impressive work. I wonder if this wouldn't be easier by using a video camera pointed at the screen, and you make a program to teach and A.I as you play, something like shape discrimination.

  • @yurij1590
    @yurij1590 Před 2 lety +14

    You could use OCR to recognize the time text and convert it to a string. Same thing for tower health, which you look at after checking the bar exists by checking if the color for the bar is correct (otherwise, it's full health).
    Recognizing the enemies might be harder, but maybe you can take some pixels below the red level indicator & check the resemblance of the pixel colors to recorded values (i.e., the values of pixels for giant's head add up to around 1000). Besides that, maybe you could do some post-processing on the difference of images & set a certain threshold, so only large & enemy-shaped(vertical) patches remain.
    Anyways, interesting idea & great video!

  • @mini4x494
    @mini4x494 Před 4 lety

    love this video going to sub & like :D

  • @emanuelnolasco3745
    @emanuelnolasco3745 Před 3 lety

    Awesome!

  • @ninjapig28
    @ninjapig28 Před 3 lety

    This is amazing

  • @ammarsajjid8258
    @ammarsajjid8258 Před 3 lety +4

    for tower health u can look up the level of the enemy tower and hardcode the max health after first hit make ur program read the health written and once the tower is destroyed enemy level disappears of u know tower health is 0

  • @torchtopher1861
    @torchtopher1861 Před 2 lety

    For number recognition, you can use tesseract ocr in python

  • @milanmlynar2753
    @milanmlynar2753 Před 3 lety +5

    maybe you do not need to figure out how much time is left, you just need to know, when the game starts, then you start the regular timer on computer?

  • @maximillianmusnr.2088
    @maximillianmusnr.2088 Před 4 lety +1

    Wow great video

  • @arjunprasaath5538
    @arjunprasaath5538 Před rokem

    Hey nice work, can you tell how much FPS you got and in which interavel do you take screenshots?

  • @seanthomas5303
    @seanthomas5303 Před 3 lety +26

    It seems like you should be able to train specific AIs to accomplish specific subtasks like elixir detection or unit detection or time detection.
    It would be easy to train those to be robust to changes in color and placement by image manipulation of the training sets.
    In fact you should be able to train a single network to output each state variable you're interested in with individual and combined losses.
    And while I'm thinking about it, those subnetworks could be directly fed into whatever network architecture you're working with.

    • @Seedzification
      @Seedzification Před rokem

      "easy"

    • @seanthomas5303
      @seanthomas5303 Před rokem

      @@Seedzification yeah I take your point. 'Easy' in this field means it's something that has a solution that's already known. It still takes effort to implement, but 'hard' doesn't mean 'takes a lot of work' it means 'it's not clear if you could even do it'. Elixir detection, unit detection, and time detection are 'easy' tasks only in the sense that anyone who does machine learning would likely be able to accomplish it (even if it takes a lot of work to do).

  • @filipfilipov2261
    @filipfilipov2261 Před 2 lety +3

    as in for the position of the units I think you can use a bitmap and as in for unit type you can find out the static addresses of the units using cheat engine, same for the timer. Great work tho

    • @filipfilipov2261
      @filipfilipov2261 Před 2 lety +2

      advanced level you can fully use a proxy packet sniffer to analyze the data and then make an AI to react with the specific packets but not sure if that would be legal :D

  • @murraywright1103
    @murraywright1103 Před 4 lety +1

    This is awesome! Great work!

  • @austinford4975
    @austinford4975 Před 2 lety

    Can you use movement speed to be able to somewhat vet which enemies get which counters? Usually tanks move slower.

  • @orangespuddy7118
    @orangespuddy7118 Před 3 lety

    Clash royale does have an api that you might be able to get some data from, such as grabbing the deck of your opponent so that you only have to look for those cards. You sadly can't use it to battle or anything but it may have some useful info for you to use if you ever revisit this. You might be able to change the pixels to black and white and make reading the screen easier too.

    • @Ombarus
      @Ombarus  Před 3 lety

      I tried B&W but I found it easier to say spot mana by simply looking at which pixels has the most red in the bottom instead of trying to use the relative luminosity of a B&W picture. Not aware of the API you're talking about. Do you have some documentation for it?

    • @orangespuddy7118
      @orangespuddy7118 Před 3 lety

      @@Ombarus Yea, developer.clashroyale.com, you have to make an account to see the documentation for some reason but theres a bunch of data that can be grabbed from it

  • @z-production6551
    @z-production6551 Před 2 lety

    How long would it take to calculate if you give the entire game arena as input?

  • @EthackCreation
    @EthackCreation Před 4 lety

    In the game, the time for the 3 crowns win is the first 3 min and the time for the sudden death is 2 mins just after the 3 crowns time ends. I guess the game time is not a big deal but time taken by the CNNs to recognize the characters and processing is the real heck. Predicting the mana of the opponent team and placing the right troop in the correct position is what pro players do while playing the game. Perhaps, mimicking that strategy could be a better idea.

    • @Ombarus
      @Ombarus  Před 4 lety

      Yes, It would be nice to know the time precisely but a good hack would just be to keep a separate timer... it might be off by 3-4 seconds but that's probably fine... Predicting the opponent's mana would be relatively easy too if I could identify the troops on the board... so it all comes down to identifying troops on the board.... I'm pretty sure there's some convolution networks that could do it already (after all there's neural net capable of recognizing thousands of images).... I just don't have the knowledge to make one from scratch only for clash royale :).

  • @voon7820
    @voon7820 Před 3 lety +1

    This video deserve a three crowns

  • @DrWho2008t101
    @DrWho2008t101 Před 3 lety

    thanks

  • @houtenklaas7205
    @houtenklaas7205 Před 4 lety +1

    GG dude GG

  • @creativeleo
    @creativeleo Před 4 lety

    Wow you're genius

  • @lunussextips9966
    @lunussextips9966 Před 3 lety +1

    The easiest way i think is to inject into the game code and directly check the game memory for objects

    • @Ombarus
      @Ombarus  Před 3 lety +2

      I heard about this but I have no idea how to pull this off, especially for an Android game running inside an emulator.

  • @maker5732
    @maker5732 Před rokem

    For the mana you can calculate it Your self Ande for the cards after you play a card it goes back in the cycle so you can esactly calculate, after you ha e played 4 cards and seen which card you ha e at hte begginning, all the card that you ha e during the entaire game without cheking the screen

  • @flexhub100
    @flexhub100 Před 2 lety

    Which software you use

  • @michaelplaczek9385
    @michaelplaczek9385 Před 2 lety

    I think there's an API now

  • @trashcontent9637
    @trashcontent9637 Před 2 lety +3

    I’ve NEVER seen someone automating any supercell game…
    Great video!

  • @miurabynes
    @miurabynes Před 2 lety

    Guys, what if you use sound to identify minions, every unit has its own unique deploying sound or several, u could match them, and the time number of level appears, to stick it to them, so that you could calculate speed per square and where it will be at the certain moment of time?

  • @dashingmlg601
    @dashingmlg601 Před rokem

    you can spectate yourself on a different account and see what cards there playing and where and how much elixir they have

  • @zarakikenpachi1238
    @zarakikenpachi1238 Před 3 lety

    Can it make for every game ?

  • @ducking_fonkey
    @ducking_fonkey Před 3 lety

    Hey bruh
    Divide image of game on cells that would help and also you can lower size of image and AI left only to do

  • @user-bf6if2rs4x
    @user-bf6if2rs4x Před 6 měsíci

    hello,your vid is very interesting😂i want to konw if the chatgpt could
    help this work

  • @thetrustypwo
    @thetrustypwo Před 2 lety +1

    I may be able to help you with that, you got the source code somewhere?

    • @Ombarus
      @Ombarus  Před 2 lety +2

      I do have the source but I haven't used it since the video so it's quite outdated at that point github.com/Ombarus/clashAI

  • @gotcaught395
    @gotcaught395 Před 2 lety

    What module did you use for the machine learning

    • @Ombarus
      @Ombarus  Před 2 lety +1

      I didn't get very far with Machine Learning. I was trying to implement reinforcement learning with SciPy but it's not really made for that. I tested some simple algorithm using tic-tac-toe and couldn't get anything to work. What I show in the video is a simple hand-crafted algorithm

  • @levsmolsky8354
    @levsmolsky8354 Před 2 lety

    3:23 lol as a clash royal fan and a magic the gathering lover I can relate :)

  • @b34rpolar90
    @b34rpolar90 Před 3 lety +4

    You should code with the 2.6 hog. You basically can defend any unit with the gunner and the snow golem. Perfect for attack and defense if you know the Strat and works with the program to make it simpler. Skel+ gunner. ice spirit+ gunner Log + gunner all works

  • @spock3009
    @spock3009 Před 3 lety

    This is not an AI,this is just a bot. Clash Royale Bot

  • @marcelpuhlmann3581
    @marcelpuhlmann3581 Před rokem

    It would be so nice to have a clash royale AI like in chess, that would beat the best players with bad matchups

  • @vladimirgetselevich4704

    Good work! I am impressed. But I think that even if you will get all the information about the current game board state and your and your opponent cards on the field and in the waiting stack and remaining towers health and time it still will not be enough to write RL algorithms. Since you need to model behavior of each of the cards in the present and the future. So you need to know the exact algorithms of each card behavior implementation in all different possible situation. This info Supercell has but it is very difficult close to impossible deduct from analyzing the screen. You can try to go in the route of DeepMind with Atari games and try to learn algorithms solely from screen pixels but these were much simpler games I think.

    • @vladimirgetselevich4704
      @vladimirgetselevich4704 Před 3 lety

      It would be more realistic to do such a work, like writing an algorithm for ideal play from inside of Supercell. Possibly they even have something like this, since they have a training arena, right?

    • @Ombarus
      @Ombarus  Před 3 lety

      I don't think it's very important to know the behaviour of each card because you cannot control them once they are on the board so it becomes much like a game of chess. For any set of time/card/position/health that you have seen before the ML should be able to predict the outcome. Of course, I never got there so it's only a theory

    • @vladimirgetselevich4704
      @vladimirgetselevich4704 Před 3 lety

      Well usually in chess and other similar games to choose a good move you do look ahead (min max or monte carlo trees), you try to predict a combination of moves yours and your opponent until some depth and at the end of the branch you estimate the received position and propagate back the conclusions. So beside of predicting what card opponent can put on the game field and also where the algorithm needs to predict how existing cards on the board and towers interact in a given time frame. Seems as very interesting research problem in case you have access to all game info.

  • @sjkgaming2174
    @sjkgaming2174 Před 2 lety +1

    Can you make for moblie legend?

  • @mato4290
    @mato4290 Před rokem

    Can you try again whit the help of ai

  • @dpvlogs0921
    @dpvlogs0921 Před 3 lety

    I want it for clash of clan as well

  • @teambrasil6801
    @teambrasil6801 Před 2 lety

    you can make a current version, thanks in advance!!!

  • @ahmdmoadi
    @ahmdmoadi Před 2 lety

    link for the AI plz :)

  • @GagandeepSingh-ku2ss
    @GagandeepSingh-ku2ss Před rokem

    hey ombarus can u code an AI that plays clash of clans

  • @prasannakukade300
    @prasannakukade300 Před 3 lety +2

    bro it would be much better if you directly use data from the source in code form in backend rather than in visual...backend code will clearly tell what is what

    • @Ombarus
      @Ombarus  Před 3 lety +2

      If you know of a way to decode or capture data from the game playing on an emulator I'd like to know how to do it because I can't think of a good way of doing that.

    • @Kami_26
      @Kami_26 Před rokem

      I think there is a java decompiler that splits the entire game and its java code

  • @sp11oki
    @sp11oki Před rokem

    Any one named not a bot or not a ai makes it damn obvious its a ai

  • @kyleruan
    @kyleruan Před rokem

    Think about how the recording work. Grabbing image and doing analysis is slow. Too much input out put; if you perfectly simulate what will happened in the battle filed then we could just grab the packages for troop placing. Furthermore, knowing battle system Behind is the key to train a strategic AI which could predict win or loss.

  • @Anonymous-qb4vc
    @Anonymous-qb4vc Před 2 lety

    Base builder bot

  • @h8txii
    @h8txii Před 2 lety

    Can u make a bot for Android

  • @confusedwheat4600
    @confusedwheat4600 Před 2 lety +2

    I'm creating my own AI for this game with about 80 lines of code, and it got to 253 trophies, but I'm struggling with identifying where the opponents are. How did you do this?

    • @knuckle_head
      @knuckle_head Před rokem

      1. did u ever find a fix?
      2. could i use the ai?

  • @qabrm5367
    @qabrm5367 Před 3 lety +1

    After *sometime* I made myself (AI)
    Now I don't want to do anything ✌️

  • @noobsunleashed9703
    @noobsunleashed9703 Před 2 lety +1

    3:01 so pretty much egolem

    • @Ombarus
      @Ombarus  Před 2 lety

      Yes -_-''. But I don't think my AI can reach Arena 11 so Giant-Balloon it is!

  • @eoalmadanepai4683
    @eoalmadanepai4683 Před 4 lety +1

    In reddit they selling clash Royale autootouch bot

    • @Ombarus
      @Ombarus  Před 4 lety +2

      From what I see it's a bot to open chest and lose a certain number of trophies... it doesn't actually try to play the game.

    • @eoalmadanepai4683
      @eoalmadanepai4683 Před 4 lety +3

      @@Ombarus I don't understand why people pay for that 🤔🤣

    • @eoalmadanepai4683
      @eoalmadanepai4683 Před 4 lety +5

      @@Ombarus I don't need to pay to lose trophies Im already a pro losing trophies

    • @eoalmadanepai4683
      @eoalmadanepai4683 Před 4 lety +2

      🤣🤣🤣

    • @Ombarus
      @Ombarus  Před 4 lety +3

      @@eoalmadanepai4683 The tilt is real... I was trying to make a AI that's better than me.... I failed but it was fun :)

  • @zarakikenpachi1238
    @zarakikenpachi1238 Před 3 lety

    Why you dont use Api of clash royal ?

    • @Ombarus
      @Ombarus  Před 3 lety

      I'm not aware of Clash Royale having any sort of Api. If there is please let me know where I can find some documentation about it!

  • @thayaganthusiyanthan9708

    Is there any source code

    • @Ombarus
      @Ombarus  Před 2 lety +1

      It's not very pretty but you can check out my github : github.com/Ombarus/clashAI

  • @badboygm9760
    @badboygm9760 Před 3 lety +1

    I can just say wow 😀😍

  • @Erbmon
    @Erbmon Před 3 lety

    I don't know if you implemented it, but you can use a Nvidia GPU to do the pattern recognition with openCV. This is probably possible with a modern computer but is far from a weekend project

  • @Hexnano
    @Hexnano Před 2 lety

    3:23 MTG player? 😅

  • @dieweltentdecker5878
    @dieweltentdecker5878 Před 4 lety +1

    Code pls!!!

    • @Ombarus
      @Ombarus  Před 4 lety +3

      I committed whatever I had here : github.com/Ombarus/clashAI Use at your own risk.

  • @charlieclifton2091
    @charlieclifton2091 Před 4 lety

    Just leave it on overnight and you will probably be in a really high arena

  • @checkcommentsfirst3335

    mana = elixir??? xD

    • @Ombarus
      @Ombarus  Před 4 lety +5

      The pink stuff that you're always missing 1 for the perfect defense....

    • @mugivamv3396
      @mugivamv3396 Před 4 lety

      Apparently, he says Mana for people who might not be familiar with the game, yet they still clicked on the video because they are interested in the AI topic.

  • @emoboy3448
    @emoboy3448 Před 2 lety

    Sir please contact I need your help

  • @thyentertain369
    @thyentertain369 Před 3 lety +3

    Get Elon fund ai for this game.

    • @dutiot2326
      @dutiot2326 Před 3 lety +1

      He scaired of ai yet he want a chip to be put in our heads.

  • @linear2822
    @linear2822 Před 4 lety

    Can you make an ai play a roblox game called black magic 2

  • @machomb
    @machomb Před 3 lety +1

    So it's not really AI, just a bunch of ifs. A little disappointed , but good effort nonetheless.

    • @Ombarus
      @Ombarus  Před 3 lety +1

      I did spend hours trying to program a Deep Reinforcement ML using sklearn but the library doesn't really support it and it didn't work so I had to leave that part out of the video :).

    • @machomb
      @machomb Před 3 lety +1

      @@Ombarus I'm trying to do the same, but with a different game, and I've been struggling to implement the ai for days. I might have to go with a simpler approach too.
      I liked your video, but calling it an ai is misleading.

    • @ashishthakur3420
      @ashishthakur3420 Před 3 lety +1

      @@machomb hey i was preparing myself to create an AI for a game.I am completely new to AI and wanted to do something like shown in this video but for a different game, i can code in python and other languages too could you just give me a head start of what all things i need to study and know so i could work my way up
      Thanks

  • @matejnovosad9152
    @matejnovosad9152 Před 3 lety

    Why not just make a CNN instead of hassling with this?

    • @Ombarus
      @Ombarus  Před 3 lety

      That was the idea. Never got there though. So many questions. How to get enough training data? what kind of CNN? How do you train it? It's not like Clash Royale provides an API for AI to play like Starcraft and I can't exactly make my own simplified game like Chess or Go...

    • @matejnovosad9152
      @matejnovosad9152 Před 3 lety

      @@Ombarus yep that is where the challenge lies. I will try clash royale on my own. You would have to fiddle a lot with game data and modding the game perhaps. If you are looking for a fun project we have this discord for rocket league discord.gg/H4zQfUQs most of the bots there are hardcoded but some are machine learning and we are working on a gym env that has all the bugs out. Sort of a beta version is now out. Let me know if u joined. Good luck and have fun with future projects

    • @trickybarrel444
      @trickybarrel444 Před 2 lety

      ​@@Ombarus The hardest thing is to find a good loss function. How do you know whenever playing a card at a certain position is good or bad?

    • @Ombarus
      @Ombarus  Před 2 lety

      @@trickybarrel444 I had a few ideas. Of course rewarding damage to the enemy's towers, punishing damage to your own tower and damage to enemy units. For enemies it might be enough just to reward any decrease in the number of enemy units on the board.

  • @MasterBronzeElite
    @MasterBronzeElite Před 4 lety +2

    Coded and AI should not be in the same sentence lmao. You don't code AI, AI self learns. You coded a bot: not an AI. AI also learns and gets better over time - which your bot does not do.

  • @sara69xd
    @sara69xd Před 2 lety

    Make coc bot and give the code!

  • @MrCaptainTea
    @MrCaptainTea Před 3 lety +1

    I don’t know if you would ever be interested in doing this, but you can make ridiculous money by coding AIs for games and selling them. Leaguesharp was just a script service and they made over 10 million in their whole lifespan