Automating Android Games with ADB: Bowling King (Perfect Games)

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
what's going on engineers it's time to automate some more games and this time it's going to be bowling King and not only we're gonna automate it to beat our opponent but we're gonna beat them with a perfect game we'll be using a DB which is Android debug bridge to accomplish this a DB lets us do tons of different things to our Android phone but the one that we're particularly interested in for this video is going to be the swipe action and so my other automating Android games videos we used ADB through Python but for this video we're just gonna use ADB directly because the solutions not that complicated for this one so let's jump in and start blowing some perfect games so let's start by look at the mechanics of the game unfortunately there's no practice mode so we have to just jump into a real match the rope against Randy he's probably gonna beat us because we're just experimenting here so as far as the mechanics go it's really just you can move the ball left and right and then you can swipe it up to throw the ball but then you can move your phone around to actually guide the ball so the moving the phone around that's problematic because how can I guarantee you can see that you can really throw it off so it's kind of sensitive and if that's going to do that how are we gonna make sure that that is in the exact location every time so because we need to make precision throws every time we can't be dealing with the actual tilt of the phone so rather than try to work around that or something I just disabled that sensor fortunately with Android 10 this is extremely easy just go into our menu and turn sensors off and then that's it we don't have to worry about the accelerometer doing anything anymore so our goal is to actually make a throw we want to just throw a straight shot now the ball can be thrown at an angle but rather than doing that we're gonna try to just throw it straight into the pins and see if we can get a strike every time so min student now is the coordinates I have to throw it so I know my screen is 1080 pixels wide so I know the middle is gonna be 540 as far as the distance to throw it I'm using my debug tool I'm gonna start kind of about right here which is about 5 1,800 and go up to maybe 1400 something like that so let's write our first command we're gonna use a DB shell input touch screen and then now I have to specify the X&Y starting point then the X&Y ending point so we said roughly five 40 which is of course the middle point and we'll start it at like 1700 and then we'll keep the 540 keep in mind this is just a straight shot but we'll go up to 1400 then the last value is how long it should take to do it we'll try just 500 to start so a half a second but first I need to add the swipe keyword now let's put the center terminal and see if we can get it to do anything there it goes actually through the ball but is it going to actually do anything so it did actually get a strike that actually worked really well I know that's a fluke ran out so it's gonna ride it again see if we get another strike so the ball goes and it wasn't a strike that time so I'm guessing even though we're swiping at the exact same point there is still slight variances although it's not being caused by the phone till because we've disabled that fortunately we do have a command here it does something useful it makes a 300 pixel swipe directly up the center of the phone and it does in fact throw the ball and it did actually get a strike every now and again so we'll save this for now you know a throw ball it's going to be that command so while this does balls strike it doesn't bullet consistently so we gotta come up with a new command that's actually going to ball a strike every time so we have really three options for this we can either make it curve which is not really possible we've disabled the sensors we could throw a diagonal shot but that might be subject to the same kind of variation that the straight on shot is the last option we could do is move the ball over a little bit and then take a straight shot into the pins I'm not a bowler but I seem to recall that that actually works in bowling so first I get the position of the ball so I'll start another game and find that out so if I put my finger on the ball I see that the position of the ball is roughly 540 by 1700 so as far as writing a command to move the ball it's going to be similar to this command except rather than moving it up which would be you know in lowering the 1700 to 1400 instead we'll move 540 over to say like 500 that should move it left 40 pixels and we'll keep the same 1700 I will do that over say 400 seconds okay so it's our turn again let's take our move ball command and run that and see if it moves the ball over a little bit so it did it moved it over 40 pixels just like it should now it will throw the ball straight up into the pins and there it goes let's see if it works it did that was a strike perfect so it's our turn again let's try our commands again so we'll move the ball and then we'll throw the ball I'll see if we get a strike that we did two in a row now so it's a turn again let's just try it a third time just to see if it's working consistently so we moved it over 40 pixels and that will send the ball down the lane and another strike perfect everything's working the last thing I do before we try to bowl a perfect game is just combine these two commands into one script so we have our file here but all we want to do is just add a slight delay between the move action and the throw action so about one second should be fine okay let's go destroy somebody with the perfect game all right we're in a game sorry Jose but I got to do it to you so our script called Bowl and it moved it over and then threw the ball so hopefully a bull's a strike alright it did great ok second frame run it again and got a strike ok third frame another strike fourth frame another strike and then fifth frame will try to bowl three in a row that's number one number two and number three and that's our perfect game house they put up a good fight but here's just no match and that's right all there is to it three lines is all it takes to bowl a perfect game now of course we could throw this on a loop and we could add a sleep at the end of the three lines and then we could just kind of let it go we wouldn't have to touch it at all I think for the purpose this video this is probably good enough now for those of you that don't have Android ten and can't readily disable your sensors I did do some testing with this with my sensors enabled and as long as I had it on a perfectly flat surface and I didn't touch it then this script it still worked just the same so if you want to test it out just put your phone really flat and you'll be fine and we're done I know the solution was not super complex but it did take a little work on some experimentation to arrive at a simple solution and certainly disabling sensors did make it a whole lot easier if you have any questions or comments about anything you saw in this video or if you can think of some improvements to what I've done please leave them below in the comments if you know of a good game that you'd like me to try and automate you should definitely also tell me below in the comments on what that game is and are in that hub the serial by the next video take care
Info
Channel: Engineer Man
Views: 51,577
Rating: undefined out of 5
Keywords: android, android adb, android automation, bowling king, engineer man
Id: yg8kBz7jIwE
Channel Id: undefined
Length: 7min 23sec (443 seconds)
Published: Sun May 17 2020
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.