WEBVTT

00:01.080 --> 00:07.450
So now you've gotten the ship or the boards to draw properly.

00:07.800 --> 00:12.420
Actually almost done sort of we even know it didn't seem like it.

00:12.420 --> 00:17.430
All we've done and play game is do the set up boards but really that was actually a lot of the heavy

00:17.430 --> 00:20.900
lifting in tween lectures.

00:20.970 --> 00:22.410
I just set up the

00:25.260 --> 00:35.640
to run in my terminal because I want to have it I want to be able to clear the screen and use that clear

00:35.640 --> 00:38.850
screen function that we wrote hangman.

00:38.910 --> 00:47.750
One thing I did also is I changed the size of my bat the terminal window the default size.

00:47.760 --> 00:53.380
Usually it's like 80 by 24 I made it 86 by 32.

00:53.580 --> 01:00.750
So I did that by going to preferences and then settings and then in the window size that is change that

01:00.750 --> 01:07.710
columns to 86 and the roosted to you in Windows.

01:07.800 --> 01:14.430
You really just have to right click and then hit preferences or something or settings possibly and you'll

01:14.430 --> 01:16.830
see somewhere called

01:19.700 --> 01:24.970
I think it's like size or something and then you can actually change the size of your window on Windows

01:24.970 --> 01:26.170
as well.

01:26.230 --> 01:29.700
So that's just one thing I did.

01:30.210 --> 01:31.930
So I'm not going to show you how to set that up.

01:31.930 --> 01:35.160
I showed you that already in hangman.

01:35.650 --> 01:45.950
So now I want to in our draw function is done here.

01:47.570 --> 01:48.660
Job boards.

01:48.720 --> 01:52.930
I will clear the screen clear screen

01:56.560 --> 01:58.990
J.

02:00.280 --> 02:00.550
Do.

02:00.550 --> 02:13.290
This is a one vertical clearing the screen and there's one other thing I want to do in set up boards.

02:13.810 --> 02:18.190
You wrote that function in our

02:20.380 --> 02:26.330
utilities to wait for a key press.

02:26.350 --> 02:28.410
So I actually want to use it here.

02:28.420 --> 02:35.250
So here I want to use wait for key press.

02:35.370 --> 02:40.200
And actually here AFTER AFTER THIS TO WAIT FOR THIS

02:44.510 --> 02:46.240
like that it's.

02:46.320 --> 03:02.000
So now if I run it and I say A or actually say J say 10 or Zambal it wasn't a valid placement it says

03:02.010 --> 03:06.200
it's a and b c it says Press any key to continue.

03:06.720 --> 03:13.870
So then again it's a one horizontal k.

03:14.200 --> 03:17.290
So it's working pretty nicely.

03:17.320 --> 03:25.690
So now we should really just start wrapping up really.

03:25.690 --> 03:30.070
So we want to finish play game

03:32.730 --> 03:35.650
and you may think so many things to do.

03:35.780 --> 03:46.870
It's really not that mean things to do and actually one thing we need is the current player or current

03:47.100 --> 03:59.170
Where am actually going to set them to be Player 1 just because player 1 will get precedence and the

03:59.170 --> 04:03.560
other player will be player to notice him using pointers here.

04:04.140 --> 04:17.770
And I will also get the guess an I guess and we'll say do will draw the boards.

04:18.790 --> 04:21.450
Of the current player.

04:23.410 --> 04:26.230
Since it's a pointer we have to dereference it.

04:27.200 --> 04:44.410
And all I have is valid guess at and we'll say Do While know is valid guess.

04:44.490 --> 04:48.810
So we basically want to get it or.

04:48.810 --> 04:52.830
Well first we want to prompt either so see Ouch

04:56.640 --> 05:01.930
current We're name

05:05.640 --> 05:08.820
what Which guess

05:12.990 --> 05:20.900
K and then we'll get the guess using the function he already made get board position.

05:21.180 --> 05:31.480
It's very me that function last time and we'll basically it's a valid guess is no guess a valid guess

