more tic tac toe

Started by
30 comments, last by alvaro 11 years, 6 months ago

I have tried fisherYates shuffle but it still does not work.here is my code
void Computer::move_player_O()
{
srand(time(NULL));
const int length=10;
int array[length];
for(int t=1;t<=9;t++)
array[t]=t;
fisherYates(array,length);
player_O=array[t];
t++;
}
void Computer::check_player_O()
{
board[player_O]='O';
}


int array[length]; this will not work try

int *array=new int[length];

and after you have done working

delete[] array;
Advertisement

[quote name='phil67rpg' timestamp='1350866639' post='4992635']
I have tried fisherYates shuffle but it still does not work.here is my code
[...]
const int length=10;
int array[length];
[...]


int array[length]; this will not work try[/quote]

Why wouldn't it work? `length' is a compile-time constant and using it as an array length is perfectly kosher.

int *array=new int[length];

and after you have done working

delete[] array;
[/quote]
You only need to do that if `length' is not known at compile time. Even in that case, some compilers (e.g., gcc) do support variable-length arrays. VLAs are part of the C99 standard and they almost made it to the C++11 standard.

This topic is closed to new replies.

Advertisement