Placeholder Image

字幕列表 影片播放

  • what's going on?

  • Everybody.

  • And welcome to part five of our artificial intelligences in Starcraft two with python tutorial.

  • Siri's in this video.

  • Hopefully we can secure our very first victory.

  • And, um, the way we're gonna do it is we're already started building our army, and now all we have to do is get some logic built to attack the enemy.

  • Basically, um, and our hope is that the enemy will be easy enough that we can do this with pretty simple logic.

  • So, uh, with that, really all we need Thio ad in like we're already building our army.

  • So the only thing that we need to add in is away itself dot attack.

  • So some sort of logic that we can employ to actually attack the enemy.

  • So I'm gonna come down here and I'm gonna do a sink, uh, passing himself.

  • And what are our rules going to be four actually attacking.

  • So we probably like you don't want to, like, attack with every new stalker that you create.

  • So instead, what we're gonna do is once we have a certain number of these stalker units, we're gonna send them in to battle, so we could go with anything.

  • Um, I think I'll start maybe with 10 or something like that.

  • So if self die units stalker, um mesh, veal calves, stalker, uh, dot amount is greater than it'll be five.

  • So if we have more than five stalkers, what we're gonna want to do is send them into battle.

  • So we're gonna say four s so stalker in self dot units stalker.

  • And we want to do stalkers that aren't currently doing something.

  • So we're gonna say idle.

  • So the ones that are idle, what we want them to do for s what we want them to do is await self dot Do so this is kind of like the overarching agent self dot Do and we want to make s attack.

  • Um, and we want to make them now.

  • You have to like, when you say attack, they have to choose, Like, what are we actually going to attack?

  • So we're just gonna attack, um, so you can do like, self dot known and in me units.

  • So we saw that before again, That's a method that exists inside of bought a I.

  • So that's like, appear, I think known enemy units.

  • So let's say we see an enemy unit, we know we can attack them.

  • So we're gonna just was gonna look for, um, for one of those, um, So if we have greater than five, let's just go ahead and attack an enemy unit.

  • Um, And the way the way that we're gonna do that is this is like, a list self dot known enemy units.

  • So we actually want to do something like a random dot choice of known enemy units.

  • Uh, didn't close off.

  • Okay, So before I forget, let me go ahead and, uh, import random up here.

  • Okay?

  • Now, that's all fine and dandy, but there might not actually be.

  • And I mean, like, any known, um, enemy units.

  • So the other thing that we could say is, um, see random choice in Well, let's go and run this, actually, and let's just, uh well, it's a real time false, and we'll just see if they'll actually go after any of the Attackers against us.

  • I forget how many had picked was a 10.

  • That's probably too many.

  • For if we're under attack.

  • That might take way too long to get us up to 10 so we might wanna.

  • We probably want to change that logic slightly.

  • So, um, there's a few things that we probably need to consider.

  • Hopefully lets you Maybe we'll get away with building enough.

  • I don't think we will.

  • Let me see here.

  • What do we choose?

  • Uh oh, no, we only chose five, so it'll only take five.

  • So we already have five.

  • So as soon as an enemy shows up, we should see these little guys run off and go yet.

  • There they go.

  • So we're already under attack here.

  • Okay, so they're already defending us, destroying the enemy.

  • 00 don't We went down.

  • Um What?

  • We can't choose from an empty sequence.

  • Durn Okay, So probably what we should do is like a So So what we should say is, um we probably need to check this.

  • So, like, if so, what we could say is if Len, um, self dot known underscore enemy units if that length is greater than zero, so if that's more than zero, let's go get him.

  • Okay, so that's a good, like defensive strategy.

  • Like, figure out.

  • Who do we want to attack locally, Right.

  • But then we might want it like we might actually want to do something Maur like.

  • Like if we have a large enough army, we'd like to probably seek out our enemies.

  • So, like, if self units stalker dot amount is greater than, let's say 15.

  • So if we have more than 15 of these stalkers, what we're going to say is, uh, well, just copy this line here.

  • So for each of this idol stalkers, what we should do is find something to attack.

  • So now we're gonna probably wind up.

  • We're gonna have to make a new function, I think.

  • But what will say is, um so for each of those stalkers, what we're gonna do is we're gonna await, uh, self dot do s attack.

  • And then again, we need to attack something and think time or it's a self dot find target.

  • And then we're gonna pass self dot state.

  • So this will just be like the game state.

  • Basically.

  • So then I'm gonna go above here and I'm gonna write this fine target function so deaf, find target.

  • And this is just a simple function and in this case will take an arm Sorry method, and we're gonna take in self and then the game state that we're passing in and what we're gonna look, what we're gonna do is like so first forward to say, if Len of self dot known enemy units if that's greater than zero, let's go ahead and just attack the known enemy units.

  • Um, so we're just gonna say return random dot choice, self dot um, known enemy units.

  • So if we know about some sort of enemy unit, we're gonna go for those first.

  • And then what we're gonna dio is, um LF, len, self dot known enemy and any structures So if we can't find any units to attack, we're gonna go for the structures themselves.

  • So if that's greater than zero, we're gonna return random dot choice self dot known enemy structures, and then finally, else we're gonna return self dot enemy on and me start location zero with.

  • So, in this case, when we have one enemy, so it's gonna be the zero with enemy.

  • But this is how we're gonna how we're gonna opt for, like, we just want to go on attack, right?

  • So once we have a large enough army, we're just gonna go after all the known enemy units um, And then we're gonna go after all the known enemy buildings.

  • And if we don't know about any of the enemy building so way haven't seen anything about our enemy yet, we're just gonna be like, Well, we know where the enemy started, so we know, seek them out at their start location.

  • And I guarantee we're gonna find something there, Right?

  • So So in this case, if this is the case, we go ahead and do this and then this should probably be, um l if down here.

  • So if we have a large enough army, we're gonna do army things.

  • We're gonna just seek out the enemy and destroy if we don't have an army.

  • But we have enough units, and I think I'll change this.

  • Actually, three, we have enough units to, like, somewhat defend ourselves.

  • Ah, well, go ahead and do that s o The next thing I want to do before we do this is we want to be ableto have enough gateway building.

  • So here's our offensive force buildings, and what we want to dio is we want to build, so we want to build that cybernetics core.

  • So if self um, let's see, pylon come on is like rewrite dysfunction.

  • But basically what we want to do is we're gonna build the cybernetics core if this exists.

  • If not this so prime.

  • What we should do is itself, like a way already exists.

  • I think what I'd like to do is maybe do because we want to grab the pylon and then we on Lee.

  • We really it's hard to decide if I want to build because you want to build the cybernetics core as soon as you have a gateway.

  • But then you also build cybernetics core, if not cybernetics core.

  • So maybe if a gateway exists and no, it cybernetics core, we want to go ahead and do this.

  • Okay?

  • So if we have a gateway already and we don't have a cybernetics core, build the cybernetics core.

  • Ah, l If if we can't afford a gateway and we're not already pending on a gateway, build a gateway.

  • So what?

  • I don't understand why we don't have, like, infinite gateways being built at this stage, But I'm just gonna say l if, um Len Self die units Gateway Ah, if that length is less than or equal to three, so if we have less than or rather, what we should say is just less than three.

  • So let's build three gateways.

  • So if the length of our however many gateways we have is less than three, if we can afford a gateway and we're not already building one, let's go ahead and build a gateway.

  • So hopefully we will have, um, three gateways to build all of our forces.

  • So let's go ahead.

  • Save that.

  • Um, let's run that.

  • Let's see what happens.

  • That's a lot of logic that we've kind of swapped around.

  • Please.

  • No, ever.

  • Okay, we're off for building the Kaiser's.

  • Here is a pylon.

  • Here's one of the gateways.

  • Now, at some point, we should build our cybernetics core.

  • And another gateway.

  • Hopefully.

  • Yep.

  • There's another gateway.

  • Lovely, lovely.

  • Okay, we're producing our stalker's Here comes in 1/3 gateway for us.

  • Awesome.

  • Pay attention.

  • The mini map here, and we'll see if we get attacked because we have to.

  • Now, I've already got three, um, things.

  • These are actually some decently built pylons.

  • These are too close to each other.

  • Okay, we're still building up our army as soon as we're under attack.

  • We're definitely gonna go after them, but probably pretty soon, we already have 9 12 Okay, they're off.

  • It looks like they just went attacked.

  • Somebody they just came over here.

  • And it may be over here, not just over here.

  • So pretty soon, these guys are all gonna run towards the enemy.

  • Hopefully, yeah.

  • It looks like they're off to the enemy location, so I didn't see any.

  • So here we are at the enemy.

  • I'm not sure if we're, like, frozen or what.

  • Or did we lose?

  • Yeah, I think we just got frozen or something.

  • So we're definitely at the enemy base.

  • Just kind of trying to take them out.

  • Now.

  • Looks like it's probably game over for the enemy at this stage.

  • They're doing their best, like repair their little building as we destroy it.

  • Um, they're actually building it quickly.

  • Okay.

  • The eh, I already wants to surrender, but, um, no, thank you.

  • It's just more enjoyable to destroy.

  • At some point, I believe everything just gets revealed.

  • If you destroy like especially like the remain like command center area.

  • I'm not really sure what it's called for the terror.

  • And I forget, I believe when that thing is destroyed, though eventually they'll get, like all their stuff is revealed, and then we can find them.

  • Very simply.

  • It looks like it's a game over, though.

  • Victory.

  • Nice.

  • So we actually defeated the easy bought, um, pretty easily.

  • Um Okay, So now what we could try to do is the medium by.

  • We'll just see how that goes.

  • And then while we're kind of waiting on that, um, I just want to point out already how many variables have entered into this that we wait Could significantly optimize.

  • So, for example, you know how much supply we have left before we build a pylon.

  • We could we could optimize that.

  • I'm just gonna kind of move this over as I'm talking.

  • Um, so we could already optimize that kind of stuff.

  • How close we want to do is sort of could eventually there's probably just a perfect number there.

  • How many?

  • How much expansion should we make?

  • That should be optimized quite significantly.

  • Um, I'm just waiting.

  • Eventually, we are gonna have a look.

  • It's gonna get We're gonna either get attacked, er, attack, But anyways, um, but this price should be like a fixed number.

  • It depends how far we are into the game.

  • How big is our army?

  • How many resource is do we have?

  • Like this?

  • Needs to be way more complicated.

  • Um, the offensive forces.

  • How many gateways do we build?

  • That's probably a good idea to go ahead and stretch that out.

  • It looks like a priority.

  • Had some combat.

  • These guys air, uh, over, um Anyway, um, and then other things, too.

  • Like how many?

  • What kind of rays show should we have, like workers?

  • Two Attackers.

  • And then probably eventually we're going to need to have, like, multiple different attack types.

  • You know, like we just have these little stalkers.

  • But the other kind of type is the avoid.

  • Raya's another good one that I wouldn't mind trying out at some point because that thing actually flies and has a really it does a lot of damage, but it's super weak.

  • But if you calculated like DPS over health, basically, So how much damage can this thing do?

  • Tow?

  • How quickly can it die?

  • It's a pretty good ratio.

  • Plus it flies, so that's always a benefit.

  • Why?

  • Pretty sure we're gonna defeat this medium boss or medium Media may I Oh, catch.

  • I accept victory.

  • Okay.

  • Uh, surely if we go toe like hard Julie, we're not going to defeat the hard one.

  • Right?

  • Look, I demand a slightly bigger challenge.

  • I wonder if maybe some people have posted or something like, ah, much harder a I that we could compete against.

  • Especially if we beat this hard won already.

  • That's gonna be kind of a bummer.

  • Expect greater challenge is doing it because there's definitely a lot more for us that we have to.

  • We have to actually consider here.

  • Um, and there's a lot more things I'd like to explore, So hopefully, hopefully I can't beat the hard won yet.

  • Also, it's probably gonna very slightly like, um how free, You know, like you might win the medium, you know, 80% of the time or something.

  • But you're still gonna lose sometimes.

  • Well, we'll see.

  • We'll see how we do it.

  • Looks like we're already under attack.

  • Maybe, huh?

  • I'm not sure.

  • I think that whatever it was got destroyed so fast also.

  • Is that not what's going on over there?

  • I can't really tell.

  • Hopefully surely will have enough.

  • See you faster, please.

  • Okay.

  • Their Army is definitely a little larger now.

  • We may not make it through this.

  • Uh, no.

  • Oh, my gosh.

  • I think we actually win.

  • Oh, man.

  • Selling a perfect anybody survive, I think everybody lost.

  • Uh, it's okay.

  • Were sanded and more reinforcements.

  • Man, I wanna be bummed out if we defeat this guy.

  • Yeah, The other interesting thing, First of all, like if we made Maur expansions, like probably at this stage of the game, you might as well expand over here.

  • Here we go.

  • Looks like they're going in for an attack.

  • One thing that probably have been smarter is if they clumped up together rather than going in, like little groups like this.

  • Okay, Yeah, probably.

  • They have us now.

  • Now, we're just sending in one at a time.

  • This pretty unfortunate.

  • He's not gonna last very long doing that.

  • Yes, probably were Not.

  • Well, yeah, they're army is just bigger than ours.

  • So at some point, you probably wanna build more gateways and produce more units and all that, like a resource we have times of resource is like we could definitely be making a much larger army at this point.

  • Okay.

  • Anyway, I don't think we're gonna win.

  • Eventually, they're gonna sic that army on us.

  • And, like, we're constantly like, using up our entire group of Attackers, and they're defeating us every time.

  • So eventually they will come and just destroy us.

  • Um, apparently, I was just gonna take a while.

  • Also, the other thing to keep in mind, too, is like as we keep creating these, like, we keep creating workers like we have no limit on how many workers we're gonna create, so eventually, we're not even have space for enough of these, like stalkers and stuff.

  • So Okay, so we're definitely not gonna be the hard won.

  • It might take a while.

  • I'm just not gonna waste your time.

  • Jeez, look at the size they were a little orange way we try to do is see the whole thing.

  • Oh, my goodness.

  • Okay.

  • Anyway, um, so more to continue.

  • Um, because we definitely aren't gonna be the hard one If you've got questions, comments, concerns, whatever feel free living below.

  • Yeah, it looks like they're actually attacking us.

  • We're probably gonna lose here.

  • I don't want to see it.

  • How do I forfeit a match?

  • It's not looking good, guys.

  • It is not looking good anyways.

  • Um come Questions, comments, concerns, suggestions, Whatever.

  • If if relieving below.

  • If you want to support the channel, you can subscribe.

  • Sponsor all that.

  • You can also get a python parliament that slash support for more options.

  • Otherwise I will see you guys in another video.

what's going on?

字幕與單字

單字即點即查 點擊單字可以查詢單字解釋

B1 中級

指揮你的AI軍隊--《星際爭霸II》中的Python AI教程第5頁。 (Commanding your AI Army - Python AI in StarCraft II tutorial p.5)

  • 0 0
    林宜悉 發佈於 2021 年 01 月 14 日
影片單字