05:31.570 --> 05:32.290
if

05:34.500 --> 05:42.540
essentially the current CH clear

05:46.010 --> 05:48.130
so the guest board

05:51.260 --> 05:55.640
so his guest board is is valid.

05:55.640 --> 06:01.010
If it wasn't if we haven't guessed they're essentially so

06:03.560 --> 06:06.510
what.

06:07.160 --> 06:12.180
So if that's equal to G.T. non

06:19.700 --> 06:22.870
So that's that one.

06:23.170 --> 06:25.510
While these

06:29.380 --> 06:30.960
will make that in a minute.

06:31.270 --> 06:35.960
So that's really all there is to that one.

06:36.580 --> 06:39.950
And then we have to check to see if it's not valid.

06:39.970 --> 06:43.000
Yes we should just output.

06:43.960 --> 06:56.580
Yes we should point to the user that it was which was a valid guess.

06:56.850 --> 06:58.270
He.

06:58.590 --> 06:59.240
Yes.

07:04.310 --> 07:08.690
So.

07:08.910 --> 07:15.570
So now that we have a valid guess we should update the board.

07:15.670 --> 07:16.310
Right.

07:16.750 --> 07:26.820
So the board will actually return to ship type the ship type that was hit.

07:27.400 --> 07:32.760
So when to use ship type time.

07:33.720 --> 07:45.950
And it's going to be cool to update or it's using the guess in the current player and the other glare

07:50.420 --> 07:54.090
and then we will draw the boards of the current player

07:59.410 --> 08:07.430
so and we'll say if the type is not equal to Esti none right.

08:07.450 --> 08:10.530
So if it was a hit.

08:10.540 --> 08:29.050
In other words and if it if we sunk the other players ship the player and other player so his ships

08:29.950 --> 08:34.710
of the type that we hit minus one.

08:34.840 --> 08:35.520
OK.

08:35.740 --> 08:38.290
So notice up here.

08:38.290 --> 08:48.650
That's how we kind of initialize our ships before we actually initialized it in this order.

08:48.680 --> 08:53.880
So aircraft carrier first then shipping group cruiser than destroyer and submarine.

08:54.080 --> 08:56.980
And we have this none here.

08:57.000 --> 08:57.570
Right.

08:57.830 --> 09:01.670
Well we I actually initialize them in this order as well.

09:01.670 --> 09:04.680
So that's not a coincidence how I initialized it.

09:04.970 --> 09:13.200
So the type will actually be one plus the

09:15.940 --> 09:21.400
proper index into the players ships.

09:21.420 --> 09:26.030
OK so the example aircraft carrier is one.

09:26.110 --> 09:30.410
In this case so but aircraft carrier should be zero.

09:30.410 --> 09:40.680
Is that is the zero element in the ship so I just said down here and play a game type minus one.

09:41.020 --> 09:42.180
OK.

09:42.220 --> 09:49.410
So that's again another use for income's is using them as indices into arrays.

09:49.510 --> 09:50.170
OK.

09:50.260 --> 09:53.720
And I did that very purposely.

09:54.340 --> 09:56.830
So that was not an accident.

09:56.980 --> 09:59.260
So Ouch.

09:59.340 --> 10:00.170
You sunk

10:03.980 --> 10:04.920
there.

10:06.320 --> 10:11.680
The air is a your all your name

10:17.790 --> 10:23.330
and then that ship name or ship type

10:28.900 --> 10:29.420
so

10:34.350 --> 10:50.410
gay men here we will say wait for the press just so that it doesn't automatically get cleared once drop

10:50.410 --> 10:55.130
or will call the job boards.

10:55.180 --> 10:58.600
That's OK.

10:58.750 --> 11:01.710
So and then we will switch the players

11:05.700 --> 11:19.090
in the current player and other player and notice I'm giving it the address of these pointers.

11:19.100 --> 11:28.160
So if you saw the lectures four pointer pointers you know what I'm going to do here.

11:28.580 --> 11:31.490
And then so is game over.

11:31.490 --> 11:32.660
I'm going to need

