WEBVTT

0
00:00.600 --> 00:09.240
So in this lecture I want to go over how to make a very simple AI and AI will just kind of randomly

1
00:09.240 --> 00:11.260
guess.

2
00:11.730 --> 00:20.540
And since we're changing the problem now our original problem was more for two human players.

3
00:21.120 --> 00:27.270
And now it's for well we're going to be able to choose whether we want to play against a human or a

4
00:27.480 --> 00:29.260
AI.

5
00:29.860 --> 00:34.140
And since we're changing the problem this really changes the data.

6
00:34.470 --> 00:43.050
In order for us to get this working we'll need to add something to our data.

7
00:43.560 --> 00:46.100
And we're going to adding another

8
00:48.690 --> 00:50.120
called player type

9
00:52.750 --> 00:58.790
in this player type could be human.

10
00:59.330 --> 01:05.430
Human or PTV AI.

11
01:05.830 --> 01:13.770
So now that we have that rapid change or player as well and the player is going to have a player type

12
01:17.750 --> 01:21.280
type.

13
01:22.780 --> 01:29.440
And now we have to change a couple things around.

14
01:29.440 --> 01:34.180
So in our the game function

15
01:38.570 --> 01:48.950
we're going to before setting up the board when you clear the screen.

16
01:49.570 --> 01:54.940
And we're going to set the player 1 player type to be human.

17
01:55.070 --> 01:57.900
So that will be us.

18
01:58.380 --> 02:12.590
The human hand red shoes the player type for Player 2 and we do that through functions of get player

19
02:12.830 --> 02:13.670
to

20
02:17.340 --> 02:20.070
share of the eye makes sense.

21
02:22.320 --> 02:27.100
OK that's function in we're going to define this function here.

22
02:27.110 --> 02:35.790
So you said it here somewhere cleared up here.

23
02:35.880 --> 02:39.770
It's all that.

24
02:39.960 --> 02:44.630
So it's going to turn to player type.

25
02:44.680 --> 02:45.960
No arguments.

26
02:47.960 --> 03:07.370
Copy it's in and we don't here you will find it so we're going to say Konst it's valid inputs to make

27
03:07.370 --> 03:13.970
use of our function that we made or.

28
03:14.250 --> 03:18.910
And you do this a different way but we can't do it.

29
03:18.960 --> 03:23.940
So get integer.

30
03:24.600 --> 03:29.890
Who would you like to play against.

31
03:33.950 --> 03:38.590
It's put in a new line and one is human.

32
03:38.600 --> 03:43.310
New line two is AI

33
03:45.870 --> 03:47.730
some more new nuance.

34
03:47.740 --> 03:50.290
What is your choice.

35
03:54.840 --> 03:55.440
So

36
03:57.960 --> 04:01.080
A.C. input it's here.

37
04:05.590 --> 04:10.200
Screen it's two

38
04:14.470 --> 04:16.240
and we're going to

39
04:20.740 --> 04:31.930
basically want to check to see if the input is equal to 1 turn.

40
04:32.050 --> 04:35.350
Human else

41
04:38.060 --> 04:38.610
turn

42
04:46.910 --> 04:50.140
so that's all that's going to do.

43
04:50.200 --> 04:56.160
Now we have to do some changes in the play game function.

44
04:56.750 --> 05:05.580
So here really we don't want to draw boards

45
05:08.680 --> 05:12.200
if it's an AI OK.

46
05:12.310 --> 05:17.820
So here I'm just going to make the change if the current player

47
05:22.790 --> 05:23.790
is player.

48
05:23.800 --> 05:24.260
Ty

49
05:27.460 --> 05:33.950
is human.

50
05:34.090 --> 05:36.990
Then you can draw Bortz.

51
05:39.300 --> 05:46.490
And only then and here we won't want to get the yes right.

52
05:46.510 --> 05:54.870
So if if he's in there I say so here we're going to say

53
05:57.980 --> 06:00.920
if current here

54
06:03.730 --> 06:07.810
is player type is the human

55
06:11.810 --> 06:20.350
then we will do this.

56
06:20.460 --> 06:28.980
Otherwise we're going to have to get a guess somehow from the AI.

57
06:29.150 --> 06:40.810
So you just get a I guess current player.

