what's going on everybody welcome to the
second part of our machine learning with
halite 3 tutorial in this video we're
gonna just be building on the last one
so in the last video we we basically
were checking to see if we could do this
like math of relative positions to get
the surrounding coordinates of any given
ship we definitely confirm that we could
including getting like the rolling over
of the edge of the map and so on so we
are confident that we we can do what we
want to do so now what we want to do is
work on what does the what is the
individual ship see so to speak and what
is the input layer to our neural network
in this case it was specifically a
convolutional neural network so coming
on down here to this like block of code
that we took from the testing grounds
that we built we just kind of need to
slightly modify this but not not too
much most of what is here actually gets
to remain we're gonna be adding quite a
bit though
so for size 3 is it's probably too small
we just did that for for testing
purposes I would go with 15 or maybe
even as 16 if we go with a 15 that would
give us a 31 by a 31 so it's always
gonna be this number times 2 plus 1 and
that will give you the the grid size I'm
gonna go with 16 purely because if we
want to use things like mobile net and
Inception and some of these other models
the the minimum size is 32 by 32 so we
could resize or we could pad or whatever
or we could just build data that has the
proper size right out of the freakin
gate and we'll be all set so that's what
I'm gonna do so next so size 16 that
gives us at the end of the day a 33 by
33 grid that every ship sees so on the
smallest map it'll see the entire map on
the largest map a 30 33 by 33 grid is
huge should the ship exceed those
boundaries for whatever reason it's
probably already lost anyways but okay
anyway cool so 16 by 16
for now surroundings is currently empty
and later we were gonna populate with
coordinates but we really don't need to
do that
that was just for quick testing purposes
now we want to do is populate it with
meaningful values so what I propose is
that surroundings contains its a list of
lists where each list is your pixel
value so to speak and we should have the
following I think my I've lost my that's
unfortunate my caps lock light on my
keyboard no longer works yeah that sucks
what a bummer I don't know if I can go
on in this tutorial that's really
depressing oh man my number lock all
those lights aren't working anymore
darn it okay show must go on I guess I'm
really dead inside now okay anyways so
so the first value will be halide amount
then ship and then drop off so probably
will be a shipyard but it could be it
could be just a simple drop-off location
I doubt we will make it that far
we will probably only have shipyards
rather than adding more drop-offs and
stuff I don't think we'll get big enough
to need drop-offs but hey that would be
really cool and it'd be great to be
prepared should we be so lucky ok so so
that's what we want Purcell so for each
pixel let's say in this image that we're
gonna draw the first value so it's we
will be able to depict this as if it's
RGB so we could show this in like OpenCV
or something just to test but anyway
that should be all the data we need the
only thing we're kind of missing here is
what turn number are we on so we have
really at this stage we're not inputting
to the neural network we're in the game
are we so if you're like really early in
the game you could travel pretty good
distance that's fine as long as you and
the other thing we don't know is like
how much how light do we currently
possess right now so in the early game
or like kind of early mid esteem it's
okay to try
long distances but towards the end of
the game if you travel out too far and
you don't have time to come back and
deposit at the end of the game that's no
good so so we have no concept of where
we are in the game or how much how light
we actually have so that's kind of
unfortunate that our model won't have
that data later on maybe we could also
pass turn number or even a ratio of like
turn number out of how many turns we
know there will be so you know exactly
how many turns there will be by the size
of the map so you could maybe rather
than a three channel content you could
have a four or five so we could have
turned number and halite and then maybe
you know make the max how light I don't
know 70,000 or 80,000 something like
that that is a pretty high threshold and
so it would still be between 0 and 1
which you want for scaling purposes
anyway for now we'll stick with a 3
channel but there's definitely room to
add more of things for tour okay
so to know certain things like ship and
drop off we want to know is it our ship
or is it an enemy ship is it our drop
off location or an enemy drop off
location I think these things matter
so before we iterate over ships we do
want to have we want to know where are
we want to know our ships and we want to
know we would like to know our drop-off
locations so at least our drop drop off
will call this drop-off hmm I'm trying
to decide what how I want to do this
drop off because like the drop off
ourselves
we really could just go mmm me get I
think it's me get drop off so like drop
offs equals me dot get drop offs but I
don't recall if me get drop offs
contains also me dot shipyard I don't I
don't remember and this I don't know if
this is a list so let's make sure that's
a list
in them plus me Dutch shipyard we'll
just do this so this should just be drop
off objects and shipyard objects list
yacht get drop-offs in fact let's do cat
drama so how about mmm I'm trying to
decide how I really want to do this
[Music]
and then for now let's just say ships
equals no we definitely need we want to
know with the position so let's do D dot
position for D in because we want to
know cuz we're gonna be only looking at
the cell so we definitely need to do it
this way drop off so let's call this
drop off positions and then we'll call
this ship positions and then yeah we'll
just do what we had done before I can't
remember if this was in our text-based
version or not if we had done up to this
point the ship positions and drop off
positions but this definitely we need so
now it'll be s dot position for s in
list me dot get underscore ships okay so
now we've got the drop off positions in
ship positions this way when we go to
check that cell on the Halla on the game
map if it has a ship and we don't have
those coordinates in our ship positions
we know that's an enemy ship if we do
hey that's our ship great cool same
thing we're drop off we can find out is
it our drop off or is this an enemy drop
off just by checking to see if we have
that position in those lists okay so
now so this is our row we are definitely
going to keep that as a row so now what
we're gonna do is 4x and then 4 or 4y
rather than 4x what we're gonna say I
just want to make some space so I can
see what the heck I'm doing here and
then we'll zoom in okay cool so first
we're gonna say current cell equals game
map and then we want the game map at
ship dot position so ship top position
that's ship as in the ship up here that
we're iterating through ship top
position plus a position object of x and
y so this is just that relative
coordinate relative to our current ship
so that's that cell that we're currently
interested in so current cell maybe of
interest would be a better a better name
then what we're gonna say if current
underscore cell daunt position in drop
off positions or let's see if current if
current position in because in theory we
could have I have to do it but cuz you
could have an enemy ship on your drop
off that's totally possible so and
actually I don't know the answer so if
two ships collide the halite sings but
if an enemy ship is on your drop off
location and you go to the drop off
location I don't know what happens to
your how light like will you deposit it
or does it sink to the bottom of the
ocean I don't know the answer to that
anyway someone comment below if you know
the answer what happens in that scenario
anyway if current in drop off positions
if correct let's say drop drop friend
foe equals so if that position is in our
drop-off we'll say that's a one else
drop friend foe equals negative one so
if we happen to find a drop off and it's
not it will check these numbers
hopefully this will make sense later
this is probably like the worst logic
ever
if current cell dot position in ship
what does it ship is that what we called
it ship positions ship positions ship
friend ship friend foe equals one else
ship friend foe equals negative one so
we can use this as a multiple so I
believe we can only find out if a cell
has a ship like it's a true or false
kind of thing so either it has a ship or
it doesn't have a ship so we're gonna
use that by we can because I don't think
we can find out if it's our ship or
their ship the only way we can know for
sure is if if it's in our list of ships
or not I can be totally wrong like I
said I this is just me running through
this problem I am sure there are many
ways that we can do things better than
I'm going to do them okay so so
basically what we're gonna say is we
need to get a few things so first of all
how I to know about that we're gonna say
how I equals current cell dot highlight
underscore amount and that gives us the
current amount which the maximum you
could ever have is a thousand so a given
cell can't have over a thousand I don't
believe at least naturally it can't
again if two ships crash into each other
there they
lose all their halite but it doesn't
sync it just stays afloat so I don't
know what if two ships have a thousand
halite is that make that two thousand
how light or does it max out at a
thousand I really don't know cuz the
constant max halite is is a thousand so
I don't know again comment below if you
know the answer to that one anyway for
now let's just assume it will always be
a thousand and once in a while it'll be
more but basically we want to make we
want everything and with neural networks
especially but most machine learning
algorithms we want everything to scale
between 0 & 1 or negative 1 and positive
1 so in this case halide amount being
anywhere from the zero to a thousand we
don't really want that instead we want
to divide it by constants dot max halite
and then i'll give us a decent number
but to stop for any gigantic long
decimals
we'll also round that to the nearest two
decimal points just so we don't get
anything too absurd and it was just this
way we can keep our data set size
relatively small because over time each
game could is going to be probably quite
large and we just there's no need to
have a super long decimal point there
we're really just looking for general
numbers so then ship status would be
current cell dot ship again this is a
true or false or actually I think maybe
it returns a ship object if there is and
then otherwise it's none I think that's
the way it goes
I'm not positive also yeah so we're in
erisa that would be a problem so we're
already saying for ship and me rocket
ships if we come down here and redefine
ship we're gonna get in a little bit of
trouble so actually let's say a ship so
a ship equals current cell chip then the
next thing was structures so current
cell dot structure again that's going to
be a nun or plausibly a actual structure
I don't recall it'll be none or a thing
though so if halite is none
if halite is none how I equals zero if a
ship is none then we're gonna say ship a
ship equals zero if structure is none
structure equals zero if how I is not I
always like to get this is usually where
I you do like a double equals but it
doesn't appear that I've done anything
wrong so cool so we got that now if a
ship in fact so in this case how light
is is if you have a ship is none else
else a ship equals ship friend foe times
and in this case it's a ship object so
we would say a ship dot how light amount
divided by max whoops no constants dot
max how light and again we're gonna want
to round that a ship front of row times
this so negative 1 times this or
positive 1 times that round and we're
gonna round that to again the nearest to
that should be fine
and then structure in this case if
structure is none structure is 0 else
structure equals what was its truck
structure what do we say here ship
Friend or Foe drop friend or foe
so whatever it will either be negative 1
or positive 1 it's only 1 we're like
multiplying here is if the ship if it's
our ship it's a positive 1 times however
much halide is on that ship divided by
the max highlight so let's say it's 50%
full it'll be you know 0.5 okay so once
we have that we have our three numbers
that we really want here so you can just
say you know our amounts are
halite a ship and structure and then we
do rowed out append amounts and then
should be one tab back right so we have
our one sat after this we have our full
row so then it would be surroundings dot
append row and then for ship in me dot
get ships so at some point we want to
write that in this case we'll only have
one ship so really we could just go one
tab over yet again with open I don't
know test dot text with the intention to
append as F F dot write the string
version of surroundings
oh no yeah that's a good thing I
scrolled down okay that's fine I think
everything else is fine let's save that
and in fact let's just do this so isn't
it is it game if game diet turn number
equals I don't know five will do this I
think we I think it's game turn number
hopefully that's right and then we just
come up here brick brick brick brick
brick surrounds surroundings
surroundings
okay hopefully that was it so just hit a
silly little error that said it wasn't
defined okay looks good let's see test
dot text let's open that bad boy up and
choosing another app my apologies for
doing this sublime text great how dare
ye also ship at the zero zero ship
should have a value so it's gonna take
too long to find it but hopefully that
gets populated at some point but also we
have a nun what was that structure nun
if structure is none o we tight bowed
okay structure we type over to ye so oh
my gosh structure well how do we do that
I did say I should probably just not
even bother with the tutorial okay save
that let me run that again let's see
what we get
make sure it updates test up toast
really no way it didn't update this
should update automatically
oh this is gonna be so frustrating to me
if really I really thought we had the
answer at least not locally for me it
will update in sublime automatically
yeah it still says none fool man what
else am I missing structure structure
structure structure append structure
dang it if
drop friend foe 1 or negative 1
man I hate when I have stuff like this
if structure is none it just looks so
clear to me if it's none then it's zero
but otherwise it's drop Friend or Foe
which is defined drop off positions cuz
drop Friend or Foe if maybe never
defined like if I do that but it would
say that's not defined if I went to run
this I don't think that would pass as
none it would ya not defined so it is
defined as drop friend or foe as being 1
or negative 1 isn't tinkering fun
everybody it is let's see 128 let's
check it got updated at 127 which is pry
legit you are killing me son oh no
that's embarrassing
okay so the problem is this I'm almost
positive oh that's gross stupid yeah
you're just depending I probably just
quit huh okay alright we are off okay so
I was just appending to it and I just
wasn't scrolling down far enough like a
big dummy okay so once we fix that
little error this some people probably
yelling at the screen like come on man
okay so looks good fortunately at some
point we should have the zero zero which
would be like
somewhere in the middle ish right like
at some point we should have a ship that
has some degree of halite I'm not seeing
it but later we are gonna have more
ships come out anyway and I think we'll
be fine
so we will find out soon enough
so okay so we have the data now what we
want to do is test out text what I'd
like to do is fully visualize it I think
so let's create a new folder and let's
call this folder gameplay okay then
we'll close this and cool so rather than
at the very end doing this what we
should do is like before command Q we
can just say something like this so
let's go ahead and let's say NP we are
we importing numpy in the first place no
so we will import numpy as NP scroll
down to the beard the end n P dot save
what do we want to save it as well we're
gonna save it as game play slash and
then we're gonna go with game dot turn
number dot n py and then don't forget to
actually save something that's probably
useful isn't it surroundings surrounding
surrounding it's cool and then so this
ships always going to move north cool um
I think we're good we'll save that and
let's test it what could go wrong
everybody all right looks good it slowed
down so I bet we are saving let's check
okay we've got some some beautiful
beautiful numpy files in there so now
what I'd like to do once this is done is
we'll just use testing grounds I suppose
and let's do so you would want to make
sure you have open CV Python so that
would be PI - 3 6 hopefully that'll give
us but yeah I think that's what we're
using I don't even really haven't really
been paying much attention so let's see
what Python corresponds to really quick
it should be Python ok python 3 point 6
min 7 yeah and the reason why we're not
using 3 7 right now is because
tensorflow to my knowledge still does
not yet support 3.7 or really 3.7
doesn't support estimate I don't test
below doesn't it doesn't work on 3.7 yet
okay so uh Python and pip install OpenCV
- python make sure we have it Ruby
didn't that would have been annoying
okay so we're use OpenCV just to display
this and um basically display it in like
video form so what I'd like to do let's
see here
I guess we're going to testing grounds
and then let us import CV to import
numpy as NP then what we're gonna do is
for I in range of and we could like
iterate over here or figure out what the
max number is I'm just gonna say okay
it's 425 so
425 in fact that would stop at it'll
start at 0 and stop at 424 so I guess
you would have to say 426 I don't know
425 is fine though and then what we're
gonna say it is d4 data equals NP dot
load and we are going to load game play
/ i dot NP why I believe it was just a
turn number yes so we load in the data
let's go ahead and just make sure that's
working print D and then we'll just
break right away really so
oh what a newb nice try again really
gate okay game play zero or game play
one dot NP why does not exist it
literally starts at two okay that makes
sense because we didn't have a we don't
have a ship so and turn one there were
no ships and we send a command Q to make
a ship so we don't have anything till
turn two
okay but here it is beautiful so we
could just play it so so in theory we
could I think we can just do this Seba
to not show we'll just give it as an
empty title and then D let me save that
and I'm gonna run this outside of
sublime sublime is not always the best
way to run things this might be one of
them so what is it Python testing
grounds I didn't see anything did I do
we maybe up to week
or something I don't know
I think this would give us just one
thing though right but it still cuts
let's try see what you do wait wait key
I don't know five I just want to see the
darn image man CV T dot M show ya see it
pops up I'm trying to think of what what
is it what does it take usually I
thought it's and I thought it would sit
there for me but it doesn't appear to be
okay there it is okay this is really
small
again it's a 32 by 32 so but I can see a
little bit of something there okay so so
first thing we want to do is show and we
need to resize these so we're gonna see
v2 dot resize we're gonna resize D and
then you can say I think this is like up
from what point maybe I really don't
know but it always is 0 0 and then FX
let's make it 50 times larger and FY 50
times so we're just the function of X is
x 50 function of Y times 50 okay we'll
save that let me run it again but still
running a parent apparently what what's
going on sir is this Python testing
grants top i whoa okay maybe a little
large
okay a little smaller next time
everybody and now I guess I can't break
out of this we're probably gonna wait
for that so let's do like a I don't know
maybe a 30 but you could probably start
seeing the halide already
Python testing okay great so there we
have it this so it'd be I bet this is
BGR right cuz the High Line is clearly
blue that dot in the middle is probably
actually the shipyard because our ship
probably has no color at all because yes
it is a friendly ship but it has
probably how likes it was just created
all right cool
we're pretty where this is this is
coming together well so now what we want
to do is can I get away with the
following D what was it for 25 save this
sometimes this doesn't work trying to
think sometimes to get it to actually
play video form you need a little more
crazy stuff but let's see what happens
Python testing grounds please work whoa
it works for some reason that stuff's
flipping around and I can't decide why
that would happen why would that happen
is it possible we're that's very curious
why are we flipping like that I will
have to come back in the next video I
guess I don't want to spend too much
time sitting on this and I guess all uh
we'll come back in the next video and
then once I figure that out once we have
that working really the next thing is to
just start saving the data and so we'll
play games we'll come up with some sort
of reason for which ones we want to use
for training data which ones we don't
and then from there we can start
training a model and see how that model
does I'm confident I'll figure out what
the heck is going on here why is that
flipping around figure that out let's
figure that out we will be all set
also hmm yeah maybe I'll do some more
logging or something I don't know
anyways kill me
but I'm not going to keep wasting video
anyway I will see you guys in the next
video we'll solve this and continue
taking over the world quick shout out to
the most recent channel members Vinicius
Nathanael Aikman Alexis Wong and Daniel
Aguiar thank you guys very very much for
your support you guys are awesome
I will see everybody else in the next
video
okay problem solved a really stupid
issue basically it was just by chance
which a I got to write first because we
were playing Santa bot vs. sent a bot
both of them were attempting to write
for that given turn number so whichever
one wrote at last that's the one that
got that turn so I made a you know quick
sent a bot - and just commented out the
NP save bit and then if we rerun that
which I have here let me make sure yes
sent a bot - then run that then come
into the testing grounds once that gets
to be to some degree done we can run
testing grounds and we can see we no
longer have that flippity floppity it
works the way it is intended so stupid
stupid error but it's the way it goes I
guess and actually I was talking to
Daniel aka danos aka problem solver
aficionado and as often happens you
start explaining your problem to
somebody else and then you realize what
you've done
so anyway funny ok so the last thing I
want to show before we get into this the
next tutorial because I don't want to
have to show the visualization again is
if we do secrets dot choice and then
what was the option Direction order I
think we can save that come over here
rerun that and what just what I want to
show is the ship as it collects
highlight it should show up as G
as green rather not G so now let me
appear nazi DM CMD Python testing
grounds I thought he would move randomly
why didn't he move randomly big dummy oh
did we do maybe we did player 2 yeah we
sure did last tutorial of the day also
unbelievably a long tutorial my
apologies but people were asking for
longer tutorials this is what the people
have wanted right ok so that should be
plenty of data so let's run this Python
testing grounds ok so he Wiggles around
as you can see kind of turns green as he
picks up more highlights if you're
running this locally you'll probably be
way more likely to see it than you could
in my replay but it does happen so let
the record show all right that's all
just wanted to show what the problem was
because I don't want to really have to
spend time the next video on it so
that's all see you guys in another video