0:00
Hello.
00:01
For programming exercise 11 .9, you are essentially asked to write a program that plays tic tactoe.
00:11
So i decided to write a couple of functions here that will help.
00:17
But the very first thing that i decided to do was to initialize the game board.
00:23
So for my game board, i'm using a three by three matrix.
00:28
And it starts off with just a empty space in all of these spaces.
00:35
I next wanted to define a function that will draw the game board.
00:41
So that is just draw board.
00:44
We're going to start by printing a line and then for every row in the matrix we want to print a sort of vertical line here.
00:57
Then whatever the matrix is at that position, vertical line, next one, so on and so forth.
01:05
And then underneath we want to, again, print a horizontal line.
01:13
So this should draw our game board and will look pretty similar to the game board in the sample run in the textbook.
01:22
And then next, i decided to define a function that will take a turn for a specific player.
01:29
So i've defined turn of p where p is the player.
01:33
And so the row is going to be the input for player p on enter a row.
01:41
And column will be the input from enter a column.
01:46
And then matrix row of column then should be equal to p.
01:52
So if it's the x player, then it'll be x.
01:54
If it's the o player, it'll be o.
01:58
And turn is also going to return row and columns so that we know where the person recently placed their x or o.
02:11
And then lastly, not lastly, we have a couple of additional ones here.
02:17
So next, i wanted to define a function that would essentially play the game.
02:22
So define tick -tac -toe.
02:24
We start by drawing the board.
02:27
Player x goes first, so i set p equal to x.
02:31
And i have a win condition.
02:35
So i want to keep playing as long as no one has won.
02:39
And as soon as someone wins, the game should end.
02:42
So i'm going to start by stating that win is equal to false because no one has won.
02:48
While win remains false, ij, so row column should be equal to turn of p, so the player's turn.
02:59
We're going to draw the board again so we can see the updated board, and then we need to check whether or not the player won.
03:07
So i needed to define one more function here is win.
03:15
So for is win, what i decided to do is to check, and then this is very similar to sudoku...