58
06:41.580 --> 06:45.420
So let's define the

59
06:48.510 --> 06:54.890
let's define the get a I guess it's Cup.

60
06:55.010 --> 06:56.120
Yes.

61
06:58.800 --> 06:59.980
And here

62
07:03.100 --> 07:06.010
this would be a position right.

63
07:08.790 --> 07:10.080
Yeah.

64
07:19.010 --> 07:19.840
In

65
07:22.980 --> 07:24.970
there

66
07:31.150 --> 07:32.870
is a case

67
07:38.310 --> 07:40.370
in way down here.

68
07:40.400 --> 07:41.660
We will implement

69
07:46.070 --> 07:56.300
so we say ship is action I guess in

70
08:00.600 --> 08:06.050
really all we want to do is get a random position.

71
08:06.180 --> 08:19.100
So essentially you'll need the rand function is say guess RHO is right and

72
08:23.230 --> 08:28.560
percent Portes it's right same the call

73
08:33.980 --> 08:42.500
or side solve this and turn the gas.

74
08:42.920 --> 08:45.340
So we need to include it.

75
08:48.000 --> 08:54.780
So and to include it and we need to see that as well so we need to include

76
08:58.200 --> 09:06.030
see lib and we need to include seedtime

77
09:10.470 --> 09:15.120
like so now in Maine

78
09:17.690 --> 09:20.390
is here.

79
09:21.810 --> 09:30.590
We should first thing we should do is see there and I'm number airier seed Rande time no.

80
09:36.810 --> 09:46.850
And now we can actually use it so that we actually get the guests properly.

81
09:46.870 --> 09:55.650
So now back in the game function I'm going to add whenever I want any output for the AI so I'm going

82
09:55.650 --> 10:01.450
to add here current player clear type

83
10:04.150 --> 10:08.080
P-T human then you can display this right.

84
10:09.130 --> 10:13.210
And down here

85
10:18.870 --> 10:27.760
so after update orders and the drop boards.

86
10:27.780 --> 10:37.440
So we want only want to see the current player or current player if he's a human.

87
10:37.620 --> 10:47.960
If the current where player type PTZ I say

88
10:51.540 --> 10:52.290
else

89
10:59.580 --> 11:00.410
this.

90
11:00.420 --> 11:10.790
So in this case we want to draw the board of the other player because if the once the player player

91
11:10.790 --> 11:15.030
makes a guess we want to see what happens to our board.

92
11:16.170 --> 11:17.960
In this case were the other point.

93
11:18.030 --> 11:18.470
So

94
11:21.560 --> 11:27.130
that's an see how much.

95
11:27.420 --> 11:30.490
And we also want to see what they chose as well.

96
11:32.140 --> 11:32.570
All right.

97
11:32.710 --> 11:33.330
Where

98
11:36.710 --> 11:42.700
we're name he chose rho

99
11:46.490 --> 11:52.140
and in and cast this to be character

100
11:55.670 --> 11:59.380
cast row.

101
11:59.580 --> 12:04.700
So I didn't really go over casting too much in this course because usually not a good idea.

102
12:04.710 --> 12:06.870
But in this case this is fine.

103
12:07.240 --> 12:13.790
Really this will just kind of change its type to be a character instead of what this really would be

104
12:13.800 --> 12:20.440
which is an integer just so it outputs as a character.

105
12:20.470 --> 12:20.940
OK.

106
12:21.000 --> 12:23.540
And that's one we can cast cast things

107
12:27.200 --> 12:31.730
and call them yes.

108
12:39.030 --> 12:39.240
And

109
12:42.320 --> 12:50.100
so now in here again science is a lie.

110
12:50.120 --> 12:53.030
If the current church where

111
12:57.610 --> 12:58.020
type

112
13:07.680 --> 13:13.310
so.

113
13:13.780 --> 13:27.370
So if if the current player is an AI A We want to say that's essentially the I think you're something

114
13:27.910 --> 13:28.430
right.

115
13:30.130 --> 13:40.260
So in this case you want to say see Ouch.

116
13:40.850 --> 13:46.180
Current player which which knows Nay I mean

117
13:48.740 --> 13:52.090
sunk your

118
13:54.770 --> 14:00.310
get Neme ship type

119
14:03.450 --> 14:18.420
type.

120
14:19.020 --> 14:19.920
Yes.

121
14:20.280 --> 14:26.110
I think there there's any other changes we need to do really.

122
14:26.190 --> 14:27.630
Actually there is one.

123
14:27.660 --> 14:41.250
So the one we need to do is actually laying out a I's ships.

124
14:41.310 --> 14:47.790
So in our set up forward here

125
14:53.080 --> 15:06.610
instead we need to call different function for the.

126
15:06.770 --> 15:21.440
So if so we're just going to say clipboards and we're going to say if the player does we're type is

127
15:21.450 --> 15:30.080
equal to PTA II then we're going to do something special for him.

128
15:30.390 --> 15:31.950
Set up a Bortz

129
15:34.580 --> 15:35.300
of the player

130
15:38.360 --> 15:41.570
and return.

131
15:41.840 --> 15:50.780
So instead of actually going through all this and asking the high rate which is silly right AI does

132
15:50.780 --> 15:52.150
need to improve.

133
15:52.710 --> 16:02.280
OK so we're actually going to make this function.

134
16:02.820 --> 16:10.300
It's nothing is cheek by reference here.

135
16:13.080 --> 16:19.520
Here you find it.

136
16:19.630 --> 16:26.320
And so we're going to need a ship position

137
16:28.750 --> 16:33.250
shin shoot or teach in

138
16:38.360 --> 16:41.750
K and we're going to loop through

139
16:46.390 --> 16:51.340
all the ships just like we did with the human players version

140
17:14.240 --> 17:24.240
and basically what we're going to do is do another live here and we're going to randomize getting position

141
17:24.270 --> 17:25.090
again.

142
17:26.150 --> 17:41.200
And so in fact we should probably see this say ship station type.

143
17:47.480 --> 18:00.590
Turn the gas and then we're just going to instead of all this churn get it done session this way.

144
18:00.670 --> 18:08.940
So here we're going to say this mission is get random position

145
18:12.590 --> 18:14.210
and the orientation

146
18:16.340 --> 18:21.140
is in order to cast this

147
18:27.160 --> 18:30.850
and it's going to be around and modulus to

148
18:33.700 --> 18:44.440
there's only two values rates here and one.

149
18:44.620 --> 18:45.970
And while

150
18:49.030 --> 18:54.870
not is valid placement we're still using this function

151
19:04.770 --> 19:08.810
and then we're still using the police ship report as well.

152
19:24.160 --> 19:26.290
So that should be it.

153
19:26.320 --> 19:31.950
I think I don't think there's any other changes really really need to make.

154
19:33.190 --> 19:36.410
So let's run this and see what happens.

155
19:37.980 --> 19:42.340
So who would you like to play with against the I.

156
19:42.660 --> 20:04.530
So again that set up a ship a one just very simply inch one on all the longtail g one horizontal

157
20:09.730 --> 20:12.430
yea.

158
20:12.460 --> 20:14.320
So what's my guess.

159
20:16.320 --> 20:20.220
A one miss.

160
20:20.760 --> 20:25.780
He chose I wrote my column.

161
20:26.350 --> 20:29.080
I was a miss for him.

162
20:29.280 --> 20:29.880
Be

163
20:33.000 --> 20:41.100
for Miss chose F in column five.

164
20:41.210 --> 20:44.480
That's Miss de

165
20:47.400 --> 20:51.110
C9 MS..

166
20:51.500 --> 20:53.830
So he actually hit me.

167
20:53.840 --> 20:54.910
So there you go.

168
20:55.100 --> 20:56.680
So you can actually hit.

169
20:56.960 --> 20:57.880
He's not very smart.

170
20:57.880 --> 20:59.740
He just kind of randomly chooses.

171
20:59.750 --> 21:01.980
But it's better than nothing right.

172
21:02.420 --> 21:09.060
So this really should conclude the Battleship game.

173
21:09.560 --> 21:14.570
And if you want you can actually try to make a smarter AI.

174
21:14.690 --> 21:20.380
If you if you're so inclined and try to see what you can come up with.

175
21:20.930 --> 21:24.640
Otherwise I will see you in the next section.