what's going on everybody and welcome to
part 4 of our starcraft AI tutorial
series in this part what we're going to
be doing now is we've got all the
resources that we need to create some
sort of army and now we're going to go
ahead and do that so first of all like I
said before there are tons of units that
we could create and probably the best
case scenario would be to create dynamic
ones like some ground units some flight
units and different ones with different
abilities but for now we're going to
keep it as simple as possible and go
with a decent all-around unit and that's
gonna be the stalker
so the stalker is gonna require us to
first build a gateway which is kind of
like your barracks this is where you're
gonna produce all your units but then we
have to produce another building called
the cybernetics core to produce the
stalker or like unlock the stalker unit
so that's what we're gonna be working on
here so let me hide that panel and we're
gonna come up here and we're gonna just
add some more methods so await self dot
and I'm gonna call this offensive force
buildings and then other than just
building the buildings I feel like we
might as well await self dot build
offensive force so those are the two
things that we're gonna go ahead and add
into here and we will start with our
offensive force building so come down
here and async dev and we're gonna do
offensive force buildings will pass in
self and here we go
so first of all what we need to do is
like I was saying a while ago I think
it's the psionic core or a psionic
matrix I forget all the terms but
anyways there's that kind of matrix
field that goes around all of the pylons
and you have to build buildings inside
of that matrix so the first thing we
have to do is we've got to find a
suitable build location so we're gonna
say if self dot units pylon dot ready
dot exists so as long as we've got some
sort of pylon
let's just choose a random one so we're
just gonna say pylon equals self dot
units pylon dot ready dot random so
we're just gonna pick one of them and
then we're gonna say if self dot units
gateway dot ready dot exist so if we
have a gateway that is ready and it
already exists we then want to either
build a stalker or if we can't build a
stalker it means we don't have a
cybernetics core so we have to build the
cybernetics core now again we could have
multiple gateways but we really want to
probably limit ourselves and just have
one cybernetics core there's no reason
to build a bunch of cybernetics cores so
anyways self dot units gateway ready
exists now if not self dot units
cybernetics core and in fact we pry it
we need to bring both of these in so
let's do Gateway cybernetics core and
then eventually it's yeah it's kangri at
us so we need to do that like let's do I
think it's just backslash enter
do you not want the commoner oh it
should be never know how to properly do
this okay there we go okay so now we've
got gateway cybernetics core we'll come
on down here so if if we have one or if
we don't have one what we need to do is
build it so if we don't have a
cybernetics core then we need to say if
self dot can't if self dot can afford a
cybernetics core we only need one of
these so then we're gonna say and not
dude and not self dot already pending a
cybernetics core then what we want to do
is oh wait self dot build a cybernetics
core near said pylon so from very
beginning that just random pylon that
we're just gonna select okay so that's
that if now if a gateway doesn't exist
we need else if self dot can afford if
self dot can't afford a gateway so if we
can't afford a gateway and not self dot
already pending a gateway so if we can
afford a gateway and we're not already
pending on a gateway then what we want
to go ahead and do is a wait oops wait
self dot build gateway and again we want
to build a gateway near a pylon or the
pylon the rein and pylon that we found
okay so that's our offensive force
buildings now we actually want to build
the offensive force itself so async
async'
offensive build offensive force again
don't forget to pass so and now here
what we want to do is we need to make
sure that we're not like you don't want
to wind up building way too many units
and for now we're just gonna we're gonna
try to build some units but workers are
probably gonna get in the way we'll see
how it goes I'm at least initially will
have a few I just want to build them and
then in the next one we'll talk in the
next tutorial we'll talk more about how
to logically split these about I think
we'll get away with this but we'll see
so what we're just going to say is for
and in this case we're gonna try to
build we're gonna try to build these
stalkers from our gateways so what we're
gonna say is for Gateway Erla see will
call like GW for GW in self dot units
gateway and then this should be dot
ready note qu e so for each gateway in
our ready gateways if self dot can
afford a zealot or not a zealot um we
want to do stalker and let's come up
here
somebody's stalker zealot is the the
most basic unit I want to go with the
stalker instead stalker well we'll see
what happens it will probably hit an
error on that one too but we'll go ahead
and build the stalker anyway early so
I'll try if we can afford the stalker
and self dot supply left is greater than
zero what we're gonna do is a weight
self dot do and then we're gonna train
GW train a stalker
okay so this one we're gonna definitely
want to not be a real-time and let's go
ahead and run it and see
whoops see how that goes hopefully no
error we'll see though we've added a lot
of code something's probably around err
so we've got our pylons up what's this
coming and we got a gateway coming in
looks like we got their cybernetics core
is coming in and then hopefully at this
point yeah we're already warping in a
stalker
so that actually that logic worked out
for us we're definitely going to be
competing stalkers against our little
workers but that's good enough cool okay
so now we have our little offensive
force is incoming and what we need to do
next is probably build in a little more
reasonable types of strategy here let's
go ahead and highlight these and like we
want to first of all like when this
stuffs happening want to be able to send
them over here like I can right-click
them over and bring them in and just
annihilate those amateurs but we'd like
that to happen automatically the next
thing is we're at least right now I mean
where our supply is constantly way ahead
of you know how many of our like
fighters we have but we probably don't
need that to be happening eventually we
don't need to keep producing these
little workers there's not much point
because eventually two we're just gonna
run out of space and and really we want
more of our little fighter units also
it'd be probably advantageous to rather
than just having one gateway have many
gateways so anyways in the next tutorial
that's what we're gonna cover is how
we're gonna actually build our strategy
to create our units how many units do we
want and then possibly go ahead and
attack the enemy with some decent logic
and hopefully come up with our first
victory so that's what you guys have to
look forward to if you have questions
comments concerns whatever feel free to
leave them below otherwise I will see
you in the next tutorial