Saturday, April 26, 2008

8 Puzzle Code - TreeNode.h

First of all, we create a TreeNode class for storing puzzle state. Below is the code store in TreeNode.h.

#ifndef _TREENODE_H
#define _TREENODE_H

#define SIZE 9
class TreeNode{
public:
UINT fn, gn, hn; //For A* algorithm use.
UINT h; //Heuristic value.
char state[SIZE]; //Current puzzle state.

TreeNode* parent;
TreeNode* child1;
TreeNode* child2;
TreeNode* child3;
TreeNode* child4;

TreeNode(){
parent=NULL;
child1=NULL;
child2=NULL;
child3=NULL;
child4=NULL;
}

void setState(char *p){
for(int v=0; v<SIZE; v++) state[v]=*(p+v);
}
};
#endif

No comments: