what is going on everybody welcome to
part 11 of our Python 3 basics tutorial
series where we have been learning to
build a game of tic-tac-toe to pretty
much just learn the basics of Python
while actually doing something of
interest so so where we left off we were
determining the horizontal row of
winners and now we want to just do the
vertical row next or vertical win
basically so it really big column
anyways let's go ahead and get into it
so what I'm gonna do is actually I'm
gonna comment out this section because I
just I all I want the only code I want
right now is just for vertical win later
we'll combine all of the wind types of
codes into the same function but for
simplicity we're just gonna do do this
so here we have a a at least a game map
it didn't look very fair for player
number 1 but we have a game map where
player 2 clearly won vertically so how
could we determine that player 2 has one
or that somebody has one well basically
it would have to be everything in each
row every everything with the same index
would have to be the same number so for
example for row in game if we print row
0 and we run that we can see it it's
over all the rows prints the zeroeth you
know so the first element in each row
you see 2 2 2 right and then you could
have some sort of check here that's just
going to be like a list and because it's
like remember we you have a little check
column or check functionality here that
determines whether or not someone is one
so we actually could use this exact same
logic so in fact I'm going to copy X I'm
about to use it and let's append row 0
to check so the list unlike a tuple a
list you can continue building so to add
a value to the end of a list we can use
append so you can say check dot append
and then we're gonna append what we're
gonna just append the value that is row
0
so then whoops I just wanted to comment
that out then after we've done that we
could check and we'll just tab this over
and instead of being row count we're
gonna do check so if check dot count
check zero and then check and then check
and in fact let me fullscreen this I
don't know why that was so small print
winner so now if we run that we get
winner and then if we were to change
this hopefully back to a 1 we would see
okay there's no winner great so
obviously that's great but we've you
know hard-coded to check for row zero so
how could we go about checking all of
them well of course we could do this you
know this little snippet here and by
snippet I mean not a snippet and
actually all the way up to here and do
it four times or three times rather for
the 0th index the first tooth and the
second if index but obviously as I've
said before that's really not ideal we
want this code to remain dynamic as
possible so and yes I am aware that well
there's two major things one is the
print of the zero one two at the top of
our game map that we've worked on before
is not dynamic we'll fix it don't worry
and the game itself is not really
changeable easily but again we'll fix it
don't worry anyways we want to keep it
as dynamic as possible so what could we
do well we could I think I'm gonna leave
this here
I guess check can stay but basically we
would say you know we would need some
number of columns and you could say 0 1
into 0 1 2 and then and then iterate you
know for call in columns and then run
this and then it would be row call and
then the rest stays the same so again
run it winter and then if we changed
this and then we did
like this now player one actually got an
opportunity to play this time player one
one and we could comment this one out
okay no winner cool so so this logic
clearly is working but again we've got
this is being hard-coded in and we don't
want that so what could we do well this
is you know it's three elements and it's
just increment it starts from zero and
increments by one per each what well per
each column that we have and also the
sense the game is square you could say
per row that we have as well so if we
were to get say the Len which is a
built-in function for Python Len of game
the answer to that is equal to three
also we could just have a counter like
you could literally for call and you
could say for call in column rather than
that you could say for call in like I'm
trying to think of a really good really
good way to get around it but coms
basically we could just say columns is
like if you just wanted to iterate 0 1 2
what probably the best way is with a
range so again range isn't something
that we've talked about but it's a
built-in function in Python so let me do
built Python functions really built-in
Python functions 3.7 maybe I'm surprised
that wasn't like the top result I must
have typed it different than normal
anyway we can come down to range and we
can actually see that range is it going
to explain range anyway okay yeah it
does rather than being a function range
is actually an immutable sequence type
so it's actually not a function but we
treat it like a function so it's okay we
all just we it's it's included in the
built-in functions because we treat it
like one
but in the backend is actually not a
function it's a much it's much more
efficient and the reason why you'd want
that is in theory you could do you know
range of like a huge number and that
won't blow your memory but if you were
to do something to convert it to a list
for example and make that a list of that
size that will absolutely blow your
memory so let me open up the command
window real quick and let's run pi -
three points us not three six three
seven I'm so used to typing three six
there okay and let's just say an x
equals range three and then like for I
in X prints I you get zero one two okay
so it just iterates over that and it's
not quite a list it's al it's much more
efficient than a list and we'll see
later that there's other operations that
we can do on this that are similar
operations to what we could do to a list
as well so anyways that's how I think we
should go about it we're basically this
number three is just the Len of the game
so what we'll do is we'll come over here
and so forth rather than being for call
in columns what we'll say is a four call
in and then we'll just do range Len game
and then we can get rid of this silly
columns run it again okay no winter
let's add a winner here let's do this
run it okay we've got a winner and then
we can change that go maybe do this one
over here winner
cool nobody should win cool nobody won
okay so I think that the probably the
next thing that we want to do is I think
in the next video we'll do both
hopefully we can do both of the
diagonals I don't really think there's
gonna be I want to stuff that in in this
video
anyways so this will be our methodology
for detecting vertical winds and this
should work at least from the swimming
to click on that this should work for
any size game board it's just going to
run through all of the rows at those
specific indexes and if there's a winner
cool we print winter and later we'll
print winner to be a little more dynamic
say who won how did they win all that so
we will get to stuff like that but for
now I think I'll stop it here and in the
next tutorial we are going to do the
diagonals which arguably is maybe the
hardest but shouldn't be too bad so
anyways that's all for now if you've got
questions comments concerns whatever
feel free to leave them below otherwise
I will see you in the next video