what's going on everybody and welcome to
halite part 5 in this part what we're
going to be doing is building on the
last tutorial where we at least got a we
built the AI to or at least we built a
script to pull features and just play
the game randomly between choosing three
choices my nap lanit remind our own
planet attack or mine empty planets not
in that order so so what we need to do
now is we need to have a way to make
these these two players play against
each other and then we're gonna save the
winning players plays and they're
basically their features so their output
that's what we want to save so we've got
the code all done but now what we want
to do is actually create a script that
will just automatically run them the
other thing we want to do is I'm just
going to go over here the script that
we're going right now is data creator
I'm going to call my bot and I'm
actually just going to do my bot - 1 I'm
gonna copy paste and this will be my bot
- - I'm gonna edit that and I'm gonna
change version 2 to save exit done so
now to run these like if we wanted to
compete against ourselves real quick I
went in and just saved it but it would
be howlite dot exe and then my bot 1
first my bot - go ahead and run that
real quick and make sure dang I closed
it for whatever reason if you copy
something an idol and then you close
Idol the copy does not remain anyway ok
so these two AIS competed against each
other this this dummy only produced four
ships did 510 damage this one produced
36 ships did quite a bit more damage and
we can watch a replay of that real quick
Oh interesting I think they crashed into
themselves immediately both both a eyes
did that and then it looks like he's
probably gonna come destroy him real
quick pretty good okay so um so yeah
like watching this guy play even you're
like oh yeah no that wasn't bad so so
not a bad not a bad set of moves there
so anyway so let's go ahead and I guess
I'll leave this up because actually
right now I'm running Charles on on the
latest version of this this deep
learning AI so I'm gonna exit that out
and yeah so as you can see here - the
other thing to pay attention to is
basically we've got the input vectors
and the output vectors already saved so
we can just pull up one of them so
here's an example of an input vector
quite a bit of data to be showing there
but anyway there's your input vector
basically all this data and then that
map's to the output vectors which much
simpler all that data okay so this the
first thing we need to do is we need to
figure out how to make this call you
know that that to run so we're an import
OS and then OS system is what we can do
to make a system call and then we just
want to run that command which I
actually kind of say that saved it over
here just like all the other tutorials
if you just if you want the sample code
and exactly what I'm doing you can go to
the tutorial I'll put a link in the
description you don't have to type all
this out so we just call the system to
go ahead and run all this now the next
thing we want to do is we can't we need
to know who won the game if the problem
is from what I could tell there's really
no easy way to determine that at least
with Hal itxc
so what we're gonna do is actually we're
gonna take this which is missing the
closing weird how did that run the first
place we're missing the closing that
anyway we want to run that and out this
data - we're just gonna call this data
game
okay so we send the data out to that
file so that's just going to send
whatever runs here to just a quick file
basically it's going to append the
output to that file so we run that and
then we can parse that file so for
example we could just say with open and
then data came out and we're just going
to open that with the intention to read
as F we're gonna say contents equals F
dot read lines and then the way it works
is I mean first we could just run this
real quick just so you can see it but it
should have kind of the same order every
time just waiting for this game to be
over dated game out here we go so here's
an example of the game out file so it's
exactly what you see in your console but
as you can see here these are the lines
that we're after so basically so read
lines is gonna read by new lines so this
would be the last line so negative 1
negative 2 negative 3 negative 4 so
player 1 is going to be whatever
contents negative 4 is that's going to
be the information on player 1 or
they're calling it number 0 the second
player or player number 1 is going to be
negative 1 negative 2 negative 3 and
then from here we can parse what rank
did they get you could say how many
frames they got through how many shifts
did they produce and how much damage did
they deal we can grab all that data so
we can just parse it so that's what
we're gonna do so we're gonna say
Charles Charles bot 1 is equal to
contents contents negative 4 and then
Charles by 2 would be contents negative
3 and then we can just go ahead and
print both those out so just copy that
paste copy paste and then we'll run it
drag this over right so we can see okay
we've got those two things now so
times if somebody times out this won't
be the case and then we'll end up
hitting an error which is okay well
we'll make it but yeah the only time
these won't be in that order is if one
of the bots times out or hits an error
okay so now we want to do is be able to
parse data from these lines you can use
regular expression or we could just
split it I'm gonna do splits and I'm not
gonna make you guys sit through me
writing this out like I said before I
think it's just a waste of time so I'm
gonna paste get ships get damaged get
rank so we split by rank number go to
the right hand side split by space and
go to the left hand side boom got it
someone wants to write a regular
expression to do that have at it this is
just easier for my little brain to
understand
so anyway continuing along what we want
to do now is grab that data and then we
can output that data again I don't see
any value in making everybody write this
one out so I'm just going to copy and
paste this one as well and all this does
is grabs how many ships how much damage
how much rank for player 1 player 2 one
thing I'm going to point out here is you
might think about in this case this is a
1v1 you might think about doing training
both 1v1 and 1 V 1 V 1 V 1 because both
of those matter so so make sure make
sure you consider doing that if you only
train this AI to do 1v1 matches spoiler
alert it will become very aggressive and
it will eliminate your your 1v1
opponents in just a lightning fashion
but so basically it'll pretty much win
every game that the your opponent
doesn't flee but you're gonna lose
basically every four player match
because you're going to get too
aggressive initially not good enough
so you'll probably take out one of the
players so you won't get last you'll
probably get third you definitely won't
get first so anyway something to think
about
but we're just trying to make a simple
example here so once we have all this
information we're ready to figure out
who won and then save the data again I'm
just gonna copy and paste this code
because it doesn't make much sense to
have everybody write it out if it was
Charles bought one that has rank of one
so if that is who won the game then we
want to take that input vector and save
it or basically append it to Train dot
in and then we want to take the output
vector from player one and save that to
Train dot out we're just gonna keep
appending it to train that out if it was
player two that one we're gonna do the
same thing we're going to take player
two's input vectors save them to train
in output vectors same save them to
Train out now there's gonna be playing
times where like maybe some one times
out immediately or the game just went
too quick maybe one of the players
didn't actually do anything so we didn't
put up a fight or anything or whatever
there's no me lots of times where
something like that happens so what I'd
like to do is create a ship requirement
and a damage requirement again just like
a lot of these things you can feel free
to change these make them whatever you
want you don't have to do exactly what
I'm doing you can I'll show you the
results of exactly what I did it's
nothing stellar so the whole point of
this is that you guys can kind of tweak
it and see where it gets you so anyways
ship requirements we're gonna say we
want at least ten ships for the victor
and damage requirement will be at least
one thousand if we don't meet those
requirements we don't save the data so
so the way that I'm going to handle for
that is basically we'll come down here
actually I think I'm just going to copy
and paste the full code
because there's quite a few changes here
that need to be made actually so this is
with the full code now pretty much the
same thing here I just added this to
track percentage wins especially when we
get to the point what like once you've
trained your eight no idea what that was
once you've trained your AI you're
probably gonna want to now compete
either AI verse AI or AI verse random
script and save the winners and then
maybe AI verse a I save the winners and
keep doing that and iteratively improve
so I like to track who is winning at the
time because what we should expect is
after we've trained this we should
expect to see that the AI is better so
when we run this one when we run player
1 verse player 2 given enough matches
let's say we play about a thousand
matches or 5,000 matches we should see
that player 1 and player 2 are about
50/50 there should be no reason why one
is significantly better than the other
but the go p-- is after we train an AI
that the AI has a better percentage win
so the AI should be better than player 2
or whatever let's say player if a the AI
was player 1 it should do better than
5050
oh the other thing those I changed this
so this was from my code so right now
it's actually - 1 + - 2 and our code so
here it just computes the percentages
scrolling on down yeah yeah here before
we write to those files we just want to
make sure that we have more ships than
are required
we've done more damage than required
also we want to sleep for 2 seconds so
favori iteration I have no idea why we
need to do that but for whatever isn't
this for me if I didn't do those 2
second sleeps it would like copy the
data so like every time it would run it
would it would do like 5 of the game
outs it would save like 5 entire train
in train out it would just 5 times so I
don't know why it was doing that but if
I put in the sleep that didn't happen
anymore
so awesome that's what I went with okay
so I'm gonna go and say that and let's
test it make sure it runs make sure it's
doing exactly what we were hoping for so
I'm gonna pull up the command prompt
we're gonna do Python data - creator PI
let me just go ahead and run that see if
we hit any errors one thing to make sure
is make sure people are producing ships
and doing damage if you run this and
you're not seeing that happen
something's probably wrong but right now
it looks like they're running we're
seeing everything that we expect
currently it's 33 to 66 but we've only
run a few games now it's 5050 all right
and we're playing games unfortunately
there's no way to silence the creation
of these replay files you can just
manually delete them or what I did was I
just wrote a quick script that would
find all the log files and dot HLT files
and just delete them and I just called
it cleanup top I and I just double click
it let me just clear all the all the
files because you'd like to run this at
least a thousand times but probably like
I don't know five thousand times or
something like that to get a good amount
of training data so you'll you'll wind
up with a lot of replay files okay once
you've done I would suggest you do at
least a hundred games hopefully at least
a thousand and ideally I don't know a
few thousand but once you've got a good
amount of training data like I say at
least a hundred before you do the next
tutorial I think once you've got a good
amount of training data we can move on
and then basically this so this train
where are you here you are train file
there's any mods no that is not on the
screen so train it and you're killing me
let's do this okay train in train out
it's popping all around but anyway
stolen screen so train in train out as
you can see they're growing over time we
can just open them real quick so so far
for sample training data we've already
got 15,000 examples depending on how
quick your computer is
matches can go faster slow also if you
were to like I don't know multi-process
this or something like that with some
sort of lock on the train in train out
the last thing you want to happen is
these files get corrupted they need to
always be in perfect order right so
number fifteen thousand four hundred and
forty input vector needs to exactly
match fifteen thousand four hundred
forty output vector if that doesn't
happen you're gonna be in a world or
hurt so make sure that that is always
the case anyway run this for a while and
then whenever you've got a good amount
of trained it I'll see you in the next
tutorial where we actually build a
Karass model to train against the train
in and out train a model to hopefully
pick a decent output vector so I will
see you there questions comments leave
them below till next time