AI learns to play 2048

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
what's up guys today's video is on 2048 where's the second Enigma machine video you promised us well honestly I couldn't be bothered doing it so if you guys want to see that then comment below but I wanted to do this more so I did it anyway now that's out of the way let's talk 2048 I'm sure you guys know what this is it's just where you move tiles around and get a high score and whatever so we need a goal and what's better goal than 2048 let's go let's shoot for the stars let's get that 2048 all right let's begin same as always first of all we need to create the game so to start off with let's get some squares on the screen when a new tile is created there is a 90% chance that it is a 2 and a 10% chance that it's a 4 all right boom yeah got some squares on the screen try not to subscribe too hard the button can only take so much abuse anyway we need to get some actual gameplay happening so I created a play out which contains all the tiles I call them tiles now when the game starts it has two tiles and random positions now let's add the movement in 2048 you can move in four directions every tile is moved in the direction until it either hits the wall or another tile if two blocks collide which have the same value they do a quick fusion dance and create a new tile with twice the value okay here we go this should be working now let's see what happens when we press the uparrow when they're gone let's try that again yep they're gone fantastic alright so we we need to fix that right here there we go now they stick around yeah it's it's still wrong but we're getting there okay so the problem is we need to get the correct order in which we move the tiles up we need to move the ones closest to the top first let me explain so we have two tiles like this if we move the bottom one first then it will move up one space and stop because it hits another tile I haven't implemented any of the fusing action yet so we just stopped then the tile at the top moves up until it hits the top so we need to move the top tile first so it works properly okay ready wait for it oh that's how it's done baby okay okay settle down now we need to add a new tile every time the player moves this is actually way more difficult than it should have been but I got it so yeah every time you move a new tiles added fantastic but this is still far from the 2048 game we know and love because we need to implement the fusion thing I've been talking about it's really wasn't all that difficult so here it is now the game is done but it still looks like trash all the movements are hard to follow and the blocks of the same color so needs to make it look a bit prettier before we can try to crack it so I made these changes I'm actually pretty happy with how it turned out who it is pretty sexy right so now it's the game John let's do the AI so the first generation is set up and a problem immediately became apparent in 2048 you can get pretty far by just pressing random keys it's means that the evolution is much harder because those which are terrible don't just die off since the difference between random movements and intelligent movements is very small so strategy of repetitively pressing the left button emerged if they couldn't go left then they went up and if they couldn't go up then they went down you get it it's not hard the strategy was actually rather successful reaching the 512 tile by the first generation but generation 3 a similar tactic emerged but went right instead of left this will somehow much more successful reaching the 1024 tile after this I was confident that we could reach the 2048 tile in no time but well I mean you'll see the next improvement wasn't until generation 29 who just that's a bit of a step and it only improves a little bit getting just over the 1024 tile again so I let it run for a bit and then a bit more and then some more anyway the next improvement wasn't until generation 247 so it was obviously an issue for neuro evolution to work it requires gradual increases over time think of it like the baby step approach this is not that this is more like bloody steroid babies steroid baby steps but anyway I tried writing in a few more times with different inputs and for much longer but they all had the same result so it's got me thinking that meat wasn't actually the best choice for this problem but you know me I'll never take no for an answer I'll keep working till I die when the going gets tough the tough give up and try something else yeah I gave up Sumi we're not all perfect but do not fret the goal is 2048 and I'll be damned if that doesn't happen so I tried a much more classical approach to AI now this neural evolution fancy stuff just some class six searching algorithms and although I know the word algorithm scares you guys because then would you hear it you think it's not AI but you know that's okay everyone has the right to an opinion but not every opinion is right okay now that that's out of the way so first I need to introduce you to the concept of game States game states are moments in time for the game like this or this well my algorithm will do is start from the current game state which is just what the game currently looks like and construct all possible game states which you can get to from this one taking into account all possible moves and the randomness of tiles appearing Thomas here took my man Thomas looks five moves into the future at all the possible game states then finds the best one and then takes the moves which are required to get there the interesting bit comes from how to tell which game states are the best to do this we create a function which calculates a single number representing the value of that game state kind of like the score for example game state which you'd I would have a value of zero and one which you've got the 1024 tile might be like a thousand you might be tempted to just use the score as the game value however there is a problem with this the value of each game State doesn't take into account the potential of that game state consider these two game States while they would have the same score the one on the right is far more valuable as it has the two highest tiles next to each other so the value function needs to take into account adjacent blocks of the same number one final thing that I added before we've run it it is strategic to keep the highest block in the corner with the next highest next to it that way when new tiles spawn they spawn far away from the larger ones it's basically separates the lower tiles from the higher tiles so we're giving you have a value boost to gain states which have the highest tile in the top left corner very nice ok let's see if he can do it yeah Tommy's a problem child I've no idea is doing he's gonna die yay died fantastic that's why you keep a top left Tommy yes 5 12 clora the way there your bad as good as repetitively pressing the left game so it's actually quite stressful oh yes yes oh my god we're close woof pressure zone Tommy keep it top left you're doing well Oh my god no no Tommy no you're embarrassing me all right Thomas this one will be the one you can do it yeah so it's almost kind of sucks but honestly I've had about enough of this project so we're gonna sit here wait until he bloody gets it oh you're so close Thomas you dumb mother so while we're waiting for Thomas to get his act together I'm now on Twitter yeah I don't really know what to do that but I'm there Tommy every bloody time [Music] [Music] [Music] one [Music] so many baby whoa he's done it I can go to bed beauty he just keeps yeah okay no he doesn't he dies did well Tommy did well so the theme for today was failure there were issues with my first approach to creating a solution and Thomas was certainly no stranger to failure Thomas but this isn't necessarily a bad thing as BrewDog puts it in the 8 principles of learning the best learners allow themselves to make many mistakes along their journey help 90% of what I do here is fail that's how most of my guys work they fail and they learn making them slightly less likely to fail brilliant a log is not all bark they actually practice what they preach giving you valuable feedback every time you don't get a question right so you actually learn from your mistakes not like here at University weather just like wrong you get a zero and then you're like but why shut up what do you think you're here to learn or something go home you bloody failure I'm sorry I've just finished my uni exam so still a bit salty anyway brilliant dog understands that failure is an important step in learning so head over to print dialogue slash code bullets check out more of their learning principles and get your hands on a bunch of their free courses the first 200 people to use this link will get 20% off an annual subscription so guys get failing and maybe one day you can reach the elusive 2048 you
Info
Channel: Code Bullet
Views: 8,939,324
Rating: 4.9169669 out of 5
Keywords: artificial, intelligence, game, AI, neural network, algorithm, machine learning, java, processing, NEAT, evolution, game state, search, coding, learning, rage, 2048, mobile game, depth first search, programming, computer science, comedy, computers, deep learning, genetic algorithm, genome
Id: 1g1HCYTX3Rg
Channel Id: undefined
Length: 11min 10sec (670 seconds)
Published: Fri Jul 06 2018
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.