what's going on everybody and welcome to
part five of our artificial
intelligences in Starcraft 2 with Python
tutorial series in this video hopefully
we can secure our very first victory and
the way we're going to do it is we're
we're already started building our army
and now all we have to do is get some
logic built to attack the enemy
basically and our hope is that the enemy
will be easy enough that we can do this
with pretty simple logic
so with that really all we need to add
in like we're already building our army
so the only thing that we need to add in
is weight 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 sync passing
itself and what are our rules going to
be for 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 I think
I'll start maybe with 10 or something
like that so if self dot units stalker
that should be all caps stalker dot
amount is greater than it'll do 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 4s 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 a
weight self dot do so this is kind of
like the the overarching agent self dot
do and we want to make s attack
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 so
you can do like self dot known enemy
units so we saw that before again that's
a method that exists inside of bought AI
so that's like up here I think yeah
known enemy units so let's say we see an
enemy unit we know we can attack them so
we're gonna just a we're just gonna look
for for one of those so if we have
greater than 5 let's just go ahead and
attack an enemy unit and the way the way
that we're going to do that is this is
like a list self dot known enemy units
so we actually want to do something like
random dot choice of known enemy units
it didn't close off ok so before I
forget let me go ahead and import random
up here okay now that's all fine and
dandy but there might not actually be
and I mean like any known enemy units so
the other thing that we could say is see
you random choice in well let's go ahead
and run this actually and let's just
let's say real time false and we'll just
see if they'll actually go after any of
the attackers against us
I forgot how many I picked was it ten
that's probably too many for if we're
under attack
that might take way too long to get us
up to ten
so we might want to we probably want to
change that logic slightly so there's a
few things that we probably need to
consider hopefully let's see maybe we'll
get away with building enough I don't
think we will let me see here what do we
choose
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 yeah
there they go so we're already under
attack here okay so they're already
defending us destroying the enemy Oh
oh darn we went down hmm what do we do
it can't choose from an empty sequence
darn okay so probably what we should do
is like four as so so what we should say
is we probably don't even need to check
this so like if so what we could say is
if Len self dot known underscore enemy
units if that length is greater than
zero so if that's more than zero let's
go get home okay so that's a good like
defensive strategy like figuring out who
do we want to attack locally right but
then we might want to like we might
actually want to do something more like
like if we have a large enough army we'd
like to probably seek out our enemies so
like if self dot units stalker dot
amount is greater than let's say fifteen
so if we have more than 15 of these
stalkers what we're gonna say is we'll
just copy this line here so for each of
this idle 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 we'll
say is so for each of those stalkers
what we're gonna do is we're gonna oh
wait self dot do s dot attack and then
again we need to attack something and in
this this time we're going to say self
dot find target and then we're gonna
pass self dot state
so this will just be like the the game
state basically so then I'm gonna go
above here and I'm gonna write this fine
target function so def find target and
this is just a simple function and in
this case we'll take it
I'm sorry method and we're gonna take in
self and then the game state that we're
passing in and what we're going to look
what we're gonna do is like so first of
all we're gonna 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 so we're just gonna
say returned random dot choice self dot
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 do is L if 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 and I
mean start location the zero with so in
this case we only have one enemy so it's
going to be the zeroth enemy but this is
how we're gonna how we're gonna opt for
like we just want to go and attack right
so once we have a large enough army
we're just gonna go after all the known
enemy units
and then we're gonna go after all the
known enemy buildings and if we don't
know about any of the enemy buildings so
if we we haven't seen anything about our
enemy yet we're just gonna be like well
we know where the enemy started so we're
gonna go seek them out at their start
location and I guarantee we're gonna
find something there alright so so in
this case if this is the case we go
ahead and do this and then this should
probably be an 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 to three
if we have enough units to like somewhat
defend ourselves
we'll go ahead
and do that so the next thing I want to
do before we do this is we want to be
able to have enough gateway building so
here's our offensive force buildings and
what we want to do is we want to build
so we want to build that cybernetics
core so if self
let's see pile on I kind of wanna just
like rewrite this function but basically
what we want to do is we're gonna build
the cybernetics core if this exists if
not this so probably what we should do
is if smells like gateway already exists
I think what I'd like to do is maybe do
because we want to grab the pylon and
then we only we really it's hard to
decide if I want to build because you
want to build a 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 not cybernetics core we want
to go ahead and do this
okay so if we have a gateway already and
we don't have a cybernetic or build the
cybernetics core l if if we can't afford
a gateway and we're not already pending
on a gateway build a gateway so it what
I don't understand is why we don't have
like infinite gateways being built at
this stage but I'm just gonna say L if
Len self dot units gateway 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 three gateways
to build all of our forces so let's go
ahead save that and let's run that let's
see what happens that's a lot of logic
that we've kind of swapped around
please no error
okay we're off we're building the
geysers 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 stalkers here
comes in a third gateway for us awesome
pay attention to mini-map here and we'll
see if we get attacked because we have
to now I've already got three 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 going to go after them but
probably pretty soon we already have
nine twelve okay they're off it looks
like they just went and attacked
somebody they just came over here and it
may be over here nope 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
locations they 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 the stage they're doing
their best like repair their little
building as we destroy it they're
actually building it quickly
okay the AI already wants to surrender
but 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 their main like command
center area I'm not really sure what
it's called for the Terran I forget I
believe when that thing is destroyed
though eventually they'll get like all
their stuff is revealed and then where
we can find them very simply
it looks like it's a game over though
victory nice so we actually defeated the
the easy bot pretty easily okay so now
what we could try to do is the medium
bot we'll just see how that goes and
then while we're kind of waiting on that
I just kind of want to point out already
how many variables have entered into
this that we we could significantly
optimized 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 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 so I'm just waiting
eventually we are gonna have look it's
gonna get we're gonna either get
attacked or attack but anyways 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 resources do we
have like this needs to be way more
complicated the offensive forces
how many gateways do we build that's
probably a good idea to go ahead and
stretch that out looks like we've
priority had some combats these guys are
over anyway and then other things too
like how many what kind of ratio should
we have like workers two attackers and
then probably eventually we're gonna
need to have like multiple different
attack types so you know like we just
have these little stalkers but the other
kind of type is the the void ray is
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 to 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 going to defeat this medium
boss or medium medium ai
oh gosh I accept victory okay
surely if we go to like hard there's
really we're not gonna defeat the hard
one right look I demand a slightly
bigger challenge I wonder if maybe some
people have them posted or something
like a much harder AI that we could
compete against especially if we beat
this hard one already that's gonna be
kind of a bummer
I expect greater challenges dang it
because there's definitely a lot more
for us that we have to we have to
actually consider here and there's a lot
more things I'd like to explore so
hopefully hopefully I can't beat the
hard one yet also it's probably gonna
vary slightly like 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 but we'll see
we'll see how we do
looks like we're already under attack
maybe 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 we'll
have enough like see ya
faster please okay there are army is
definitely a little larger now we may
not make it through this oh no oh my
gosh I think we actually win oh man is
that like a perfect - anybody survived I
think everybody lost it's okay we're
Santa and more reinforcements man I want
to be bummed out if we defeat this guy
yeah the other interesting thing first
of all like if we made more 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 would've
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 is pretty
unfortunate he's not gonna last very
long doing that yeah so probably we're
not well yeah their army is just bigger
than ours so at some point you probably
want to build more gateways and produce
more in units and all that like our
resources we have tons of resources 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
apparently that's 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 beat the hard one
it might take a while I'm just not gonna
waste your time geez look at the size
there a little orange we try to do is
see the whole thing oh my goodness okay
anyway so more to continue because we
definitely aren't going to be the hard
one if you got questions comments
concerns whatever feel free to leave
below yeah it looks like they're
actually attacking us we are 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 more to come questions comments
concerns suggestions whatever feel free
to leave them below if you want to
support the channel you can subscribe
sponsor all that you can also go to
Python program internet slash support
for more options otherwise I will see
you guys in another video