what's going on everybody and welcome to
part 7 of the highlight 2 tutorial
series as well as part 4 of the deep
learning in halite series so in the
tutorial leading up to this point we
built a bot to randomly play against
itself basically taking random choices
and then we took the winner and save
that to training data so we trained an
AI to basically play like the random
winners and now what we're ready to do
is take our AI the actual bot the hell I
bought and have it play as whatever the
the deep learning classifier says
basically based on the input input so
Soner to do that let's go ahead and I'm
going to copy I guess we'll just copy my
bot we'll just copy this one copy paste
and then I'm gonna leave this one called
just straight my bot mostly because will
I'll be submitting it in this tutorial
so I just want it it has to be called my
bot so so now we're gonna do is we're
going to open this and right away what
I'm gonna I'm gonna do here is do this
so we can actually so one of the things
that we will do is will compete locally
and just make sure it works and then
we'll go so and upload it okay so you
just fit this to the screen real quick
cool okay
so there's only a few changes that we
need to make and really the crux of this
entire AI is going to exist here this
pick a new plan so if the ship doesn't
have a plan or we want to change our
plans
the AI is gonna take over this sector
and that's it so it's super simple we do
need to make a few imports in such and
such but it's pretty simple so let's go
ahead and import Karos we're gonna
import tensorflow
as
F and then from cara's models import
load model and then what we want to go
ahead and do is do two so tensorflow and
care us both output some stuff here you
know do some standard output and how
light uses that output to communicate
and so what we need to do and clearly
the three huge thing like line number or
output number or something so what we
have to do is actually silence silence
the outputs of tensorflow
so I'm just gotta be these over as
always links in the description for this
code but basically that's gonna do is
gonna set that log level to 99 so
hopefully doesn't log anything and then
also we're gonna set that verbosity to
only report errors so hopefully I won't
tell us anything about what it's doing
so yeah cool now what we want to do is
load a model
so we're saying model equals load
underscore model and we're basically
going to load exactly what we had before
but at least for now I'm just gonna copy
this whoops put this back up here boom
we're gonna load that model that's the
one that we just trained then also I
guess I was just I'm just gonna you
don't have to have this bit of code but
I'll explain it anyway if and in fact
actually this should probably be done
basically here I would just do it
immediately or maybe after this set log
level not really sure which one should
come first
I'm trying to decide this is only gonna
be used locally though so it probably
doesn't matter either way I'm gonna put
it here though I think that makes most
sense anyway what this is gonna do the
main issue here is we want to set the
memory fraction so if you want to run
locally anyone have like two AI is
competing against each other this will
say each AI can use a 40% of your GPU
this is what I use just so I could train
to a eyes competing against each other
and not and then also still use my
computer so basically it was only using
80% but normally if you didn't have this
code here the first AI is going to
basically load its model and it's going
to attempt to use 100% of your GPU it's
going to attempt to use all that it can
which is a problematic when you attempt
to load a second model onto that GPU
okay so now we're going to go down to
that pic and new plans so I'm just a
search pick a really new plan oh okay oh
why is planning quotes okay whatever
now yeah so I'm just gonna copy and
paste from the text-based version so
what this is gonna do is it's gonna
round that input vector basically each
item because it goes out to like this
super high precision that's not
necessary and then the output vector is
model dot predicts output max is just
where that arc max is because model that
predict is gonna not produce well we
could round it but anyway it's gonna
produce something more like this like
I'm trying to make sure I sort of
correct and then I don't know okay
something like this is gonna be the
output vector it's not going to be a
beautiful 0 1 0 or something like that
that's not gonna happen
so then we'll get the Arg max we'll say
okay the arc max vector then we set the
our max to equal to 1 the output vector
is our max vector we log the information
and we save it okay but basically the
model is picking the output vector
and that's it
that should be all so let's go ahead and
run it real quick and see what we
screwed up save we move this over open
this up please just work please Dane get
and now we get to go through the lovely
lovely just super enjoyable debugging
process of halite see we got set session
not defined so clearly we need to import
mmm something more from tender flew I
really just wanted to show you guys that
as an example of what you needed to do
to run it locally but clearly it's
something we need I forget what it is I
don't know if I can just from tensorflow
import set session let's see TF set
session let's see if I can get away with
that if not we'll see from tensor flow
and poor said session no no that's
probably bad idea I don't want to load
up on an idle let me just run that
really quickly and see if that saves us
if that doesn't and did not let me pause
it so I want to get the right right
information for you so to give me one
second okay so actually it's from chaos
to do it for Karis I guess but anyway
from chaos stop backend tensorflow
underscore back-end import set session
and let me see if that works and then
because it's important to run it locally
eventually if you want to continue that
iterative process
I'll tell me I had another error hold on
I'm gonna get rid of that just because
it might be the order but
some still another error this is
frustrating uh Charles one right okay
list index out of range what would be do
we delete something that we shouldn't
have deleted from the model possibly so
I guess I'll go ahead and leave that
there cuz that's probably not our
problem oh this one's having a list
index out of range to who would be
hitting mm-hmm it's really irritating
because I ran both of these guys versus
each other not too long ago so I know
that the my bot one works all right that
works or should work yep so how you
gonna tell me that doesn't work and how
come they both had a list index out of
range doesn't make any sense and I
appreciate this trying to film a
tutorial here
wait
it's still from tensorflow import set
session that's what I just rant just now
why is that still that's not the error
surely cuz we're not doing that anymore
did I leave that import I sure did
[Music]
okay okay oh it works out Laurie that's
glory alright
so Charles the ai1 no more errors let's
bring this down let's go ahead and
submit that and see how it looks is this
it yeah so replay the file not what I
intended to do go back
here we go so Charles one is our AI he
is pretty brutal
see ya alright not bad not bad looks
like a pretty good AI to me okay
so let's say we're happy with that we're
like okay yeah good let's push that so
what I'm going to do now is looks good
so what changes would we need to make
from here so first of all we've already
done the Karis backend part so that's
not a problem
the other change we want to make is we
need a language file leave pause for one
more second to make sure I get this
right okay so just wanted to make sure
but so so what we have here is basically
because my bot PI is a dot PI but the
language is meant to be actually ml
because we're using a machine learning
script instead so to package this up we
also will want to have a I'm just going
to delete this just clean this up so we
can see things better we want to have a
file called language so I'm gonna call
this all caps language and then let's
open it up to sublime and we're going to
just call the language ml yeah like that
better fun so close that and then to
package this all up we need the language
the bot the model that we're importing
and then the highlight stuff because
we're using that as well and then we can
send that to a compressed folder I'm
gonna call that submission and now to
submit it there's a couple things we
want to do one thing we want to do is
probably go to or actually I think we
would want to go to edit profile or
maybe settings yeah so in settings
you'll want to enable GPUs for your
current but that way you don't timeout
so go ahead and just hit that drop-down
and choose yes if you don't have that
already and then you can go to save I
already had that there so I'm not going
to save it again now what you can do is
go to submit a bot
and we're gonna submit that new
submission there so that's version 24
just remember that so if we start if we
start having games and no errors and it
says version 24 it worked
okay so says it'll start playing games
within 15 minutes it should be pretty
quickly let's just refresh see if it
comes up pretty quickly or not know what
I'm gonna do I think is I'll pause it
until I start playing games or erroring
out we'll see which one happens all
right and we are playing games the turns
are greater than one so it looks like
we're doing all right we have one game
that we lost and then one game that we
won let's go ahead and check those out
real quick that guy just takes his sweet
time probably cost us the game there we
should fire him
this guy's a savage all right and then
this one we actually win and we didn't
move very quickly we sat there for a
little bit
interesting I'm not sure if this guy's
just mining planets or what cool okay so
he's playing we'll see where he kind of
settles I've kind of been poking around
you're seeing how we do and at least
obviously this one we just didn't have
very many games under our belt there
there's a lot of parameters that you can
change but actually one one of the AIS
that I trained only played 40 games and
cuts up down in 929 now obviously that's
just a by chance probably but anyway
this one will probably I'm not really
sure where I expect this one to settle
hopefully hopefully somewhere in that
one thousands but it just depends
because we didn't really train that many
matches so for example just to show you
as well so you could compete now locally
against yourself with the data creator
and then using either the percentage
share or maybe do the AI versus the the
default like random bot I wanted to show
you a picture I'm not sure it's gonna
happen I can't seem to get this the
picture to like zoom in when i zoom in
on this page it's annoying anyway
I just wanted to show a couple examples
so basically after I trained you know
with random models after a little over
5,000 steps obviously the you know the
the split was about 50/50 and then after
I trained the player to play you know
versus itself basically or basically
this is AI versus the random bot I guess
the AI 166 percent of the time after a
hundred matches so it definitely had
some improvement now the other thing to
pay attention to is like this this model
right now was trained on 1v1 matches so
I actually kind of forgot about that so
that's probably why work multiply stay
pretty badly ranked because it's really
only good against 1v1 so probably if we
go here let's see what he does but I'm
guessing he's just too aggressive like
he probably forfeits his position wait
to well he just killed himself
that was his main mistake but as you can
see he's going in for the attack like
immediately but really we should be
mining some planets but that's kind of
what happens when you're playing or when
you start off or if you only trained on
1v1 it's probably going to create a
pretty aggressive AI and these guys are
not even good come on
anyway that's all for now like I said
there's so many things that we can
modify and change and work on and all
that another probably the biggest one is
just to also include some four player
matches if not always have four player
matches or something like that but
anyways just there's so many things that
we could tweak and change and like I
said one of the other things I would
probably do is add a flee option so
maybe just do attack mine and flee
rather than differentiated between
mining our own planets and mining an
empty planet just mine a planet
somewhere and like probably mined the
closest maybe like one of the features
should be like the closest mine a bull
planet and it doesn't matter if it's
empty or owned just needs to have a slot
stuff like that those are probably some
changes that I think would would help
quite a bit
the other thing too is don't forget
about the ml starter bot and doing
replay files you can check those out too
like I said I think they're a little
more challenging too because you kind of
like it's not like you can just generate
features immediately you can't have two
parsing translate into features a lot of
times and then also translate into moves
and stuff like that kind of figure out
that logic but it's definitely something
worth looking into as well and they do
host like a bunch of like the golden
above games like the replay files so
there's a ton of data there that you
could learn from so anyways a lot of
stuff if you have questions comments
concerns suggestions whatever feel free
to leave them below otherwise I will see
you in another tutorial