11:35.990 --> 11:38.040
one player to.

11:40.360 --> 11:42.900
And we're going to need display when her

11:54.980 --> 11:55.680
k.

11:55.920 --> 12:06.710
So really we need to implement update boards is sunk so players is game over and display winner.

12:08.040 --> 12:14.620
And they'll be one more with in is game over that we already saw two improvement.

12:14.670 --> 12:21.270
So let's start at finding these and let's start with updateable it's

12:25.420 --> 12:26.380
capitis

12:34.800 --> 12:41.820
turn ship type ship that you hit.

12:41.930 --> 12:51.830
If you did hit one and ship position to I guess and should be

12:55.490 --> 13:01.250
the should be a reference.

13:01.630 --> 13:05.940
Is your current player.

13:07.720 --> 13:08.210
Here.

13:08.280 --> 13:09.330
It's the other.

13:13.270 --> 13:20.020
So it's going to hit it right here.

13:21.500 --> 13:22.820
So update board.

13:22.820 --> 13:40.720
So if the other player ship or third the CAS row and the gas column so if it's a

13:43.360 --> 13:48.810
type so if it's not Esti none then it must be a hit.

13:48.870 --> 13:50.010
Right.

13:50.130 --> 13:52.070
Is the hitch.

13:52.120 --> 13:54.210
Otherwise it's not a hit.

13:54.370 --> 13:55.310
OK.

13:55.840 --> 14:11.840
So the current player gets bored Gastar row guess or call them is Gaspard.

14:11.860 --> 14:15.180
This should be cat.

14:15.860 --> 14:17.410
And the other player

14:20.790 --> 14:24.280
shipboard.

14:24.520 --> 14:26.030
Yes.

14:28.860 --> 14:30.020
Yes.

14:30.220 --> 14:32.910
Call them in.

14:32.910 --> 14:34.280
This should be.

14:34.440 --> 14:44.090
Is hit and it's true.

14:44.570 --> 14:49.340
And then here you say get current player like he didn't hit.

14:49.340 --> 14:58.020
He missed us or had just bored guest row and stuff.

14:58.120 --> 15:02.130
Which column is he missed.

15:04.340 --> 15:14.070
And will return other player ship or add in the guest row.

15:15.070 --> 15:20.600
In the yes column in the ship.

15:20.620 --> 15:21.000
Right.

15:22.060 --> 15:22.640
OK.

15:22.970 --> 15:27.230
So whether it's Jiechi non or it's some other type.

15:27.440 --> 15:28.430
OK.

15:29.610 --> 15:32.460
So that's really it for the update.

15:32.460 --> 15:43.070
Actually it's really nothing more to it what to do is game over.

15:43.260 --> 15:44.150
Cup is

15:48.880 --> 15:50.380
put it here.

15:51.450 --> 15:53.820
And returns true if the game's over and falls.

15:53.840 --> 15:54.430
It's not

15:57.850 --> 16:03.260
need to change the player it also can be Konst.

16:03.670 --> 16:04.290
Your

16:08.260 --> 16:09.390
copy it's

16:11.960 --> 16:20.310
in play place it after here is OK.

16:20.470 --> 16:23.210
So how would this work.

16:29.490 --> 16:39.260
So if we look we made some new function called are all ships sunk in.

16:39.270 --> 16:41.140
Gave it the player.

16:42.160 --> 16:49.030
So we need to implement that.

16:49.160 --> 17:15.000
So here we're just going to say return our ship ships sunk one or our ships song for play or to and

17:15.280 --> 17:18.640
now appear are going to implement.

17:18.650 --> 17:24.610
So it's going to turn a billion are all ships

17:26.870 --> 17:28.840
and given the player

17:32.450 --> 17:33.160
here.

17:34.030 --> 17:56.670
And we go through see through this number of ships plus an F notch is on onto that next ships

18:00.170 --> 18:01.500
and we return false right.

18:01.530 --> 18:17.540
So if one is not Sonke and not all the ships just like lies which are true and now for the sunk will

