Hey, I've got a code that calculates the amount of unique moves in a game of naughts & crosses but I was trying to change it to use an array of flags so that everytime a unique position comes up, it gets set to true. Problem is I don't really know how. I want to just have something like
1 2 3 4 5 6 7
bool flag[1000] = {false}
if(flag[bd] == false) //if its a unique position
{
flag[bd] = true;
}
But using the position of the board gives errors so I'm stuck. Any help?
a) I'm not sure {false} sets all values to false, or just the first... You should test it.
b) How is 'bd' defined? In your example [which is probably just a small snippet, thus incomplete] it's not initialized, which in some compilers (like MSVC++ Express) means it has a very large negative value, making it an illegal index.
Yeah I tested it and it seems to work. I defined bd as int bd[3][3];
I changed the code and now it runs but it comes out as 100 odd less than what it should, not sure if you can help without the full code but heres the function anyway:
1 2 3 4 5 6 7 8 9 10 11 12 13 14
int search(position p) {
int i = board(p.bd);
if(flag[i] == true) //if its not unique
{
return 1;
}
if(flag[i] == false) //if its a unique position
{
flag[i] = true;
return 0;
}