Тёмный

Automating Android Games with Python: Stick Hero 

Engineer Man
Подписаться 537 тыс.
Просмотров 382 тыс.
50% 1

Automating games regardless of platform is a fun and challenging way to learn programming skills whether it's Python, JavaScript, or otherwise. Oh, and getting huge high scores is cool too.
Hope you enjoyed the video!
Check out this code here:
github.com/engineer-man/youtu...
Join my Discord server to chat with me:
/ discord
Check out some code on my GitHub:
github.com/realtux
github.com/engineer-man/youtube
Come visit us on Reddit:
/ engineerman
Other Social:
/ _engineerman
/ engineermanyt

Наука

Опубликовано:

 

20 июн 2024

Поделиться:

Ссылка:

Скачать:

Готовим ссылку...

Добавить в:

Мой плейлист
Посмотреть позже
Комментарии : 486   
@EngineerMan
@EngineerMan 4 года назад
Did I win? What game should I do next?
@FinanceForecastbyAI
@FinanceForecastbyAI 4 года назад
Try the game go
@aryanbhatia6992
@aryanbhatia6992 4 года назад
Please do Tower Twist it will be very interesting to see how you approach it...
@stewie055
@stewie055 4 года назад
Dark souls
@Redachouhani
@Redachouhani 4 года назад
You did bro! Big time!
@greenin5537
@greenin5537 4 года назад
What about the old classic vector
@semism
@semism 4 года назад
i didn't even know you could pass shell commands to a phone like that, let alone use python for it, thanks for sharing e-man.
@GamingGleeSquad
@GamingGleeSquad 4 года назад
I am curious after knowing this,What are you going to automate next? 😅
@DaDrummerthe1st
@DaDrummerthe1st 4 года назад
Is he sending commands to the actual phone?
@chedisLoL
@chedisLoL 4 года назад
@@DaDrummerthe1st yes, he's sending commands to the device shell
@harshavardhan6349
@harshavardhan6349 4 года назад
how do we do that?
@anirudhvallabh419
@anirudhvallabh419 4 года назад
@@harshavardhan6349 'adb' is Android debug tool, you can get it by installing android SDK for you OS. Enable usb debugging in your device developer options and connect it to your pc by a cable. Install an android emulator to show the real connected device as he does it.
@user-eo5bh2zg2f
@user-eo5bh2zg2f 4 года назад
Since the guy has to run across the distance of the bridge, if you pass distance as the parameter for sleep you should get a pretty dynamic/accurate result
@gouravchouhan1790
@gouravchouhan1790 3 года назад
Someone's here is smart
@undefinedchannel9916
@undefinedchannel9916 3 года назад
distance is how long it takes for the bridge to fall but he'll also need to take in account the time it takes for the stick figure to run across.
@denic6861
@denic6861 3 года назад
@@undefinedchannel9916 you’d just have to divide the distance by the constant speed of a player moving per pixel and that’ll give you a near perfect rest time
@prenomnom5637
@prenomnom5637 2 года назад
i thought the same
@nabhyaplayz9665
@nabhyaplayz9665 2 года назад
i dont think that would work perfectly as the distance is not the same as the time the person has to hold on the screen bc the distance can be like lets say 100 px but i think holding only 0.1 sec on the screen would not make that far as you can see in the video too it sometimes drops a little bit far so its no perfect but it works so for the perfection someone would have to actually calculate the exact distnce it draws in like 1 sec and then we can get the value for 1 milli sec according to that
@shreyassable4981
@shreyassable4981 4 года назад
EM, the creator of Stick Hero wants to know your location.
@teenspirit1
@teenspirit1 2 года назад
The stick growth uses an easing algorithm, so at the start it grows slowly and then grows a little faster. That's why you miss on short sticks and very long ones.
@SunnyNagam
@SunnyNagam 10 месяцев назад
I bet you could account for that by making the percentage decrease with the distance by some other coefficient. Like instead of * .98 it's * (.98 - 0.000002*distance)
@Hyuts
@Hyuts 4 года назад
The flow of this video feels like the perfect speed for me.
@gouravchouhan1790
@gouravchouhan1790 3 года назад
Yeah, that exactly how everything should be. Perfect
@tommasog.5561
@tommasog.5561 4 года назад
Actually I tried to recreate the script and I found a lot easier to just find the first gap and then the little red box at the center of the second column. It worked fine
@haydencordeiro
@haydencordeiro 4 года назад
Hey can you help me set up the adb
@ishkapoor7931
@ishkapoor7931 4 года назад
hey can you help me with the same to find the gap between the pillars... I'm really confused!!!
@az-db3rd
@az-db3rd 3 года назад
I thought the same when i saw the video
@asoliev698
@asoliev698 3 года назад
Haha exactly what I was thinking
@Xevion
@Xevion 3 года назад
@@haydencordeiro Why do people ask for help on RU-vid comments? And then like the comment? Figure it out yourself dumbasses.
@ashuborhade4170
@ashuborhade4170 4 года назад
Rumor has it... Engineering Man is secretly The Stick Hero
@bigjoepro75
@bigjoepro75 4 года назад
This was INCREDIBLY interesting! Hope you do more stuff like this in the future.
@Hasan...
@Hasan... 4 года назад
Easier way: Have the exact height for the 'Red box', and start and stop based on the distance till the Red box, without worrying about any Blacks (or even gaps) because the starting position of the Ninja remains the same on the screen.. It's a matter of minor trial and error to calibrate. Great video E-Man !
@Hakim_fz
@Hakim_fz 2 года назад
اخ حسن ايش رايك ابتدي بتعلم لغة الجافا او بايثون؟
@innerinsights224
@innerinsights224 Год назад
Someone always comes along and shortens something you thought was destined to be much more
@someonlinevideos
@someonlinevideos 4 года назад
This is my favorite video of yours. Thanks! Loving python after picking it up lately.
@ScadooshGoat
@ScadooshGoat 4 года назад
I love the logic used to solve problems. Want to see more videos like this.
@wilcosec
@wilcosec 4 года назад
The end of loop sleep time could be a function of the distance.
@marnotto8269
@marnotto8269 4 года назад
Smort
@kieudung
@kieudung 3 года назад
plus some times for the character to move between 2 pillars
@manuelnovella39
@manuelnovella39 4 года назад
Wow, this was so much fun to see, and so interesting! Thanks! Keep doing similar stuff, I think people will love it!
@thaddaeusmegow
@thaddaeusmegow 3 года назад
Sweet and informative, thanks dude! I wanna add to the convo that ISPs will frequently reassign IPs to consumer modems and restarting it (or power events) can result in the WAN IP discussed here changing. This would require updating users and/or dns records.
@UpDownAndUnder
@UpDownAndUnder 4 года назад
Woah, this rekindled my interest in coding again. Nice work, EM! I would like to see how you'd do with some bullet hell games like Bullet Hell Monday
@0xbitbybit
@0xbitbybit 4 года назад
This was awesome! Do more stuff like this please! Love your video style too, straight to the point and coding, keep it up :) subscribed!
@dummypg6129
@dummypg6129 4 года назад
This is actually an interesting problem-solving in programming to control android. I did same trick for Piano Tile game.
@jemakrol
@jemakrol 3 года назад
Python is just awesome. Great video! Beyond the scope I know but I'd scan from top-left downwards to get the proper starting location of Y without hardcoding. That would suggest breaking out the transition detection into a reusable function. Furthermore, I feel it's kinda waste if time to store the screenshot on file. Haven't tried the libs in question but if it's possible to screen cap directly inro memory I'd consider it way more neat. Finally it would be interesting to actually clock the time drawing the stick and dynamically adjust the timing along the way to get better accuracy. Of course, that's all overkill for a proof of concept as shown here. However, it does take into account good practices and interesting extensions like reusability and device independent code. I believe the code required to do it wouldn't be too complicated. Again, great video!
@MuhammadKhalid-cv4mu
@MuhammadKhalid-cv4mu 4 года назад
This is what I needed for an automation project I have in work, thanks!😊
@naveenkumarpolipalli5930
@naveenkumarpolipalli5930 3 года назад
Engineering Communicated with Unparalleled Clarity 👏🏻
@michaelhearmon9965
@michaelhearmon9965 4 года назад
Thank you for that, always looking for Python ideas, you've just gained a sub
@sasakanjuh7660
@sasakanjuh7660 4 года назад
Well, this one was super fun! :D Hope to see more videos of this sort! :)
@DerekWelchElectric
@DerekWelchElectric 4 года назад
Looking forward to trying this, thanks for the video!
@fototrip9346
@fototrip9346 3 года назад
Great and simple approach. It's probably overkill but instead of 'time sleep' in the end we can pull image and as soon as previous is different from current start applying the algorithm.
@Chris-no9tn
@Chris-no9tn 4 года назад
Stumbled across this while random video hopping on RU-vid. Fantastic - I work with Python daily, and do automation with it. I never thought about applying that to android games. You have a new subscriber here. looking forward to seeing more :)
@EngineerMan
@EngineerMan 4 года назад
Welcome!
@Chris-no9tn
@Chris-no9tn 4 года назад
@@EngineerMan Many thanks! You inspired me to try out some python adb stuff myself, so I built a Sudoku Solver for the Sudoku.com Android App.ru-vid.com/video/%D0%B2%D0%B8%D0%B4%D0%B5%D0%BE-bTKpGMR1km0.html Have a look if you have 30 seconds.
@williamdowling7718
@williamdowling7718 3 года назад
i know i'm kinda late to the party, but i just found this today. Seems like the sleep command at the end of the loop should be dependent somehow on the length of the previous transition. because a longer gap will take longer to walk across, having a set time interval isn't optimal. alternatively you could put a condition at the beginning of the loop that checks the delta of your transitions to see when the screen scrolling motion stops indicating the character has arrived at the edge of the next platform and the rest of the loop is ready to go, no waiting. Good stuff man. can't wait to see what else you've got in store for me on the channel!
@alexdominguess
@alexdominguess 4 года назад
Good job! I would have a diiferent approach on how to find the distance by finding the red square that each column has using the pyautogui that has a function that finds an specific image in the screen and return the center position of that and then do all the math you did.
@bsal5347
@bsal5347 3 года назад
I am currently learning python, can do some basic stuffs but i enjoy watching what these modules do even though i havent heard most of them !!!
@6s6
@6s6 4 года назад
Can you do a tutorial on making a basic Android app? Or go over an introduction to adb and scrcpy?
@eduardob5463
@eduardob5463 2 года назад
Maybe the 2.5 seconds for transition could be changed as percentage of gap. Really awesome work! Congrats!!
@e5caflowne500
@e5caflowne500 4 года назад
Awesome! Keep doing! I got an idea before you begin the next game: Show us how to configure your notepad(atom, right?) and the Virtual Android environment. So we can sync :)
@robertpearson2143
@robertpearson2143 4 года назад
I liked the way you did the logic... and Thank you for sharing.
@MakeDataUseful
@MakeDataUseful 3 года назад
Thanks for sharing, this is really awesome, I had no idea there was a thing called Android Debug Bridge and that you could control it with Python! I am excited to create some tutorials controlling android from Python! Subscribed.
@mikapeltokorpi7671
@mikapeltokorpi7671 4 года назад
Nice 1-1,5 hours coding task. Including full environment installation (had already only Pycharm). I did it some coding with openCV, as I have experience working with it - and I would assume to code more on that side, anyways. The most difficult one was to detect where the ledge the ninja was standing is *in all situations*. In that sense this is a good task also, that your phone may have different speed with keypress; I had to adjust speed by factor of 0,73. 100 climbs(?) passed already.
@klarkforgetit2642
@klarkforgetit2642 4 года назад
It would be interesting if the program would find this percentage on his own by measuring how long it takes to grow the stick a certain distance.
@seppel198021
@seppel198021 4 года назад
You make it look so easy. Bravo!
@maxikuck1308
@maxikuck1308 4 года назад
Instead of multiplying by .98, you should've subtracted by a constant value. the problem was that the stick doesnt spawn exactly at the start of the gap but a few pixel to the left.
@woosal-kc7tr
@woosal-kc7tr 4 года назад
interesting technique and funny to watch, thanks for sharing! :D
@tipsbunker4431
@tipsbunker4431 2 года назад
Got it working so that he also catches the cherries! Great channel keep it up
@simobermaki
@simobermaki 4 года назад
I've been searching for a while for a way to automate some stuff on android, i did know about adb and adb shell since i've been rooting for some years now, but damn to be able to use python as well!! that's mind blowing, is there a documentation on shell commands? Have you thought about social media automation?
@befruky5868
@befruky5868 4 года назад
you most likely will get banned by instagram twitter... if you automate follows likes as they have a limit
@Jack-yz6yp
@Jack-yz6yp 4 года назад
@@befruky5868 For this you're probably better off using selenium (unless it's something like Snapchat where you can't use a web client)
@dairop3220
@dairop3220 4 года назад
@@Jack-yz6ypYep selenium is better but I don't think it work for android, only on PC
@lucasarnolds1596
@lucasarnolds1596 4 года назад
Great Video. Hope that similar videos are coming soon :)
@DaDrummerthe1st
@DaDrummerthe1st 4 года назад
Give us more! Splendid way to learn more Python!!!
@MrAjmal2010
@MrAjmal2010 3 года назад
This guy is really awesome 👍👍👍 keep sharing. You motivated me to learn python after watching your videos.
@Pertinate
@Pertinate 4 года назад
Btw, you can see the coordinates (it's actually the delta/change in touches) from the developer options on your android device
@bargey13
@bargey13 4 года назад
This comment saved me! if you want to turn on the dX, dY, Xv, and Yv coordinates, they are in your developer > input section.
@Nik-rx9rj
@Nik-rx9rj 2 года назад
First Cr1tikal and now you. The two Florida men that make Florida a proud state. All jokes aside, I've watched your videos for a little while and I'm a huge fan. Thanks for the videos, man!
@EngineerMan
@EngineerMan 2 года назад
You're welcome, glad they've been helpful :)
@elijahmedrano2068
@elijahmedrano2068 3 года назад
You are an inspiration. Thanks for the awesome videos
@Jakub1989YTb
@Jakub1989YTb 4 года назад
Great idea! I was thinking about automating few android games my self too. Can you please elaborate more about how to connect the phone and get the adb working? That's the only part this video is missing.
@swing-o-gram
@swing-o-gram 4 года назад
Android is super easy to connect via ADB. All you'll need is the adb drivers and you're good to go in the command line.
@1996Pinocchio
@1996Pinocchio 4 года назад
There are probably enough videos about it on youtube already :)
@Katatonya
@Katatonya 4 года назад
you can do it through wifi too,, check google on how to
@PLumisko
@PLumisko 3 года назад
Damn, nice one - python is so fun and easy - I need to learn it.
@marcoscoding7275
@marcoscoding7275 4 года назад
I think that you can calculate the "line draw" rate, making a first screenshot then press for 1000ms then screenshot again and measure the distance (even using a photoshop or anything else), that would be a solution, I don't know if there are lags when you take screen shot, but in case of not, that would be more accurate measure
@______--_
@______--_ 3 года назад
Man that's awesome. I wish i could be as good as you are one day. :) happy coding everybody!
@yassinemessaoudi
@yassinemessaoudi 4 года назад
Wonderful video !
@Bianchi77
@Bianchi77 2 года назад
Vote up, nice video clip, thank you for sharing it :)
@DrGearHeadSS
@DrGearHeadSS Год назад
This was so interesting. It makes me want to learn how to do this.
@avikhandakar
@avikhandakar 4 года назад
Please continue this series.
@samORDOCH
@samORDOCH 3 года назад
Please make more of this kind of content
@MrQuenonoscaguen
@MrQuenonoscaguen 4 года назад
Loved it!!
@amrdaking1
@amrdaking1 3 года назад
it's scary seeing u code O.O u make it looks super easy
@FatLingon
@FatLingon 4 года назад
The sleep-timer could be optimized based on the distance-value, the ninja travels that distance, thus the animation time should roughly be a multiple of the distance-value + a set value.
@wolfrig2000
@wolfrig2000 4 года назад
I have no idea what's going on, but it's super interesting, I'd like to learn to code and Python seems to be able to automate really well!
@TommyReady
@TommyReady 3 года назад
Wow, this is kinda cool and I didn't know possible with an emulator. Now I have to try to make my own.
@EduAnmoldeep
@EduAnmoldeep 3 года назад
Great Video man!, Just a doubt, what you are using to run the game ?
@theltrain458
@theltrain458 Год назад
This was great. I am learning from you.
@seba123321
@seba123321 4 года назад
Awesome idea!
@r_t9419
@r_t9419 4 года назад
I learn a lot from your methodology. Tnx
@r00tku
@r00tku 4 года назад
You could use a distance multiplied by a certain coefficient as sleep time. That way, you could minimize the amount of time the bot waits on shorter distances.
@Hugos68
@Hugos68 2 года назад
doesnt it move faster on longer sticks?
@kithuto
@kithuto 3 года назад
Hi! Really good video. What are you using to emulate the phone device?
@azr_sd
@azr_sd 4 года назад
Hi Enigeer Man.. as always awesome video :) Can you please make some videos on docker and microservices ?
@ademdjek1253
@ademdjek1253 4 года назад
I liked your video ... That's awesome ❤️
@yamikuro1098
@yamikuro1098 4 года назад
I would really want to see how you automate game like "Summoners War" that would be a challenge ^^
@Nirvanaki
@Nirvanaki 4 года назад
i am using autoclicker to finis hmy toa and toah. you can start with that :P
@barungh
@barungh 4 года назад
Amazing ... More videos like that ... Something with C too
@felineentity
@felineentity 4 года назад
Taking a screenshot makes sense, but I wish there was a more "live" way of reading screen pixels in general. If you could read pixels as they update you could press the screen until a certain pixel above you turns black, always giving you the right distance.
@EngineerMan
@EngineerMan 4 года назад
I intend to experiment by using opencv to monitor the screen in real time then apply a solution in that way. Stay tuned.
@hexa-b
@hexa-b 4 года назад
@@EngineerMan your resolution is the "long pole in the tent" when it comes to using CV. For this simple task it would be suitable, however operating on text/more intricate designs makes it far less trivial. Also, maybe you can consider saving the screencap to a bytesIO object to ensure you're always operating on the correct image. You can reduce your time.sleep that way as well. Thanks for the videos! Keep it up!
@ghitapaints91
@ghitapaints91 3 года назад
This is sooo awesome!
@pw5687
@pw5687 3 года назад
hey mate, was wondering what software you use to get the android screen on your pc so you can see coordinates?
@forestcat512
@forestcat512 4 года назад
very good video!
@niklaskras5498
@niklaskras5498 Год назад
if you dont want to write the image to your harddrive all the time you can use img = np.array(pil.open(io.BytesIO(image))) with numpy, PIL and io to convert it for image recognition or whatever
@awsumgeorge1
@awsumgeorge1 4 года назад
Small tip: Its unnecessary to write the image to a file and then open it again to read it. It probably slows the script down by quite a bit, especially with a hard drive (not ssd). Otherwise really solid video man :)
@jeremyshorter2641
@jeremyshorter2641 4 года назад
Using the red spot on the top of the pillar as a reference point instead of the beginning of the pillar might help to make the program shorter
@wirechair
@wirechair 4 года назад
Hey, awesome work! Do you know where I learn more about image analysis? Like pillow and maybe stuff to learn computational photography? Thanks in advance!
@trevorrowe5126
@trevorrowe5126 3 года назад
Georgia Tech's Masters in Computer Science program has a computational photography course, and all of the lectures are available for free online. Look up OMSCS Computational Photography and there should be a link to the lectures on the course page.
@Sole880
@Sole880 4 года назад
You should show a sped up clip of your automated game at the end, like an hour of it playing the game all sped up to a minute for us to watch, and if you stick an ad the first 3 seconds in to it then you can most likely get good ad view time, just make sure you have good attention grabbing- remix making music for the sped up clip so it will take their attention before they decide to stick through the ad
@XxdualpistolXx
@XxdualpistolXx 4 года назад
Great video. Do you use any specific scrcpy command to view the x and y coordinates?
@phillip9245
@phillip9245 Год назад
Its not a scrcpy command, you can enable this on your phone under 'Developer options -> Pointer location'
@jamboy4308
@jamboy4308 2 года назад
At least someone is going after scammers. Not the phone company. Not the government. thank you!
@Richard-xu7kz
@Richard-xu7kz 3 года назад
Engineer man, nicely done. Q. If the start point is always the same and the height does not change, why not got to the row that contains the target piece, check that row for the red target RGB values and subtract the difference?
@abhijeetghosh27
@abhijeetghosh27 4 года назад
Amazing 👏👏👏
@AmrMKamel
@AmrMKamel 3 года назад
Great video thank you 🙂
@marty40
@marty40 4 года назад
I couldn't unpack any values from the transitions. Turned out my image[value] was too low. Works now ;)
@mikaelh9584
@mikaelh9584 4 года назад
Same here :)
@KrisS-nh8lr
@KrisS-nh8lr 3 года назад
@@mikaelh9584 @Martijn Facee Schaeffer same here sir....how to solve it? change image[value] to what?
@thengakola6217
@thengakola6217 3 года назад
engineer man is a hero actually.... lets call him e-man
@mfadhilal-fatih1427
@mfadhilal-fatih1427 4 года назад
Its pretty fun to watch even though i cant program, i just love how you searching a solution from a problem and implement it on programming languange. i have one same solution (the time/pixel one). I'm thinking "can i learn program(the easy one is okay) only using online IDE on website like hackerank?", Because my mom's laptop is too scary to try to download a thing because her laptop might be become slow and she can't do work on her laptop.
@Dylan-fr5rb
@Dylan-fr5rb 4 года назад
You can, or use a lightweight text editor like vscode or atom
@TheDesvendador
@TheDesvendador 4 года назад
i only did some automation with webdrive using NodeJs, it's possible to "control the screen" like these using NodeJS i have to use python? i see alot of automation stuff with pyhton, why? nice video btw!
@krazyinstinct
@krazyinstinct 4 года назад
Wouldn’t it be easier to search for the red box since the pillars seem to stay at the same y level all of the time?
@YoloMonstaaa
@YoloMonstaaa 4 года назад
Use a decompiler to decompile game files determine the real time => distance equation.
@NNNedlog
@NNNedlog 2 года назад
this is incredible
@pemessh
@pemessh 4 года назад
Time to add game automator to my resume.
@vazzury8896
@vazzury8896 4 года назад
Why not check for the first red pixel then compute the distance ? Amazing video as always EM
@spicytelescope5487
@spicytelescope5487 4 года назад
I think an answer might be that the background (of what we know, it can changes multiples times) may contain red pixels before the one you're trying to get the x-value of. So this algorithm doesn't work with any given background and therefor is not "automatic" !
@vazzury8896
@vazzury8896 4 года назад
@@spicytelescope5487 Yes I thought about that but it would be unlikely that one pixel of the row would have the exact same RGB value. But I agree that EM's way prevents it
@vazzury8896
@vazzury8896 4 года назад
@@spicytelescope5487 Plus we could check for the red pixel only once the first black pixel of the platform has been found, as EM said there is plenty ways to implement this
@sumanene8468
@sumanene8468 4 года назад
Yoooooooo this is sick
@janicknorman8778
@janicknorman8778 2 года назад
Damn this is mindblowing.
@jonny5495
@jonny5495 4 года назад
@2:15 what shortcut do you use to create IF statements? :p
@rookievideos8865
@rookievideos8865 3 года назад
Maybe this is a stupid question, because I don't know much about this, but would it be a viable approach to check for the right pixel above the ninja to turn black, instead of calculating the time? I can imagine getting screenshots the whole time would be bad for performance, but I wonder if it's possible to just check for one specific pixel. If so, could it be more accurate without losing too much performance?
@malanbandara
@malanbandara 2 года назад
Awesome 😎
@gotia0073
@gotia0073 3 года назад
Man this is soooooo... neat....
Далее
Understanding Fork Bombs in 5 Minutes or Less
5:55
Просмотров 166 тыс.
ТИПИЧНЫЙ РЕСТОРАН
12:09
Просмотров 428 тыс.
If __name__ == "__main__" for Python Developers
8:47
Просмотров 380 тыс.
Automate your job with Python
6:07
Просмотров 363 тыс.
Automating Android Games with Python and OpenCV: Pong
11:55
RAG from the Ground Up with Python and Ollama
15:32
Просмотров 23 тыс.
Beating a Pay to Win game with a bot
5:09
Просмотров 1,9 млн
How I Wrote a Script that Cracks Code Automatically
16:53
Омагад, планшет от POCO!
0:52
Просмотров 16 тыс.