what's going on Iranian welcome to a
tutorial on correlation one's game of
terminal which is a competition where
you compete against other players the
it's kind of a game map like other games
you might have seen like halide or
something like that although this is a
fixed game map but the idea is you
compete against other players at writing
these BOTS in various languages will of
course be using Python so correlation
one is just a company that aims to help
other companies find data scientists by
way of having challenges like this
really not much different than like
Kaggle or like two Sigma's highlight for
example so I think the best way to learn
terminal is likely just go play it by
hand a couple of times or you can follow
along with this tutorial and hopefully
learn it but before we get too far into
a tutorial I just want to describe the
actual unit types because that's pretty
useful to understand what you have so it
kind of falls under the unit types fall
under two different categories you've
got attackers and defenders so under
attackers you've got ping EMP and
scrambler the ping is a very very cheap
unit but also it doesn't really do much
other than it basically it's really fast
but it's weak so we it'll get destroyed
quite quickly
you've got the EMP which is a lot more
it's a lot slower but it's quite
powerful and then you've got a scrambler
which also affects other enemy
information units as well then you've
got your defenders you've got a filter
and the filter again is cheap can't
disrupt any enemy units but it can kind
of get in the way create a wall
basically also you can use it to protect
your other larger defender units so
you've got a now you've got a destructor
this is quite expensive your biggest one
but it can also destroy other enemy
units and then finally you've got the
encrypter which just strengthens your
your offensive units or your information
units okay so basically you can read
more there are tons of rules in just
documentation in general as far as how
things actually work because all you do
is you place
you start your enemy units like you
deploy at a location and that's it so
the rest like all the movement and stuff
is just completely automated so the why
is probably to go to read the
documentation to get an idea for exactly
how each thing is allowed to move and
like what happens in certain scenarios
so really it's more about coming up with
a strategy and placing units kind of
like a like a game at chess or something
like that rather than a game like halite
where actually your biggest thing is
like how do you want to move this is
more of how do you want to place units
so with that let's go ahead and get
started there's two kind of major ways
you could do this you could either code
locally and then upload your algorithm
and then see how things went but to
generally I think to develop you want to
be able to see like what errors you
might have made and stuff like that and
so if you just upload it's a little
challenging but it can also be
challenging to run it locally especially
on like Windows but if you go to their
github I will put links in the
description for all this stuff you can
you can get the install basically you're
going to need Python 3.6 or later you're
gonna need PowerShell which comes with
Windows 10 otherwise you can install it
you also will need Java 10 or later and
then you need the the starting script
I've already done all the things that I
need to do but again definitely go to
there the github again I will link to
the github in the description for sure
also I'll have a text-based version of
this tutorial so you can get all the
info but probably the hardest thing is
just making sure this part works it can
be a little finicky with PowerShell and
also I'm just not that creative
PowerShell is it was actually the first
time I've ever made use of PowerShell
but like I said you actually don't have
to use PowerShell also if you're on like
Mac or Linux you'll be fine just in your
terminal it's really just if you want to
run on Windows but it is super useful to
be able to develop locally so you can
actually see what errors you hit so
anyway the next thing I'm going to do is
clone this I'll download
the zip and we'll get started also in
terminal I'm already logged in but you
you can log in with your github
basically so I'm gonna move this over I
was hoping to stick it to the side of
the screen for some reason I was not
working okay so I think what I'll do I
think I'm gonna leave that up so I'm
just gonna extract this great and if you
are on Windows and or any other
operating system for example and you
just don't have Java or whatever feel
free to pause the video get the things
that you need to actually run and then
come back wow this is taking a while to
extract I don't think that was going to
take so long so once we have that let's
go into this directory here and then
into the master here and just for the
record to like run things you can just
type PowerShell again if you're on
Windows to get that to pop up here cool
so now for just a quick example of like
running things this will be the the way
that you run pretty much everything also
make sure if you do type Python that
that corresponds to Python 3.6 or
greater okay so the next thing is like
to run something I would type like
Python and then we want to run scripts
and then it's run underscore match dot
hi and part of me wants to shorten this
so it doesn't take up the entire screen
but yeah it's okay I'll just do maybe
this anyway we want to use run match dot
pi and then the two things that we want
to run so in this case we're just gonna
run this sample algorithm here so it'll
be Python algo so then you just say
python algo vs python algo hit enter and
make sure that works if that doesn't
work for whatever reason feel free to
come into like our discord discord GG
centex and feel free to ask questions
also check out like I said the
correlation one github
and all that and because they like I
said on Windows it can be a little
finicky especially with running various
different things and permissions issues
and stuff like that so just take note of
that okay so anyways this appears to be
running just fine
whenever it is done we'll get a replay
in this replays directory it looks like
we've got one building right now and
then once you have the replay you can
come into the terminal website and then
go to play and then right here you can
drag and drop a replay file but first
we're just gonna get coding and then
worry about the replays but also in here
you can play like by hand and then
versus a bot or something like that or
by hand versus by hand it's kind of a
good way to figure out a strategy to
play or you can play like by hand versus
one of your BOTS and stuff like that
it's pretty cool so this in fact what we
could do I could just upload that since
that's done now so you just click and
drag that over to your replay file here
hit watch replay maybe pretty sure I
clicked it
I don't know this machine is going kind
of slow today there we go
I'll start the tutorial or start the
replay rather okay so as you can see and
then you can cut you can speed it up by
coming down here and then I can go like
a Dex speed anyways
so these are like the defensive units
and then this is like an attacker unit
and the goal is to get to the opponent's
edge and that's kind of how you get
points or get rid of enemy health stuff
like that so now I minimize this and I
guess I'll leave this up for now we'll
come into here and I am going to make a
new directory and we're gonna call this
tutorial I'll go and then we're gonna
take some of the files from the Python
I'll go here cool we'll take game Lib
run run this is a powershell script by
the way i'll go json and i'm going to
copy the algo strategy as well we're
probably just gonna empty it but it's
okay and then we'll come into where's
the one I just made a tutorial I'll go I
need to zoom in I can't even see it
there we go
cool okay now the only thing we need to
modify here is algo strategy and I'm
going to use sublime text so you can use
whatever you want to use open with
sublime text cool
alright I'm gonna empty that out start a
nice and fresh alright so now what we're
gonna do is begin to build our algo
first I'm going to import game Lib this
just has a lot of the helper kind of
functions and stuff for interacting with
the game for us then class tutorial bot
and then in here we will inherit from
game Lib dots
I'll go core so then we have a defined
on game start this just is run one time
this is where you're gonna set any of
your like your kind of constant values
or variables that you want to use
throughout self dot config equals the
configuration it's past for now we're
not going to set anything but pretty
quickly we'll set our units there cuz
the like the unit the library of up of
the units that we can choose from
basically it was not going to change so
that's like something that you would say
here any sort of like constant value
then what we're gonna say is define on
turn self and turn state and for now
we'll just pass here and then finally to
run if name equals may algo equals
tutorial bot and then I'll go start so
that's just kind of like a quick initial
skeleton of how things are gonna work
and then basically on so here you'll
define all your starting values or
whatever then on turn this is where your
logic will go now this doesn't do
anything so let's go ahead and do some
stuff first we'll set some of these
starting values so we're in a global
we're gonna global a bunch of stuff here
filter encrypter encrypt or destructor
ping EMP scrambler unit to I D so we're
going to global all of those works are
not going to set unit to ID here so
we'll take this
Museum at a little bit cool and then
we're going to say filter encrypter
destructor paying EMP scrambler equals
and we're just going to do a quick list
comprehension here this will be equal to
the config or self dot config unit in
formation and then we'll use index and
then shorthand for ID x in range six so
that's just going to iterate over these
unit types basically so we can save
those so one later we can just reference
filter encrypt or destructor and so on
as the thing that we want to build right
so those are just our unit types would
be nice if these were just like stored
in some way that we could just import
them I think that would peak a little
more sense but this is the way that I'm
gonna do it for now
so now that we've done that we're ready
to actually do something on on turn so
first we're gonna get the game state
because that's gonna change every single
time so game Lib game state self dot
config and turn state so that just tells
us what the state of the game is so we
can get certain values of where things
are placed and all that then what we're
gonna do is game state dot and Nabal
warnings equals false so right now it
seems to be I don't know some sort of a
bug where you get like this warning
every single time so I'm just going to
turn that off if something's happening
you'll still get certain errors and
stuff just fine and if for whatever
reason something's happening and we
can't figure it out we can set this back
to true but we end up getting this like
could not spawn at location over and
over and over even when that's not an
issue so we're gonna set that to false
for now then on turn basically we've got
two different types of units that are
doing two different types of things so
we're going to basically have two men
it's one for attacking one for defending
so we're gonna say self-defense and this
will take in a game state for now and
then self dot attack also game state and
then game state dot submit turn and we
should be good to go so then obviously
we need to have these methods actually
exist so real quickly it will just add
those so sell define the offense self
game state for now we'll hit a pass here
and then define a TAC self game State
game sautee game state and we'll pass
again so the logic for defending will go
here in the logic for attacking will go
there okay so now we will start with our
defense logic so what we're gonna do
here is basically I think what we'll
we'll have a quick helper here so define
build defenses and what this will do is
build defenses if we can otherwise kind
of notify us if something went wrong
basically so self location list location
list firewall unit game state and row
equals none so these are kind of like
coordinates or you can pass row here so
you would have like a row and then an X
location so row is almost
interchangeable with y so it's basically
you know where do you want to place a
unit so again pretty much the entire
game is all about whether it's a
defensive unit or an attacking unit it's
where do you deploy that unit that
that's all you have to think about in
this game so or at least that's the only
action you get to take you obviously
need to think about a little more than
that probably take into account some of
your enemy position stuff like that
okay so so then what we'll do is zoom at
some more as we continue to have too
long of lines for location in the
location list that we pass if not type
location if not type location list then
we're gonna say location equals a list
that is location X and then what road do
you want to be on Y so then that
basically is going to populate the
things for in terms of like where we
want to place units and then what we
want to say is if game state dots can
spawn a firewall firewall unit at that
location so reasons why you wouldn't be
able to spawn something maybe
something's already in that spot or
something is passing through and so on
so anyway also can we afford to actually
spawn it so anyway game state can spawn
okay so what we'll say is game state dot
but just want to capitalize that game
state attempt to spawn a firewall unit
at that location and then we'll use
debugging game Lib debug underscore
write F strings firewall unit deployed
at location then whoops we will decrease
that resource so game states dots player
underscore resources zero cores - equals
game state type underscore cost fire
wall unit
so if we've spawned one of those what we
want to say or basically we want to take
away the cost from our resources so we
know later on can we can we spawn for
example okay so once we've done that
make some space here so if if we can
spawn great we will do that but L if not
game state dot contains station
stationery
Stacia soon as I can figure out a spell
stationary unit at that location we will
return false so if there's some other
reason like so if we try to spawn that
unit but there's already a unit there
that's okay we haven't like run out of
resources for example but for any other
reason we want to return false and we're
done iterating here otherwise if we make
it all the way through return true all
right so now we want to do is create
basically this is what will will pass
lists and then we'll pass a type of unit
here in that so like our build defenses
all it's going to do is build the fences
for basically the locations and the type
of unit that we pass so now coming back
to our defensive or defense method here
now we want to populate with locations
so again the game is a fixed size this
grid right here every single time so
everything's in the same spot so at
least to start the best way I can think
of to do it is just by manually figuring
out it's like if you hover over here you
can see here are the pointing to it but
they're over here anyway you can see
where the positions are and so that's
probably the way I think most people are
doing it eventually it'd be cool to
somehow to algorithmically pick those
locations but for now we're just kind of
hard-code them because there's really no
reason not to
other than later you might want to
algorithmically choose it based on maybe
your enemy is deploying unit something
like that anyways for now we're just
gonna hard-code the positions so defense
basically we're going to say okay where
do we want our filters to be placed and
so we're gonna place those and this will
just be a list of lists so we're gonna
place those at 0 13 then 27 13 so that's
basically the edge all on one side edge
of another side then 112 and 26 12 then
what we're gonna say is we're basically
gonna pass those to our function here
and then make sure that we didn't hit a
false at any point along the way so what
we're gonna say is if not self dot build
defenses and we're gonna pass filters as
the things basically the locations
filter is the unit we want to use and
then game state is the game state cool
successful if not then we want to build
our destructors and all the destructors
are going to be on the same row so we're
gonna say save say the row is 11 and
then we're gonna say the doors their
exposition will be a 225 621 11 and 16
again to pick those I would just
recommend going and hovering over that
map to figure out okay here are the
positions that I want to use for now and
later on you can get a lot more
complicated than than that but I think
to start that's honestly is just the
easiest way to do it so now if not self
dot build defenses and this time its
destructors then destruct door and then
game state and row equals row in this
case return
okay so now we've got that and then we
could build even more filters after this
like you'd pretty much want to continue
populating until until you've run out of
resources pretty much so now I'm going
to pass filters and this one is going to
be 324 423 522 728 19 918 1017 12 15 and
again this will basically happen in the
order that you pass so to keep in mind
that it's like you're not net you might
get a unit to here here and here and
then you've run out right and you can't
produce any more units so you'd want to
keep in mind that these are in order of
importance so you've got filters and
then if not itself don't build defenses
and in fact we'll just do this copy that
paste they're done okay
so let's save that and now come over to
our PowerShell I'm just gonna hit the up
arrow here and rather than Python algo I
think we couldn't call it tutorial algo
tutorial algo @ vs Python algo that's
fine we'll run that make sure we just
don't end abruptly
okay it looks like we ended abruptly
let me scroll up here
hmm
okay games state not defined so I
capitalized the s and game state
somewhere yay
find where I did I actually see this one
at least let's save that let's run that
again it's totally possible I made that
mistake multiple times also could I
while we wait on that font looks like I
hit another error
let's try 36 for now that's quite large
okay our issue here I forgot to add the
row here right so up here we were
passing that as part of the location but
what we need to pass here since we're
just we're gonna send them all to the
same row row save that run that and then
now what we should get is an actual
replay while I let that go ahead and
play I am going to come over to the
algorithm itself and we'll package that
up and also upload it so let me do this
Python now go we actually want tutorial
I'll go so all you need to do is just
zip it up so I'm gonna right click send
to desktop we'll leave it named the same
no problem and then you can come to play
and or actually let's go to my out goes
I thought we could upload it in play
yeah come here come to one of your empty
spots actually that other bot is the
same thing but let's make sure it works
so we'll go to desktop coming to here
here and we'll grab that zip that we
just made open
okay I'm gonna bring it in that I'll
compile for a little bit looks like it's
almost looks like it's done looks like
it compiled pretty darn quickly and then
eventually you'll start seeing some
games here we've actually made some wins
but as you get games up here you can hit
play and all that I'm kind of curious
how we won without attacking anybody but
okay that's fine so we can play this one
for example
wait for it
Perez here I wish it would just start
automatically and speed it up so as we
can see here we've we've got our side
here and then as the turns progress we
start adding our more of our defenses in
here as we can eventually we are
definitely going to lose this game but
but soon we'll start adding our own
attackers and hopefully doing a little
better but I think right now is a decent
stopping point so in the next tutorial
we will add some attacking and I think
we'll do much much better I think we'll
rank a lot better for sure if you've got
questions comments concerns whatever
feel free to leave those below also if
you want you can compete in a syntax
only competition at c1 Gamescom slash
Centex you can come there there is a
$500 cash prize for the for the
competition and if enough players come
in they'll raise it to a thousand so
we'll see how that goes
otherwise I will see you guys in the
next video where hopefully we do a
little more than defend ourselves but as
you can see our defenses are working
good enough so anyway questions comments
concerns whatever feel free to leave
them below come chat in discord
especially if you're having any issues
all that that's discord ggs last cent
cent dicks otherwise I'll see you next
time