Placeholder Image

字幕列表 影片播放

  • what is going on?

  • Everybody.

  • And welcome to a machine learning slash deep learning example with how light.

  • So before we get too far into that, I just want to cover real briefly, uh, least the overarching structure to really any machine learning at least classifier.

  • Obviously, there's different things.

  • There's like progressors, or you might have generative output or something like that.

  • But for your typical classifier, whether it's deep learning or machine learning, you're gonna have some sort of some sort of input.

  • Vector were array, I suppose.

  • But we'll call it a vector.

  • Uh, and that's just gonna have values.

  • So these they're gonna be your features.

  • So this could be anything in the case of how light these features might be, things like, How many planets do we have?

  • How many ships do we have?

  • How many enemies do we have?

  • How far away is enemy number one?

  • How far away is enemy number two?

  • So they need to be some sort of numerical value.

  • You couldn't pass an entity object in this input vector, and then you're gonna have some sort of output.

  • Now, in the case of deep learning, it's probably gonna be an array, and it's going to be some sort of one hot array.

  • In most cases.

  • If it was traditional machine learning, then your your outputs probably gonna need more like a one.

  • A two, a three a four.

  • Uh, something like that, depending on how many choices you have.

  • So let's say with deep learning organise deep learning here.

  • So we're gonna think of the output as this sort of one hot array, which means only one value is one the rest would be zeros.

  • So in my case, we might say, for each value in here that first value is attack, second value is mine.

  • And then the third value might be Explorer or something like that.

  • So in this case, where we've got 010 that would mean we want to mind.

  • So let's mind our own planet.

  • But if instead, the output vector was maybe a one, that would mean attack was hot, so we would choose to attack, for example, so just a really quick, um, overview of what we're gonna attempt.

  • Basically, in order to do machine learning or deep learning, we have to translate everything we have into this sort of structure, where you've got input features and then output choice.

  • So and then, in the case of deep learning, that output choice needs to be some sort of, like Vector, basically a one hot array.

  • So now let's talk about how we can go about doing this.

  • So we have a few options with how light so of the highlights starter, but which I can pull up real quick, which is totally worth checking out.

  • We're not going to be using that for a variety of reasons, but also, um, the way this works is off of replay files.

  • So those little files that you can upload to watch your replace those contained basically all the information from the game.

  • Um, it's basically it's like a log file.

  • You can think of it like a log file.

  • So what the the M L Starter bought does is it reads the log files and then just kind of determines where we should allocate our ships.

  • So this Aye aye, Onley makes that choice of where should the ships be allocated?

  • Um, and it doesn't really do anything else besides that.

  • So there's obviously going to need to be a lot of logic on top of that.

  • But that's totally fine.

  • So you can use a I for choosing your entire strategy and where to go.

  • Or you could use a eye for something really simple.

  • Like, how fast should your ship go?

  • And that's the only thing he used a eye for.

  • So you can use it for literally anything.

  • So what I'd like to do is use a I to choose whether we should attack minor own planet, reminding Empty Planet Just something simple enough.

  • And for now, I'm not gonna use the replay files.

  • But if you are interested using the replay files and you and you still want to check it out, check out the M l starter.

  • But But also, I'm just gonna copy and paste a snippet of code here just for anybody who is interested.

  • Um, based, this is code.

  • And also there put a link in the description because we're just gonna be doing a lot of snippets of code rather than writing everything out here.

  • Otherwise we'd be here for hours.

  • Um, this is a snippet of code to read a replay file again.

  • It's in the description.

  • There's a link to this tutorial in the description.

  • You can get this code, but for whatever reason, with the M L starter.

  • But I couldn't read replay files.

  • Maybe it's like a Windows thing.

  • Um, but the code didn't decompress the game data at all.

  • So I'm not really sure if maybe the stuff that's in the cloud is not compressed.

  • Don't know.

  • Anyway, If you want to read your local files, you definitely need to decompress Izzy STDs.

  • You have to install that as well.

  • I think I don't think that's a standard lied anyway.

  • That's example.

  • In those replay files, they're just basically just these giant Jason files, and they contain here.

  • You can operate through thegame frames.

  • You could get events, you could get information on planet ships, and then you can kind of pour through.

  • This is just some examples of me kind of parsing that data, but again, it's like a log file, so it's really challenged like it's not like you can just read the replay file, mimic it and directly mimic it.

  • You actually you still have to kind of parson, translate that log file.

  • So I think it adds kind of a layer of complexity that can make especially if you're not totally familiar with deep learning.

  • Um, I can make that a little more challenging, I think, to pick up.

  • But maybe I'm wrong.

  • But you can also, Like I said, besides this tutorial, you can go check out their, uh, their M l starter bought as well in, uh, maybe try both.

  • So now, uh, let's go and get started with script.

  • Um, Like I said, I think I'd rather just use the snippets here and explain its most this stuff.

  • We've already gone over, so I would just be wasting time if we're just gonna rewrite the script.

  • So what I'm gonna do?

  • Like I said, it's all have a link in the description for all the code.

  • And then I'm just gonna move it over here and basically just explain it as I go that way.

  • We're not that way.

  • You guys don't have to type it, and I don't have to type it X again.

  • Pretty much all this stuff is stuff we've coded before.

  • It's Hal.

  • I could So I was gonna paste this in.

  • So we're importing that Hallie directory logging to log order dick, because eventually we wanna have a dictionary That for sure retains its order.

  • Uh, numb pie for numb pi thing's random for choosing a random choice and os for making and deleting files.

  • Well, really, Just deleting files.

  • I don't have a few more Constance here.

  • Uh, this is gonna be how many features per entity that we want to track.

  • That's gonna make a little more sense once we get to that point of entities.

  • Percent changed chance.

  • Kind of like before where we had our ships, and we're kind of saving whatever plan we had for our ships.

  • Um, this is the chance that that plan might change.

  • So if a ship is currently attacking, it might get to the point where we're gonna change its plan and make a go mine or something like that.

  • And the finally desired ship count.

  • I'm setting us to 20.

  • Somewhere between 20 and 50 is a good number.

  • 50 seems to time out.

  • So once you get to many ships, your calculations were gonna take too long.

  • So you have two seconds to to generate through olive your ships.

  • So each turn, you have two seconds.

  • So, um, so one option you have is time.

  • How long you're taking.

  • And then once you've taken too long, you just break.

  • But then that means a lot of ships are probably just going to sit there and do nothing, which is not desirable.

  • So instead, what I've decided to do is if we have more ships than however many ships we desire to have, we send the remainder of ships off to their death on and make them attack.

  • So, uh, that's how we're going to kind of keep control of our ship count.

  • There's there's a few different ways that we could handle that best way I'm gonna handle it.

  • So then we're gonna have our typical you know, starting information.

  • So just the name of the game and start our logging information and stuff.

  • Uh, then, just like before ship plans.

  • And like I said, with that percent change chance, you got a 30% chance, basically every frame per ship to change the plans of a ship.

  • Uh, now what I'm gonna do is we're going Thio.

  • If the file exists, we're gonna delete it.

  • So basically, every game we're gonna save all of this player's moves to a file, depending on whatever version number is.

  • So basically, we're gonna have two scripts.

  • The exact same script.

  • It's just gonna be one's gonna be player.

  • One one's gonna be player two.

  • And then whichever player Winds, we're gonna take those winning moves and then we'll use them to train and at least to start these.

  • It's just gonna be totally random.

  • So the both bots will just be making random moves, and then we use those to train, and then you can actually just continue.

  • The iterative process can have to a eyes compete against each other, train based on the winners and continue.

  • As long as you have some degree of chance and randomness, you should find that you you continue to slowly improve.

  • So once we have that, we're ready.

  • Thio ahead and begin that that mean loop.

  • So let's do the wild troop game map.

  • You should already understand that Command Q.

  • Nothing new there.

  • So now, um, the big Three huge crux of this entire program is collecting those features.

  • So there are some features that we can collect without doing it per ship.

  • Um, so paste is in so we can find out all of our team ships we can find out all of the ships, and then we can find out all of the enemy ships.

  • We can do that without doing it on a per ship basis, because all we're trying to figure out is like, how many ships do we have here?

  • And then we can get So how many ships do I have?

  • How many ships does enemy have?

  • And then how many ships total are there?

  • The next things I'm just gonna grab here, we're gonna get our i d.

  • And then we're gonna put least prepare for empty planets, our planets and then enemy planets.

  • And then here, I'm gonna generate through all of the planets.

  • I'm gonna grab their size and then if it is owned, um, I'm sorry if it's not owned, that's an empty planet.

  • So we're gonna save that.

  • So this entire thes dictionaries are gonna be by size.

  • Uh, and so if it's empty, will throw it in there.

  • If, um, if if we are the owner, then we're going to save it to our planets.

  • And then if we're not the owner, but it is owned, then we'll store it to the enemy planets.

  • So then once we have that we can figure out how many planets each player has.

  • So there we have that.

  • And then finally, we can go by the actual sizes themselves.

  • Something's gonna paste that in.

  • And basically all this gives us is it's the K for Kay.

  • So it's Keefer key.

  • The key was the size of the planet.

  • So this just tells us how big are these planets?

  • And then because of sordid, is gonna go from smallest to largest.

  • We actually were going.

  • We might want largest, a smallest planets.

  • So I'm just reversing the list at the very end there.

  • And then once we have all this data, we're ready to actually start iterating through our ships because the rest of stuff are things that we need to calculate on like a ah per ship basis.

  • So, for example, we might want to know how close are the closest five enemies to each individual ship, or how close is the closest planet or so on.

  • So there's a lot of a lot of those kind of questions We actually have to ask that on a per ship basis, so I'll at least start this, um, so's reiterate through if the ship is basically of the ship is docked.

  • Let's skip it.

  • This is questionable whether or not you want to leave it or not, I would test it both ways.

  • I kind of think it's pretty inefficient.

  • Toe, like docking on docking, docking undock.

  • So I didn't leave it in there, but because we're only choosing between three choices.

  • Um, and one of those choices is mine.

  • Empty planet, uh, which is not likely to be an option much past the first, Let's say 100 frames.

  • Uh, it's probably only gonna learn one move, which would be attack.

  • Okay, so So it'll probably wind up with a very aggressive ai ai if you go with this.

  • Whereas if you remove this the day, I would be much more likely to learn other instances where hey, Yeah, we actually can dock, So yeah.

  • Uh, anyway, continuing along, we'll grab the ship, I d and then determine whether or not we want to make a change.

  • So here changes currently false.

  • But if we choose a random manager, that is less than or equal to, um, the percent change chance.

  • So basically, I think we chose 30.

  • So if it's less than 30 30% chance change equals true.

  • And then we'll use that down the line when we actually go to actually pick whatever move we want to make.

  • Okay, Now comes the massive, uh, list of features that we're going to grab.

  • Um, it's a tonic.

  • Oh, but these air pretty much all the same idea.

  • So we're gonna paste it, and then we'll go over it.

  • So entities by distance, this just grabs all the entities by distance.

  • We've done that before, and then we sort the entities by their distance.

  • So whatever is close of, like making this bigger, as if that's gonna help you anyway, um, and then we're gonna sort that by the key, so it'll be closest to furthest.

  • So now the closest enemy planets.

  • Um, this will just be anything that I'm sorry, this is close to empty.

  • This will be anything that is doesn't have an owner, but yet it's still gonna be sorted.

  • And then entities by distance, that distance in the zeroth element, this will be the values.

  • Here are the actual entity.

  • So you could navigate to each value in this list.

  • And then these are simply the distances So we want both Because on, you know, the feed our neural network or any machine learning classifier.

  • Um, we want to know we want scaler values, right?

  • So we want the actual distance.

  • How far is that thing?

  • Where is here?

  • If we say hey, Yeah, we actually want to go to the closest planet, number one or whatever.

  • We also want to be able to know.

  • Okay, What is that?

  • Because we've got the distances, but we also need to know the entity.

  • So then we're just doing the exact same thing for our own planets and then the enemy planets.

  • And then, honestly, we did it.

  • It's the same thing for the team.

  • Ships were grabbing the actual entities, and then we're also grabbing the distances, same order and all That s o then finally, um, yeah, so that's all done.

  • And then we come down here and this is probably this will be the sole slightly different because basically, what we're doing is we're one of our factors that we're gonna pass is gonna be thesis Eyes is right.

  • We've got sizes and distances.

  • Um, if there's gonna be times when like, for example, when the game first starts, We don't have any planets, and our enemy has no planets.

  • Right?

  • So if we don't have those values, we're just gonna populate negative 99.

  • So the distance will be negative.

  • 99.

  • We also are end up doing the same thing for, like, closest empty planets.

  • All these things, like with the distances we do this fix data function, which, actually, I haven't put that up yet, but I'll show it in a second.

  • Um, which again is just gonna do?

  • The same thing is gonna make sure we have is many values is we're expecting because I guess I didn't mention it before.