Hi guys, Im doing a tic-tac-toe game in C for my college project, the game is played by a person called Player1 and the computer called Computer, the person introduces the coordinates to produce its play, but the computer generates this coordinates with a random function in each coordinate (LINE and COLUMN, its an array).
Now, this functions always repeat the same number, for example: 11, 00, 22. But i want it to be able to play 10, 12, 21, 20, etc. Can you guys take a look at the code of the random function to see whats happening?
int computerLine( int mainBoard[3][3], int x)
{
int x1 = 0;
srand((unsigned)time(0));
{
x1 = rand() % 3;
}
return x1;
}
int computerColumn( int mainBoard[3][3], int y)
{
int y1 = 0;
srand((unsigned)time(0));
{
y1 = rand() % 3;
}
return y1;
}
Thanks Guys
EDIT: I want it to create completely random integers from 0 to 3 excluding this last one.
Question
.Dan
Hi guys, Im doing a tic-tac-toe game in C for my college project, the game is played by a person called Player1 and the computer called Computer, the person introduces the coordinates to produce its play, but the computer generates this coordinates with a random function in each coordinate (LINE and COLUMN, its an array).
Now, this functions always repeat the same number, for example: 11, 00, 22. But i want it to be able to play 10, 12, 21, 20, etc. Can you guys take a look at the code of the random function to see whats happening?
int computerLine( int mainBoard[3][3], int x) { int x1 = 0; srand((unsigned)time(0)); { x1 = rand() % 3; } return x1; } int computerColumn( int mainBoard[3][3], int y) { int y1 = 0; srand((unsigned)time(0)); { y1 = rand() % 3; } return y1; }Thanks Guys
EDIT: I want it to create completely random integers from 0 to 3 excluding this last one.
Edited by .DanLink to comment
Share on other sites
3 answers to this question
Recommended Posts