Software Development and Programming Careers (Official Discussion Thread)

levitate

I love you, you know.
Joined
Sep 3, 2015
Messages
38,922
Reputation
5,722
Daps
147,619
Reppin
The Multiverse
Reached the first milestone project on my Udemy Python course....


...a tictactoe game.
:yeshrug:
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...
 

Obreh Winfrey

Truly Brehthtaking
Supporter
Joined
Nov 18, 2016
Messages
20,851
Reputation
25,252
Daps
131,928
Reached the first milestone project on my Udemy Python course....


...a tictactoe game.
:yeshrug:
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...
Have you done any programming before this?
 

DJSmooth

Superstar
Joined
Oct 22, 2015
Messages
3,914
Reputation
1,199
Daps
23,482
Reached the first milestone project on my Udemy Python course....


...a tictactoe game.
:yeshrug:
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...

Use a 2D boolean array instead.

[
[false,true,false],
[false,true,false],
[false,true,false]
]
 

Obreh Winfrey

Truly Brehthtaking
Supporter
Joined
Nov 18, 2016
Messages
20,851
Reputation
25,252
Daps
131,928
:patrice: I should have thought about that. Good catch.

Maybe a 2D array and use int 0-2; 0 for blank space and 1 and 2 for X and O?

[
[0,1,0],
[0,1,0],
[0,2,0]
]
Certainly an option. What would be your plan to translate from 0-2 to Xs and Os when printing out the game board?
 

DJSmooth

Superstar
Joined
Oct 22, 2015
Messages
3,914
Reputation
1,199
Daps
23,482
Certainly an option. What would be your plan to translate from 0-2 to Xs and Os when printing out the game board?

two for loops then if else statements to check if X or O

for(row)
for(column)
if(array[row][column] == 1){
string+= ' X';
} else if(2){

} else {

}
}

or could just save String in the 2D array depends.
 

Obreh Winfrey

Truly Brehthtaking
Supporter
Joined
Nov 18, 2016
Messages
20,851
Reputation
25,252
Daps
131,928
two for loops then if else statements to check if X or O

for(row)
for(column)
if(array[row][column] == 1){
string+= ' X';
} else if(2){

} else {

}
}

or could just save String in the 2D array depends.
Interesting :jbhmmdup:. But is that necessary with how Python prints arrays?
 
Top