Freedman
Choppers For Karate Nggas
Never coded in python but from what I can tell list seem similar to arrays so I'd go with the multi dimensional array suggestion above and set it up with all values of 0 and change the values for Xs and Os.Reached the first milestone project on my Udemy Python course....
...a tictactoe game.
Thinking of setting up the board as a series of three lists, like this...(I don't know how to set up a matrix yet)
[1,2,3]
[4,5,6]
[7,8,9]
Then creating a function / loop that asks the Player where they'd ike to place their X (player 1), or O (player 2).
Then add logic that checks if there are three X/O's aligned and have that player win the game.
Will report back and post the code here later...
// initial board
list =[ [ 0, 0, 0],
[0, 0, 0],
[0,0,0] ]
int x = 1;
int o = 2;
// player 1 puts an x
list[0][0] = x;
// player 2 puts an o
list[2][2] = o;
// player 1
list[0][1] = x;
// player 2
list[2][1] = o;
board should then look like this
[ [1, 1, 0] ,
[0, 0 , 0] ,
[0, 2, 2] ]
Not sure if this is like something for the console or Like with actual squares on the screen so you need to work on the function to actually place the X/O and change the value and the function to check if anybody has won. Probably could use nested for loops for the last part to check the whole board
Last edited: