Hi, I am writing a program to solve the 8puzzle, but for some reason i am having more difficulty with the structure than the algorithm....
I have two classes, a tree and node class.
My main problem is to put the nodes in an array in the tree class.
Second, which is the one om having problems now, my "move" function in my Node class is giving me a seg fault if i create a int? it is also changing values of my root state?
Can someone please give me any idea where i am going wrong?
Thanks!
//inside my tree class
void Tree::addNode(int x)
{
Node child;
child = root.move(x);
//Here i actually want to add the child to my Node *nodes[] btut dont know how...
}
//inside my node class
Node Node::move(int nxt_blck)
{
//x = nxt_blck; //if i declare this it gives me a sg fault?!?
Node *result;
result->setState(state);
//the nxt_blck changes value here (to zero) and i dont know why...
result->setParent(this);
/* Swap hole and other piece. */
result->state[zero] = state[nxt_blck];
result->setZero(nxt_blck);
result->state[nxt_blck] = state[zero];
return *result;
}