Help with random command.
Apr 4, 2014 at 3:11am UTC
Hello everyone, im doing this tic tac toe program for my class... it is done, but the last requisite is that the first move must be define randomly, and i dunno how to do it... i know i need rand command, but i dont have an idea how to implement in the code..
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
for (y=0; y<3; y++){
a[y]=0;
}
cout <<"Player 1: " ;
cin >>jug1;
cout <<"Player 2: " ;
cin >>jug2;
cout <<endl<<endl<<jug1<<". X" <<endl;
cout <<jug2<<". O" <<endl<<endl;
cout <<"| 1 | 2 | 3 |" << endl;
cout <<"-------------" << endl;
cout <<"| 4 | 5 | 6 |" << endl;
cout <<"-------------" << endl;
cout <<"| 7 | 8 | 9 |" << endl<< endl ;
cout <<"Choose a number." <<endl<<endl;
for (x=0; x<3; x++){
for (y=0; y<3; y++){
matriz[x][y]=' ' ;
}
thanks, any help will be so much appreciated
Apr 4, 2014 at 2:06pm UTC
Apr 4, 2014 at 7:54pm UTC
well, noy really... i just need the random number to define which player will make the first move... =S
Apr 4, 2014 at 8:16pm UTC
All the information you need is in the link
mutexe provided.
You just have to think about how to use it.
1 2 3 4 5
int first_player;
srand(time(NULL); // Randomize the the seed
first_player = rand() % 2 + 1; // Will result in 1 or 2
Topic archived. No new replies allowed.