vendredi 13 mars 2015

children of pointer pointing to Node are always NULL C++


I`m creating a game with AI using recursive calling , i have a struct called "Node" , when filling them with new int[5][5] they are filled but when i return and call other function like when i call a fun called "bestMove" to loop within children THEY are all pointing to NULL , for an example



struct Node
{
int state[5][5];
if(root)//parent = null;
else
parent = root;child[i] = null;//after looping
}

void fill_new_state(Node* childPointer)
{
if(everything is Ok) //and its Okay
childPointer = new Node();//with linking to parent and all...
childPointer->state[row][col] = bla bla bla//fill
return;}

void expandChildern(Node* root)
{
fill_new_state(root->child[i])//looping
}

void bestMove(Node* root)
{
Node* best = root->child[0] //if not null and it is not null
//loop and chose the best
root = best
}

void main()
{
struct root = new Node();
expandChildren(root);
bestMove(root);
}


in the function fill_new_state(Node* childPointer) the child is filled and its not NULL but after returning fromfill_new_state(Node* childPointer)exactly in the functionexpandChildren(Node* root)` the child is NULLed




Aucun commentaire:

Enregistrer un commentaire