18:19.040 --> 18:24.030
sunk in now declare everything above.

18:25.510 --> 18:26.890
Where in the

18:32.300 --> 18:33.800
SO if

18:37.060 --> 18:42.240
the ship's orientation is horizontal

18:47.030 --> 18:59.290
then we'll go through all the columns of the ship ship position column

19:03.640 --> 19:07.070
then ship session

19:09.580 --> 19:12.570
complex ship such as

19:17.050 --> 19:19.090
boss.

19:19.260 --> 19:26.900
If so if it's not it's not hit here.

19:27.730 --> 19:37.780
Then you know it's not sunk because they are every part of the ship has to be hit in order for it to

19:37.780 --> 19:40.290
be sunk.

19:40.550 --> 19:44.730
Shane Rowe column

19:48.280 --> 19:51.660
it's not hit and there's no way.

19:52.480 --> 19:59.590
And then we just do that for the critical case for each row.

20:01.620 --> 20:04.450
Ship and

20:08.170 --> 20:16.560
ship and rope was ship ships as

20:19.960 --> 20:26.590
boss if not where.

20:30.120 --> 20:36.450
Grew and ship the ship and call column.

20:36.620 --> 20:37.910
So if that's not hit

20:41.630 --> 20:43.280
then it can't have been on

20:47.260 --> 20:51.970
here if it never return then obviously they're all sunk.

20:52.270 --> 20:56.010
Or it or this ship at least sunk.

20:56.560 --> 20:59.230
So now it's clear that these

21:07.980 --> 21:09.230
after it came over

21:31.400 --> 21:34.520
so we're almost done.

21:34.520 --> 21:41.250
Actually we just need to do switch players and just play winner.

21:41.620 --> 21:48.340
So let's do this one.

21:48.480 --> 21:49.690
It's kind of fun.

21:52.360 --> 22:00.720
So it's going to return nothing and it's going to take a pleasure star star

22:03.890 --> 22:06.620
because we're going change the original pointer.

22:09.620 --> 22:10.810
Just like we learned

22:13.490 --> 22:17.820
in the last section.

22:17.980 --> 22:20.830
So put it straight here.

22:23.470 --> 22:32.980
So where start Tim it temporary will be the current where say

22:35.780 --> 22:43.980
in the current Where is going to be the other player.

22:48.400 --> 22:55.560
And the other player be OK.

22:55.740 --> 22:57.850
So see our new you are referencing.

22:57.960 --> 23:01.950
Each time we're actually changing the original pointer.

23:02.220 --> 23:08.370
So we've gone over this in the last section so you should kind of understand how this is working now.

23:08.370 --> 23:15.510
And we whenever the swap kind of function before so you kind of understand how this whole swap functions

23:15.510 --> 23:17.580
sort of works as well.

23:17.610 --> 23:18.450
OK.

23:18.840 --> 23:25.180
So that's how you switch the player which players.

23:25.600 --> 23:32.980
And now really in what's left all there is left is really the display winner

23:36.360 --> 23:44.000
so this one should be fairly obvious as well.

23:44.020 --> 23:45.910
How to write it.

23:47.100 --> 23:53.460
Kind of written it a bunch of times for.

23:54.540 --> 23:58.640
So I passed this by conc player reference

24:01.320 --> 24:02.330
player for it.

24:02.390 --> 24:02.960
It's

24:05.550 --> 24:18.450
like so gay and let's just put it after as players emitting command like command click to go to these.

24:18.450 --> 24:24.370
If you're under just in case you're wondering how I'm doing that.

24:24.460 --> 24:28.050
So just put it right here.

24:29.310 --> 24:30.140
OK.

24:30.610 --> 24:42.220
And if it works you can use this one and again are all ships sunk player one then obviously player 2

24:42.280 --> 24:42.560
1.

24:42.570 --> 24:43.160
Right.

24:43.320 --> 24:44.100
Yeah.

24:46.690 --> 24:50.840
Great nations

24:54.590 --> 24:57.640
to your name

