what's going on everybody in welcome to
part three of the highlight series in
this part what we're gonna be doing is
building some logic from the ground up
so in the previous videos we've just
really been working with the starter bot
we made some tweaks and even just with
those little tweaks right now our rank
is nine hundred and thirty-four which is
you know about fifteen hundred ranks
better than running with the starter bot
and really we just made a couple tweaks
so that's pretty good now what I want to
do is kind of change gears a little bit
and start thinking about play strategies
so generally like the game is not just a
things change as the game evolves and at
least at the most basic level I see this
as kind of two major tasks right when
the game first come first starts let's
say in the environment probably your
primary objective is to get two planets
as quickly as possible so you really
want to prioritize doing that rather
than say attacking the other player but
once you have the planets once you've
got planets that you're mining probably
your best bet is to go attack the other
player especially if you're capable of
getting to more planets more quickly
than your opponent this means you can
shut the game down immediately by going
and attacking your opponent so anyways
they're likely if if you want to get
really advanced and get really highly
ranked there's gonna be a few many more
states that you're gonna have but for
now let's just say initially we want to
mine the planets once we've done that
let's go ahead and attack the other
players so with that let's go ahead and
get started so what I'm going to do is
you know my bot v1 I'm gonna go ahead
and just copy paste and I'm gonna rename
this one to my bot - v2 and now I'm
going to edit my bot and what I'm gonna
do is I'm just gonna clear this out
because we're gonna write let's just
rewrite basically the entire thing we're
still going to use some some familiar
functions and stuff but we'll start out
fresh so what I'm gonna go ahead and do
is import h LT I'm going to import
logging from collections I'll import
ordered dict
we're ready to rumble so let's go ahead
and say game equals HLT game and this
time I'm gonna call it sent ibattz you
can call it whatever you want but I'm
gonna call that so now we can do a
logging dot info kinda like what they
had before and we'll just say starting
santa bucks and then some familiar code
while true the game begins
we every turn we want to know where the
game map is so game dots updates
underscore map and then just like before
we'll have a command Q that's going to
hold basically the operations that we
want to take so now we're ready to begin
iterating over our ships so we're gonna
say for ship in game underscore map get
me dot all ships and that's actually has
an underscore all underscore ships what
do we want to do well I think we might
need ship ID I can't remember if we're
gonna end up using it I'm just gonna
comment that or put that in there for
now if ship docking underscore status
does not equal ship dot docking status
dot all caps undocked we want to
continue so basically if if the ship is
docked we want to skip the ship now we
want to do is we need to figure out
what's the state of the game so the game
map tells us some information but we
actually kind of want to know the
information and according to each each
individual ship so the way that we're
going to do that is with a few loops
here so first of all we're going to use
entities by distance entities underscore
buy underscore distance and this is just
going to use a built in function from
that HLT directory that's gonna be game
underscore map dot nearby underscore
entities underscore buy underscore
distance and we do that by the ship next
what we kind of I mean we care about the
distances but generally we care about
the distances in order so right now this
is not in any serious order so I'm
actually going to say entities by
distance now is equal
to the ordered ordered dict of the
sorted entity whoops
actually I saw that copied so I'll just
paste entities by distance dot items
where the key is just going to be a
quick lambda function so we'll just do
lambda t : t zero so that'll start us
off as the the key is just going to be
that zero so it's it's gonna be the
distance so all this did was just order
our dictionary and maintain that order
for us okay now that we have that
ordered dictionary this dictionary
contains all entities including our
ship's enemy ships planets undocked
planets so planets in terms of being
both undocked and owned by us or other
people and so on so the first thing that
we're curious about is empty planets so
I'm gonna say closest underscore empty
underscore planets and this is gonna be
a big ol list comprehension but we'll
get through it so it's gonna be entities
by distance the zeroeth element for
distance in entities by distance if is
instance so if entities by distance
distance which is the key distance 0 if
that is also an HLT dot entity dot
planet so if let's roll over if it's
just gonna iterate over entities by
distance so for distance and entities by
distance the entity itself is going to
be oops I made a mistake there the
entity itself in question basically is
going to be entities by distance
distance and then the 0th element that
will be the specific entity so long as
entities by distance
as long as that entity itself is a
planet so long as that's the case but
also we want this to be an empty planet
so we need to say and not and basically
we're just going to highlight this this
dot is underscore owned so that's quite
the doozy
I do I will put links in the description
so if you missed any of that you can go
to the text-based version of this
tutorial and just copy and paste it
because that's that's kind of a long
list there now but again we're just
iterating over the entities by distance
we make sure it's a planet and that it's
unknown and if that's the case we're
just building a list in order of the
distance and we are kind of throwing
away the distance we're just we're all
we're doing is we're saving the planet
itself at this point so that's closest
empty planets now we want to get it'd be
a good idea to know our ships because
basically we want to know what are the
closest enemy ships and the way that I'm
gonna do that is just by getting the
like just like we did here with empty
plants only we're just gonna say if the
entity is a ship and not one of our
ships so to get our ships team
underscore ships equals game underscore
map get me dot all ships and in fact we
probably could define that up here
rather than doing it every time down
here mmm
I think I will actually want to do that
so let's say team ships because we don't
need to reiterate that every loop so
team ships equals this and since we're
doing that here let's go ahead and copy
and paste there so now it's we saved it
here but we also don't need to be
calculating that list for every single
ship that's a little inefficient so this
will run a little quicker I'm doing it
that way and then let's say closest
underscore enemy underscore ships equals
and again this one is gonna be very
similar to this one so I'm actually
going to copy paste so it's gonna be
anybody
since with the key of whatever that
distance is in the zeroth element which
will just be okay that entity for
distance in entities by distance if is
instance entities by distance distance
is rather than being a planet this time
we want to make sure it's a ship and
this also needs to be a capital P for
planet and then and not in this case we
want to make sure that the entity and
not entity and not entities by distance
[Music]
we gotta take that not there and that
not in team underscore ships we'll see
that was a lot of logic I I might wind
up having to copy and paste it myself
just to make sure I didn't screw it up
but I think I got it so once we have
that now we know the closest enemy ships
we have our ships and then we also have
the the closest empty planets or at
least planets in order closest is
probably not the right word I'm kind of
naming these based on what I'm after
but closest would actually be the zeroth
element right anyway the show must go on
so so we've got the enemy ships now what
we're ready to do is we're just going to
say if the length of closest empty
planets if that's greater than zero so
if there's at least one empty planet
let's say we want to run towards that
planet we're gonna say the target planet
make sure that's on the screen target
planet is going to be the closest empty
planets zero okay then what we're gonna
say is basically if we can dock that
planet let's dock it otherwise we
navigate to it so this is pretty this is
code that you should have already seen
before so if ship on dot can underscore
dock if we can dock at that target
planet great let's go ahead and command
Q Yui Yui there we go dot app and ship
dot dock at the target planet
so if we can dock let's dock at it
otherwise let's issue one of those
navigate commands so navigates
underscore command equals ship dot
navigates and we're gonna do this ship
dot closest underscore point underscore
to target underscore LAN it's just just
for the record if you want to blow up
planets like get rid of the planet
you actually just fly into the planet
you just suicide into the planet so if
you wanted to if another one of your
strategies was to blow up a planet you
wouldn't actually navigate to the
closest point to the target planet you
would actually navigate to the center of
that planet just just so you know just
case you you want to do that sort of
thing now you know how anyway and then
we pass game map we pass what speed do
we want to go at in this case we're just
gonna do HLT constants max underscore
speed and then finally ignore underscore
ships equals I'll set it to false you
can do whichever you want to do I
haven't really tested turning these on
or off I imagine maybe there'd be a
little less calculations we could run
faster but honestly this runs pretty
fast in my opinion so we just make that
navigate command if navigate underscore
command we're gonna command underscore
qu e u e dot up n navigates command okay
now so that's if there are empty planets
what if there aren't empty planets well
L if the length of closest enemy ships
if that is greater than zero what do we
want to do well we're going to say the
target underscore ship is going to be
equal to closest enemy ships the zeroeth
element and then again we're basically
going to navigate to that ship so the
way that this works the way to combat in
how it works is you just need to be
close enough to the
enemy ships and you will just
automatically engage in combat so that's
all you have to do so props to them by
the way for making that super simple
there's so many like things that you can
do and how I and yet basically all you
really do is navigate and you
I guess you dock but you're pretty much
always just gonna try to dock if you
could dock right so so I mean I guess
you wouldn't necessarily always do that
but for the most part the biggest thing
in this game is you just simply navigate
and you do stuff automatically which is
pretty cool
anyway target ship let me just paste
this in oh I guess because this was
under an else that's why it was tabbed
over anyway let's remove that that extra
tab and then rather than target planet
we're going towards a target ship
everything else remains the same cool so
at this point where we need to send a
send that final basically the commit run
the command Q so game
dönitz send command Q and then what is
our command cute well it is command Q oh
no oh my goodness wow we got it don't
worry everybody okay okay
and then just just to make our eyes feel
better this is when the turn ends and
then the game is ended here well okay
quite the doozy I probably made an error
listen I'm just gonna run this real
quick check for syntax errors no syntax
error okay but probably made a logical
error but we're gonna see so now we're
gonna do is run my bot versus that
settler bot so let me figure out where
we were yes I guess my bot v1 that was
our settle they're just basic settler if
I wrote yeah so we'll just run him
against that I think let's just check
this back real quick see what we're what
we're running if we run that it'll run
my bot vs. my bot v1 okay I'm content
with that let's let's also delete these
just so I know what is fresh and what is
it
Senta bhatt came in ranked one good
let's run it again also came in ranked
one one more time okay so he seems to be
doing pretty well for himself
so let me I'm gonna be really surprised
if we just wrote all that out and
there's no error and yeah let's run this
replay real quick Oh what just happened
please work thank you okay senti bot is
purple so so far he's looking pretty
good I'll know more once we take over
all the planets though that's
embarrassing yeah so he definitely
attacked good stuff let's run one of the
other replays let's just make sure it
seems like the game the games are ending
really quickly
mostly because poor little seller
doesn't know what to do with himself
he's also traveling really slow we
actually should run him versus v2 which
is faster let me do that real quick
before we submit it and embarrass
ourselves with a bad rank so I'm gonna
change that to my bot v2 this time and
let's run that there we go we got to it
at least a few more turns sent a bot
came and rank one let's run mmm one more
okay rank one again so he's doing very
well let's let's see though that second
to last one took a little longer let's
just see if we made any mistakes
oh we blow okay so it took longer
because we both blower ships up yet
another major mistake everybody seems to
be making I haven't yet figured out how
many ranks that'll save you if you don't
make that mistake but I'm gonna wager
it's probably a decent number I think
probably just at the beginning of the
game maybe just make your ships
temporarily fan out and that might solve
the problem anyway okay our bots looking
good I'm content let's upload this bad
boys so let me go ahead and highlight
HLT highlight my bots send to you can't
see it but I'm doing it oh did you just
do that to me I think it was this one
submission three okay so let's make the
submission now drag it in submit it and
I think what I'll do is I'll just kind
of pause this and I will restart it once
we start playing some games and I can
confirm that we're actually playing and
then we can kind of see how the rank
does but it takes a pretty good amount
of time for your rank to drop so
probably even initially it'll it'll jump
depending on how we how we do in those
initial games anyway I'm gonna pause it
for a little bit and I'll restart once
we've played some games all right I've
only really played a few games but we've
already dropped our rank oops
I'm not sure why I went to submit a bot
anyway we've dropped a rank pretty
signal okay really wants me to be on
this page there we go we've dropped a
rank pretty significantly as you can see
we've got quite a few wins here so we're
doing pretty good and then here's a one
of the recent games it's looking pretty
good we're definitely populating much
much faster yellow player really could
do himself a favor by going faster
really all these guys could have done
them souls favor I actually if anybody
wants to comment below I have not seen
really any player negatively impacted by
zooming around fast so because even on
the starter but the most basic logic
you're you're so much better if you're
just running around quick anyway yeah so
it looks like me and orange player
moving fast the other two were moving
slow one of the guys is already dead
another Charles yeah yeah this is a game
over nice okay maybe we've dropped
further rank we're gonna almost
certainly make it into the at least
seven hundreds look at all these wins we
did make some losses though let's check
out these losses I'm gonna wager we run
into ourselves
let's see formed what Karla or am i I'm
blue oh my whoa sorry I have to replay
that I wasn't even looking so let's see
so immediately
you know the game launches boom we've
run into two of us like two of our
players or ships are gone and then we go
to the same planet and attempt to dock
at the same time which is just Auto
death for every unfortunate person
involved
so we're knocked out escape oh my gosh
that's pretty funny that's comical
anyway yeah that's gonna that's a really
simple fix or at least that's a simple
problem I'm thinking you could just fan
out really quickly in the beginning and
that won't be an issue anymore anyway I
bet that's gonna save a lot of games
though man that looks really good all
those wins look at this we almost had a
full page of wins 8:01 we will be into
the 700 soon I can't remember is this
one that we are I can't remember which
one we already played let's see if we
blow ourselves up immediately nope this
is a different one oh no wait this is a
different one and we did blow ourselves
up I think we only ended we started with
one ship right yeah so we just start
with this guy and then he runs to this
planet and by now we've pretty much lost
the game but we're still zooming around
doing our best oh the last guy he lasted
a long time
but yeah we are out of the game at that
point again this game could have gone a
completely different direction if we
just didn't make that one tiny mistake
so yeah definitely worth worth fixing
that one now into the coming stuff I'm
probably pretty done covering rule-based
bots there's I'm still gonna keep
messing around it I think it's kind of a
fun challenge but I can't keep messing
around and sharing everything with
everybody otherwise what's the point
it's not a competition anymore if I
recall right the competition ends
January 20 let me look real quick see if
I get the official date No January 26th
so the competition goes all the way till
then maybe after that point all breaks
break some of the other rules down that
I'm playing with just to give you some
ideas though think about what other
people are doing as well so like so a
lot of people are likely to do
things like first of all run into
themselves fix that but also think about
the strategies other people have an
attempt to contra contrary one of those
strategies or take advantage so for
example what's one of the the flaws that
you could take advantage of in our by
well if we look at our code here whoops
that's not the one I wanted I want to do
my bot dumb pie basically one of the
things that our body is always gonna
adhere to is right here right it's
always gonna go towards an empty planet
so one of the strategies you could
plausibly take is leaving one of the
little planets as kind of bait right
just leave it there right some of the
other things you could take advantage of
too is like if if you're in like a1 v1
v1 v1 situation you could purposely not
attack the player that's clearly gonna
lose the game or that has no chance of
beating you like if all the plants are
occupied you might not want to waste
time in lose ships going after the small
guys kind of let the bigger other people
take care of those because most people
are just gonna randomly do it like like
what we've done we're just going to as a
closest enemy ship that might not
necessarily be the best idea and like I
said before it might also be a good idea
to leave a small little bait planet off
somewhere else let other people waste
their time going to that planet or even
kill ships that go to that planet just
don't mind that planet just protect the
planet so anyway yeah stuff like that
where you kind of want to start not
thinking in terms of how quickly can I
mine and how do I get my stuff and all
that think in terms of how do you how do
you counter other people's strategies
but anyways that's all for me for now
I'm also curious about trying to do some
deep learning or at least just some
machine learning I'm not really
confident deep learning is required on
this tasket it's probably going to be
solved almost just as accurately with
something like K nearest neighbors or
something like that but nonetheless I am
gonna be kind of poking around with that
if I come up with something basic enough
to share I'll be sure to share that one
with you as well
anyways one final rank check for a
sign-off
let's see yep okay so we definitely
breached into the 700s so pretty cool
and now we're actually starting to lose
some games so we're probably going to be
somewhere in the 700s anyways I hope you
all have enjoyed if you've got any tips
of tricks you want to share with us feel
free to leave them below otherwise I
will see you in another video and good
luck in the competition