Placeholder Image

字幕表 動画を再生する

  • What's up, everybody And welcome for 14 of our A I in Starcraft two with Python tutorial series.

  • In the previous video, we talked about all the changes that we're gonna be working on.

  • And in this video, we're gonna be working specifically on improving the scouting.

  • So the scouting that we have been doing was pretty stupid, and we're gonna make it a little better.

  • Not perfect, but a little better.

  • So with that, let's get into it.

  • This one's gonna take, um, a minute or two, So let's go.

  • So first of all, we're gonna do self in the innit method's self, not scouts and spots.

  • And that's gonna be a dictionary that tracks the I.

  • D.

  • So all the units have this, uh, attribute of a dot tag, and that is a sort of unique I d to that to that unit.

  • So we're gonna use that and say in store into scouts and spots that I d tag and the location of that unit so we can kind of keep track of where our scouts are, and then when they die or whatever we can generate through things and remove the scouts that no longer exists And then we can have new scouts fill their spots and stuff like that.

  • And then also, we want to scout again.

  • You know, you want to send the first scout to the enemy base, and then you want to send subsequent scouts to the expansions of that base.

  • So I'm just gonna go to expansion zones that are, by distance, you know, closest to the expansion closest to the enemy start location.

  • So we are going to be rewriting our scout method here.

  • I don't think we're going to be using anything here except for maybe this code.

  • But we'll put that a different method entirely.

  • So I'm gonna go ahead and just delete it all.

  • Okay, let's get started.

  • So, first of all, we wanna have an ex self dot Expand this dirt.

  • Ah, And then I'll just be an empty directory in the ER, but this would be quicker.

  • The setup of this will be the key is the distance to the enemy start in The value is the actual location object itself.

  • And now what we want to do is to begin iterating over expansion locations, which are a something that is located in our actual object.

  • So for e l expansion location in self dot expansion underscore locations.

  • What do we want to do?

  • Well, we want to calculate the distance.

  • Why is that already?

  • Okay, because it's interdiction was a closet already know that distance to enemy start is equal to e l dot distance.

  • Actually, it's distance underscored, too.

  • So this so e l recall is an expansion location object, right?

  • And it hasn't a method of distance to.

  • And now we can figure out what's the distance to whatever we pass here.

  • So we're gonna say self dot um enemy start location zero.

  • And yes, it starts self enemy start location zero.

  • So wherever that first enemy started, um, and we only have one, so we're going to use that guy.

  • So now we've got the distance.

  • Now we want to add that to our expand is dirt.

  • So self dot expand this Duerr And then the key is the distance to enemy start, and the value is help.

  • So now what we want to dio is once we've got all those in there, the keys are the actual distances.

  • So self dot ordered expansion distances is gonna be the sordid list of K for K in self expand, disturbed.

  • So all we're doing is just sorting the keys and then we can start iterating through.

  • That's the assorted keys.

  • Um, t figure out the next one to go with.

  • Now, as of python 37 you can trust, trust and rely on dictionary orders.

  • Um, unfortunately, can't use Python 37 yet with Python s e to do some web sockets things, so I can't rely on that yet.

  • So this is the kind of hacky way that we're gonna go about it.

  • I'm sure somebody can come up with a way better method for a scout here and feel free to share it.

  • Um, okay, so now that we have that sorted, the next thing we want to do is check all of our current, um, unit ideas.

  • So I'm gonna say existing I d.

  • S is equal to unit dot tag for unit in self doubt unit.

  • So we're gonna grab the tag of everything.

  • So the way that we're gonna learn, how are we gonna figure out who we need to remove from self doubt?

  • Scouts and spots is again scouts and spots is gonna be a dictionary of the unit unit tag unit egg in the location that that units at.

  • So all we need to do is generate over the tags and scouts and spots and then find out if any of the ideas or tags in scouts and spots don't exist and are self doubt units.

  • If they don't pull that on that unit, unfortunately, has moved to a better place.

  • So, uh, so those were the So now that we have the existing ideas, we're gonna say two clips to be removed for now is an empty list that's going to be populated.

  • So four noted scout in self dot scouts in spots.

  • So that's, you know, for the ones that we know about these noted Scout is the scout i d.

  • If noted scout um, not in existing I d.

  • S, then we need to to be removed dot Upend that noted scout.

  • Finally, um, four scout in to be removed.

  • We want Adele self dot scouts and spots that scout because now we want some other scout to be able to take that scouts position at wherever he was.

  • Where she was, man.

  • No, he or she man.

  • Anyways, uh, okay, so if Len of self die units, robotics facility dot Ready, uh, is equal zero.

  • So if we don't have any, then our unit type, I'm gonna say unit type equals probe.

  • Otherwise, um, under case that there you don't type equals probe, and we're going to say, Ah, unit limit equals one.

  • We don't want to send all over probes to scout.

  • So, like we have observers, we want all of the observers scouting.

  • When we have probes, we don't want all of them scouting.

  • We want just one jaws one.

  • So, yeah, so else unit type equals observer, and then I'm just gonna I really don't know what to think about this limit.

  • So I'm just gonna say 15.

  • I don't know.

  • Okay, so now we're gonna set a little flag here.

  • A sign scout is evil.

  • The true if unit type equals probe.

  • What we need to do is grab one of them to, um we only want one to be, um, the scouts.

  • So what I'm gonna say is four unit in self die units probe if unit dot tag in self dot scouts and spots.

  • Um, a sign scout is going to be false.

  • Now what we're gonna say is if a sign scout, we're gonna begin a unfortunate string of events.

  • So if len self dot units of the unit type whatever they happen to be dot idol is greater than zero.

  • So, again, this is only gonna apply for scouts.

  • I'm sorry, observers at scouts.

  • Well, or one probe anyways.

  • Four obs Since this year's gonna be observers self die units unit type dot idol up to whatever the unit you not limit is why I four arms in done.

  • Thanks, Editor.

  • You know, an idol I would have been, like running this and been like, Wait, what?

  • Okay, um four obs.

  • I'm sorry.

  • Not for ups if obs dot tag not in self dot scouts and spots.

  • Well, now we got something.

  • Now, what we want to dio is take that list of distances and then So it's that list of distances.

  • And when we were on it, what we want to do start iterating through them.

  • Those distances are an order of closest to furthest from the enemy.

  • Start location, and we want to iterated over those checking the expansion location.

  • That is that distance and seeing.

  • Do we have a scout there Yea or nay.

  • If Nay.

  • Well, let's put one there.

  • So the way that we're gonna do that is four dissed in self doubt.

  • Ordered exp distances.

  • We're going to engage in a try except exception as a print A string e.

  • Um, if you want to be decent, otherwise you could just pass.

  • Uh, and what we're gonna say is location is equal to next value for key value in self dot Expand, disturbed dot items.

  • And that's if key is equal to the distance.

  • So this is the way that we're going to find the value which recall expand his dirt.

  • The key is the distance.

  • The value is the actual expansion location.

  • So this is how I'm searching a dictionary for a value.

  • Um, pause.

  • Can I not hold on?

  • I'm about to be really angry at myself.

  • Uh, it's late today.

  • I'm gonna take a little bit of credit for being late.

  • But this would be how you would look up for a key by value.

  • But I'm looking for a value location.

  • Next value for key value.

  • Why would you ever do this?

  • I'm pretty sure I'm gonna be so angry if I go down this road, but, um, the location really should just be expand.

  • Dis dir Ah, and you're looking it up by the distance.

  • That should be acceptable.

  • That should give you the location.

  • Okay, the show must go on.

  • Active locations is equal to, um self dot scouts and spots K four k in self dot Self doubt, scouts and spots.

  • Man, this is still bothering me.

  • How did I make that mistake when I went through this the first time?

  • I mean, that code works, but as I started saying why I was doing it, I'm like, Oh, no, uh, okay, anyways.

  • Too much.

  • Okay, so if location not in active locations, uh, if units type equals probe, I can't get over this.

  • Ah, four units in self doubt.

  • Units probe lips.

  • If unit dot tag in self dot scouts in spots, continue then await self dot.

  • Do obs dot Moved to that location.

  • Then we're gonna update self doubt scouts in spots.

  • Obs dot tag equals that location, and then we are done with this little loop here, and we want to break who?

  • Okay, so something is is gravely wrong here.

  • Um and I don't want to talk about it.

  • So Okay, so now what we want to do is, uh, let me scroll down here, make sure I don't mess up anything more.

  • I'm still I'm still reeling over that code there.

  • There's got it.

  • I also feel like something's going wrong here, but not gonna try to live.

  • Fix that one at the moment.

  • Um, So finally, the last thing I want us to do in this method is going to be in line.

  • Here's a two tabs over.

  • So after we're done with signing Scout, what we want to do is four obs in self die units unit type if obs dot tag in self dot scouts in spots if obs in, uh, probe four, probe in self doubt units probe.

  • Um, await self dot Do.

  • And this really is the exact same code that we had before.

  • So actually, we do save that.

  • I'm gonna just pace that.

  • And so stuff to do ob stop moves.

  • Self doubt, random location variance.

  • Uh, and then it's that that random location variance function, which I think I kept and in this case, um, instead, I'm just going to say X And why is plus equals a random dot rand range of negative five to positive five and cool.

  • I think that's really all we need there and then finally build so we don't have the build scout.

  • So the last thing I want to add is a build scout method.

  • And so this is what we're gonna do to actually scout.

  • And at least for the time being, I'm gonna use this temporary function.

  • You can go the text based version of the tutorial.

  • Um, but this right now we're just gonna build a scout for every three minutes that has elapsed.

  • So if it's nine minutes into the game, we're gonna expect to have three scouts.

  • Um, So I'm gonna take build scout, and I'm gonna throw that right before the scout method away itself builds scout.

  • And I think we're done.

  • I still can't get over that code.

  • Oh, boy, Someone's gonna Someone's gonna have a fit.

  • Many people will have fits if you write perfect code on your first pass, let me know.

  • But if I don't think anybody's had that problem, so at least the way that I came across that was at first I had this.

  • That dictionary was kind of structured a little different we do hidden here.

  • Okay, We need to import math.

  • That's an easy bug.

  • I don't mind that bug import math.

  • Anyway, at first it was it was a differently structured dictionary.

  • So I was actually searching for a key by value.

  • And then later I flipped them.

  • And then I needed I just all I had to do was go down into, uh, that method and just change the words around cause and then I was looking for the value by the key.

  • And yeah, that's that's how I how that resulted.

  • That's pretty funny.

  • As I'm running through that, I'm like, Wait, but this is what a dictionary does.

  • I should edit this out and never share this with anybody and just not talk about it ever again.

  • But that's okay.

  • So we can see here.

  • This is our little worker, and he is heading into enemy territory doing his job quite quite well.

  • So I think he's hanging out.

  • I can't tell anymore.

  • I don't even know if he's there.

  • How would I tell?

  • I don't even know.

  • Is this our guy?

  • I think this is our guy right here.

  • He's just just be bopping around.

  • I wish they would kill him.

  • So it so we'd send another one, but I don't think they're gonna.

  • Anyway, I'm pretty sure that's our unit.

  • Yeah, okay.

  • They just killed them.

  • And we'll see if this guy looks like he's setting up another base.

  • And then how long are we were?

  • Three minutes in.

  • So here we go.

  • We're sending in yet another worker unit.

  • Great.

  • Everything's working as we would expect.

  • I still can't.

  • I just can't.

  • Oh, I think he was destroyed immediately.

  • And we're just We're gonna send another one in.

  • That's all right.

  • What I'm really waiting on is the observer Unit two.

  • Come in on.

  • I want to see how that how that goes, make sure the observers start coming in and going into where they need to be.

  • Why is the game time so slow?

  • We must have some some crappy logic going on here.

  • Game time is just not going very fast.

  • Maybe once we produce an observer that will be fixed.

  • It almost looks like it has been fixed, although there goes another.

  • That was so we've got our first observer coming out.

  • Things are going faster but interestingly enough, it happened before The Observer.

  • Anyway, I'm sure there's something wrong with that.

  • Could you clearly tell I was having a mental breakdown as that could was coming up.

  • So we got one scout up.

  • Ah, well, what price?

  • Okay, here comes the second Scout.

  • So we'll see where this guy, because he already has his orders.

  • And I don't think that other scout will be even seen.

  • I'm not even sure that they will be expanded to the location yet.

  • Maybe really angry if you OK, Good.

  • That's like because at base.

  • So, yes, So he's posted up at the first reasonable expansion, but they just simply haven't expanded.

  • But we would catch it if they did.

  • So you can even see we're right here at the mineral spot.

  • That would probably be the next place.

  • Although, actually, it looks like this is the next place.

  • And to be honest, like looking at the map, this looks closer.

  • So it's probably also unfortunate.

  • And I think if you look at the padding that you could take like this expansion is the safest next expansion to take this one because I think this one on Lee still has, like, one or two areas that you could get in.

  • This one has, like, three or four.

  • And then as you go out, it's like you just totally open to attack in a lot of spots.

  • But anyway, this guy's gonna cover that next spot.

  • No problem.

  • And the A I has already been defeated.

  • All right, so okay, we at least our scouting how we wanted to.

  • Wow.

  • We really did this.

  • Totally dominate.

  • We have 19.

  • His 16 void raise now.

  • 17 Voyager.

  • It's Wow.

  • That was, like, how many minutes was that?

  • That was not very long before we, uh Wow.

  • Uh, that was a good game.

  • Anyway, I think that's it.

  • Uh, Someone feel free to comment below.

  • I still feel like something is wrong.

  • Like a I'm throwing flags here.

  • Um, someone help me out.

  • I think this will be the last tutorial for the day.

  • Ah, but yeah, that's it's interesting.

  • And nobody speak of this ever again.

  • I'm gonna delete all comments.

  • That reference that I think.

  • Okay.

  • Anyways, that's all for now.

  • Questions, comments, suggestions for improvement, whatever.

  • Feel free to leave below.

What's up, everybody And welcome for 14 of our A I in Starcraft two with Python tutorial series.

字幕と単語

ワンタップで英和辞典検索 単語をクリックすると、意味が表示されます

B1 中級

スカウトを改善する - StarCraft II チュートリアルのPython AI p.14 (Improving Scouting - Python AI in StarCraft II tutorial p.14)

  • 0 0
    林宜悉 に公開 2021 年 01 月 14 日
動画の中の単語