25:01.130 --> 25:01.730
you

25:08.580 --> 25:12.260
and else.

25:12.310 --> 25:13.240
Yeah.

25:19.060 --> 25:20.070
Shin's

25:23.050 --> 25:24.020
player 1

25:36.130 --> 25:41.670
K super simple.

25:41.770 --> 25:43.820
So that's really it.

25:43.820 --> 25:47.510
So what's actually plaguing

25:50.430 --> 25:51.310
one error.

25:51.350 --> 25:54.610
No ship name for type

26:05.300 --> 26:06.880
so I don't think that cleared

26:12.430 --> 26:29.650
so it's.

26:29.690 --> 26:33.530
So let's actually play one game of that.

26:33.890 --> 26:35.930
See if everything's working correctly.

26:35.950 --> 26:52.940
So a going to do the simplest possible out I can think of you on Mars aren't all an easy one.

26:54.090 --> 27:04.030
Horizontal so for player one all all of his hours all of his ships will be all horizontally and player

27:04.030 --> 27:07.360
to all be vertical OK.

27:07.700 --> 27:09.610
Gee when.

27:09.810 --> 27:16.000
So it all in one Santal.

27:16.200 --> 27:16.810
OK.

27:16.930 --> 27:20.640
So here is the press the key to continue.

27:20.680 --> 27:22.120
Thing again.

27:22.120 --> 27:23.630
So here's my lay out.

27:23.640 --> 27:26.950
Player 1 and Player 2.

27:27.100 --> 27:29.090
I will do all vertical.

27:29.410 --> 27:41.860
A 1 vertical in a three vertical

27:45.360 --> 27:51.060
A five go a

27:53.830 --> 27:59.600
seven or goal a

28:02.310 --> 28:03.300
vertical.

28:03.730 --> 28:05.410
And here's player do.

28:05.910 --> 28:10.480
So now switch to player 1 player 1 What is your guess.

28:10.870 --> 28:15.210
I'm going to make player one just completely destroy a player do.

28:15.290 --> 28:27.070
So I'm going to use kind of clairvoyant credible here and try that one so see how it hit.

28:27.260 --> 28:29.030
So this is my guess for it.

28:29.090 --> 28:34.640
It's a hit and it prompts me to continue by pressing any key.

28:35.700 --> 28:41.810
So player 2 What's your guess be on.

28:41.820 --> 28:45.420
So I see he has this here right.

28:46.050 --> 28:50.080
So hopefully you will do this pretty quick.

28:50.190 --> 28:52.320
Be one

28:58.970 --> 29:04.810
hit and guess B to here.

29:06.580 --> 29:17.700
Miss C-One hit and guess B three three

29:20.490 --> 29:23.080
d one.

29:23.310 --> 29:24.390
Still ahead.

29:24.560 --> 29:27.880
No this has hasn't hasn't actually sunk a ship.

29:28.010 --> 29:28.630
Right.

29:29.310 --> 29:31.410
And B for

29:33.980 --> 29:41.060
he one so use player to use aircraft carrier.

29:42.620 --> 29:45.160
There you go.

29:46.550 --> 30:00.690
Hopefully Stroh's be possible that be five miss a three.

30:02.630 --> 30:03.580
Next

30:09.480 --> 30:11.350
you won't play the entire game.

30:12.200 --> 30:14.850
P.

30:16.810 --> 30:19.120
Posts three their posts for that.

30:19.210 --> 30:20.990
No no no.

30:22.540 --> 30:25.010
So B.

30:25.300 --> 30:28.820
I mean so you get the idea.

30:28.820 --> 30:32.240
So I think everything's actually working pretty well.

30:32.540 --> 30:41.630
And in the next lecture I want to go over adding a nice little feature because it's kind of annoying.

30:41.630 --> 30:47.980
Playing against two human players raped her two human players playing when there's only one of me or

30:48.590 --> 30:52.180
so would be nice if I could play against a simple AI.

30:52.400 --> 30:55.450
So that's what we'll be doing in the next lecture.
