Bot Plays Dino Run! Can our dinosaur bot be stopped?

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments

Thanks for all the support with my Fall Guys bot it means the world to me! One of the suggestions was to not use a neural network at all! I show in this video how to do that with a simpler game like Dino Run.

Discord

Code

👍︎︎ 2 👤︎︎ u/Dwigt-Snooot 📅︎︎ Oct 05 2020 🗫︎ replies

this is still an AI, it's just not using ML

👍︎︎ 1 👤︎︎ u/Comrade-Riley 📅︎︎ Oct 07 2020 🗫︎ replies
Captions
welcome and thank you everyone for the support on the last videos a thousand subscribers i never actually never thought i'd get that many i appreciate it and i hope you guys all are enjoying the videos my favorite comments from my last video were the ones challenging and questioning the way i did things so today i wanted to answer one of those questions of why even use ai when we could simply make rules and do the image processing so today i'm going to create an image processing bot that can play the dyno run game without using any ai at all [Music] answering the question why use ai we also have a special challenge at the end of this video for anyone who can beat my bot using just image processing and rules let's jump right in game i'm going to show you this concept on is a simple side scroller called dyno run now if you've ever had a crappy internet connection like me living out in the middle of nowhere you've probably seen it before if you're in a chrome browser and your internet connection fails or you don't have an internet connection it'll pop up this little game that allows you to play as a dinosaur jumping through what appears to be a desert so what we're going to do is we're going to use the same screen grab technique that we used in our ball guys bot except we're not going to put it through a neural network as someone suggested why use a neural network when you could simply just create rules so you can see here that we're going to have to detect cactuses to jump over so once the cactus gets a certain distance from our dinosaur we're gonna have to jump over that cactus you can also see here that there's some groups of four cactuses so we're gonna have to let it get close enough that when we jump we actually make it over the cactus as well as the game continues and i'll speed this up a little bit this is just me playing the game you can see that we're also going to have pterodactyls at some point and we're going to have to duck under those so again we're going to detect the pixel as it comes up to our screen and duck under that as it approaches now once you get even farther into the game you'll notice it does something pretty tricky that caused my original bot to go a little crazy and that is it's going to switch to a dark background where the objects are light so we're going to have to find a workaround for this as well so if you want to follow along with me go ahead and download the code from the github here we're going to open up create data and then get our environment set up however you want to set it up here i'm playing in a half screen and however you set this up is going to be half how you have to run your bot so i'm going to push print screen on my keyboard and i'm going to get the area where i want my bot to look and i'm going to update these values here to fit into that area so i'm just going to pop open paint paste in my print screen now obviously these values already match up for me but you can see in the bottom left corner there it will show you the pixel values so i wanted a range from 85 on the x-coordinate so that's about there to 715 which is right about here and then my y-coordinate i start at 350 somewhere in here and go all the way to 500. now obviously you could shrink these up there's nothing happening like below the ground so i think i just picked some round numbers here when i was setting up the bot but you're going to want to define a similar area here for your whatever your values are for those pixels now once we have that we can go ahead and run this program while we're playing the game and it's going to take some screen shots and put them into this image folder for us and we can also kind of start to see what our bot is seeing now it's going to see just that area that we defined and it's going to convert it instead of being grayscale you can see there's some different values it's just going to be pure black or pure white for every pixel so let's go ahead and run this you can see here it says saving pictures because it's saving the pictures as we go and you can see the view that we've defined now it's saving these pictures so we're going to be able to use these pictures to find the pixel values that we need to jump over things like the cactus and we just want to play far enough where we can also see the pterodactyls come in so we can define when we need to duck under a pterodactyl as well and there is a pterodactyl we need to duck under so now we should have everything we need we can press the e key that will kill this program and now we have plenty of pictures to define our values now the only thing we need to define is what to jump over what to duck under and we also want to define this end button here so we're going to pop open our next program which is the program that actually runs the bot it is called run episodes and an episode is just a single run of the game itself that's what i'm using for the run here so you can see here we gotta define some values inside of this program for our bot to run correctly and that's pretty easy so let's pop open an image in paint so the first thing we want to do is define our look ahead amount now here for each episode i'm picking a random look ahead amount from 80 to 120 to kind of figure out what's the best so 80 pixels ahead somewhere in here and 120 pixels ahead somewhere in here so it's picking a random value in between those two to decide how early it jumps now i also have a speed up amount so this is how many loops this program goes through before we increase that look ahead because as the game speeds up we're going to have to look farther and farther ahead so we can jump in time so you guys can set those values to whatever you think is appropriate the important part here we want to update our screen view to match what we chose and create data so take whatever you found and create data for your bot's vision and update those values we have to handle when the screen colors invert as it does sometimes like here so we're gonna check to see if we're on a white background or a black background and we're gonna invert the colors based on that for our rules so we don't have to have a rule for a white background and a rule for a black background so i picked a random spot now on the image the y coordinate is first don't get confused there and the x is second so y is 144 so i'm checking down here where nothing changes so you can see down in this area these pixels never change nothing changes there until the background is flipped so if our background flips then we're going to switch the values of 0 and white to handle the case where the colors are inverted so you'll want to pick a value for this somewhere in this bottom area below where the dirt specs are now let's go ahead and look at the duck first so we're going to duck under the pterodactyl and that's just going to happen if something shows up on pixel 54 and whatever our look ahead amount is so if we slide down on this image to pixel 54 we can see that that would be right in the middle of the pterodactyl so you want to update this value to be whatever whatever's right in the middle of the pterodactyl for you now let's open up an image with a cactus you can see here we test pixel 92 to see if there's anything in front of our dinosaur that we need to jump over so you'll need to update this value as well so if we slide down you can see on pixel 92 somewhere in here we can start to see a cactus so we need to jump so you're going to update that value there to whatever the cactus would be for you and finally you need to update the values for testing to see if it's the end of the episode so how i test for the end of the episode is i take a look at this replay button and if that's on the screen then i know we've reached the end of the episode so you can see here i do that by testing these values so the first one i test is 395 and 45 so i'm looking right in the triangle here of this replay button to see if it's white so if there's white here and then black on 370 35 like somewhere in the corner up here then i know that we have hit the replay button so i test the value somewhere in here somewhere here for zero and then finally somewhere in the other corner or somewhere up in this corner for another black value so that's how i'm testing so you're gonna have to update those pixels as well so you want one in the white and two in the black so you know that you've hit this replay button now once you have all those values updated you're ready to run the bot here's our best run and i'll show you some statistics along the way of how our bot did [Music] so [Music] [Music] now if you think you can improve this bot in any way please do if you create a bot using just rules no javascript packs or anything like that just image processing and beat me i'll give you a shout out in the next video and a special role in our discord for bot beater please like and subscribe if you haven't and until next time keep coding [Music] foreign
Info
Channel: ClarityCoders
Views: 38,745
Rating: undefined out of 5
Keywords: bot plays dino run, ai plays dino run, bot plays dinosaur game, ai plays dinosaur game, ai playing dinosaur game, bot playing dinosaur game, python plays dino run, python bot plays dino run, Bot plays dino game
Id: HubXt90MLfI
Channel Id: undefined
Length: 11min 30sec (690 seconds)
Published: Mon Oct 05 2020
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.