P1 vs Computer

Hello guyz. I have done my first project about TicTacToe seample game, but now I want to add some new function witch allows u to play vs computer. Now in my project 2 player can play againts each other but I want P1 vs Computer. I have found some information but want alghorithm about this.

thank you
This is a learning site, show us what you think should work and maybe we can think of a way to make it better.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
char square[10] = {'0','1','2','3','4','5','6','7','8','9'};
char player = 'X';

void fun(){
	
	if(square[1] == 'X'){
		square[4] || square[5] || square[2] == 'O';
	}
	else if(square[2] == 'X'){
		square[1] || square[4] || square[5] || square[6] || square[3] == 'O';
	}
	else if(square[3] == 'X'){
		square[2] || square[5] || square[6] == 'O';
	}
	else if(square[4] == 'X'){
		square[7] || square[8] || square[5] || square[2] || square[1] == 'O';
	}
	else if(square[5] == 'X'){
		square[1] || square[4] || square[7] || square[8] || square[9] || square[6] || square[3] || square[2] == 'O';
	}
	else if(square[6] == 'X'){
		square[3] || square[2] || square[5] || square[8] || square[9] == 'O';
	}
	else if(square[7] == 'X'){
		square[8] || square[5] || square[4] == 'O';
	}
	else if(square[8] == 'X'){
		square[7] || square[4] || square[5] || square[6] || square[9] == 'O';
	}
	else if(square[9] == 'X'){
		square[8] || square[5] || square [6] == 'O';
	}
}


I have this code and need to use with random and dont know how
I am not sure where you got that code from, but while it looks like c++, I don't think it is. That is to say it is wrong in nearly every possible way.

First, a tic tac toe board has only 9 possible spaces, so an array of 10 makes no sense. Next, there is a function called fun. Is it meant to modify the array? You will need to pass your array into you function, but it takes no arguments. Finally, those if statements!! What are they meant to do exactly? It looks like maybe assign a space to 'o' but they use not the assign operator but the ==?

I suggest starting over from scratch...
Topic archived. No new replies allowed.