<?xml version='1.0' encoding='UTF-8'?><?xml-stylesheet href="http://www.blogger.com/styles/atom.css" type="text/css"?><feed xmlns='http://www.w3.org/2005/Atom' xmlns:openSearch='http://a9.com/-/spec/opensearchrss/1.0/' xmlns:georss='http://www.georss.org/georss' xmlns:gd='http://schemas.google.com/g/2005' xmlns:thr='http://purl.org/syndication/thread/1.0'><id>tag:blogger.com,1999:blog-5758484518227245221</id><updated>2012-02-16T07:14:43.836-08:00</updated><category term='8 Puzzle Code - Queue.h'/><category term='8 Puzzle Code - LinkQueue.h'/><category term='8 Puzzle Code - StateNode.h'/><category term='8 Puzzle Code - Tree.h'/><category term='8 Puzzle Code - Queue.cpp'/><category term='8 Puzzle Code - LinkStack.h'/><category term='8 Puzzle Code - ReadMe.txt'/><category term='8 Puzzle Code - TreeNode.h'/><title type='text'>8 Puzzle Code Example Share</title><subtitle type='html'>CORE SOURCE CODE solving 8 Puzzle AI problems written in MS Visual MFC C++.
&lt;br&gt;&lt;br&gt;
&lt;b&gt;COMPLETE Full set of working SOURCE CODE&lt;/b&gt; for the working MFC C++ program, &lt;b&gt;SPEED UP your learning process&lt;/b&gt;, 
&lt;br&gt;
just &lt;b&gt;4.99 USD&lt;/b&gt;. Email / Paypal to &lt;a href="mailto:ahyeek@gmail.com"&gt;&lt;b&gt;ahyeek@gmail.com&lt;/b&gt;&lt;/a&gt;
&lt;br&gt;&lt;br&gt;
Full working program can be downloaded to TRY out: &lt;a href="http://silyeek-tech.blogspot.com/2006/03/ai-8-puzzle-8-puzzle-solver.html"&gt;&lt;b&gt;AI 8-puzzle (8 Puzzle) solver&lt;/b&gt;&lt;/a&gt;</subtitle><link rel='http://schemas.google.com/g/2005#feed' type='application/atom+xml' href='http://8-puzzle.blogspot.com/feeds/posts/default'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5758484518227245221/posts/default?max-results=100'/><link rel='alternate' type='text/html' href='http://8-puzzle.blogspot.com/'/><link rel='hub' href='http://pubsubhubbub.appspot.com/'/><author><name>Ahyeek</name><uri>http://www.blogger.com/profile/06695600039671648941</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='33' height='26' src='http://www.geocities.com/ahyeek/Smaller-Office.jpg'/></author><generator version='7.00' uri='http://www.blogger.com'>Blogger</generator><openSearch:totalResults>9</openSearch:totalResults><openSearch:startIndex>1</openSearch:startIndex><openSearch:itemsPerPage>100</openSearch:itemsPerPage><entry><id>tag:blogger.com,1999:blog-5758484518227245221.post-3923112959755136436</id><published>2009-10-22T01:55:00.000-07:00</published><updated>2009-10-22T01:57:59.164-07:00</updated><title type='text'>Full working source code in C# WPF Version of 8 Puzzle Solver</title><content type='html'>&lt;span style="font-weight:bold;"&gt;Full working source code in C# WPF Version of 8 Puzzle now also available! &lt;/span&gt;&lt;br /&gt;Paypal &lt;span style="font-weight:bold;"&gt;4.99usd &lt;/span&gt;to ahyeek@gmail.com to get the package.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5758484518227245221-3923112959755136436?l=8-puzzle.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://8-puzzle.blogspot.com/feeds/3923112959755136436/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=5758484518227245221&amp;postID=3923112959755136436' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5758484518227245221/posts/default/3923112959755136436'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5758484518227245221/posts/default/3923112959755136436'/><link rel='alternate' type='text/html' href='http://8-puzzle.blogspot.com/2009/10/full-working-source-code-in-c-wpf.html' title='Full working source code in C# WPF Version of 8 Puzzle Solver'/><author><name>Ahyeek</name><uri>http://www.blogger.com/profile/06695600039671648941</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='33' height='26' src='http://www.geocities.com/ahyeek/Smaller-Office.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5758484518227245221.post-6589156021159583536</id><published>2008-05-09T06:47:00.004-07:00</published><updated>2008-05-09T06:48:04.459-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='8 Puzzle Code - TreeNode.h'/><title type='text'>8 Puzzle Code - TreeNode.h</title><content type='html'>First of all, we create a TreeNode class for storing puzzle state. Below is the code store in &lt;span style="font-weight: bold;"&gt;TreeNode.h&lt;/span&gt;.&lt;br /&gt;&lt;p  style="font-family:courier new;"&gt;&lt;span style="font-size:85%;"&gt;#ifndef _TREENODE_H&lt;br /&gt;#define _TREENODE_H&lt;br /&gt;&lt;br /&gt;#define SIZE 9&lt;br /&gt;class TreeNode{&lt;br /&gt;public:&lt;br /&gt; UINT fn, gn, hn;     //For A* algorithm use.&lt;br /&gt; UINT h;              //Heuristic value.&lt;br /&gt; char state[SIZE];    //Current puzzle state.&lt;br /&gt;&lt;br /&gt; TreeNode* parent;&lt;br /&gt; TreeNode* child1;&lt;br /&gt; TreeNode* child2;&lt;br /&gt; TreeNode* child3;&lt;br /&gt; TreeNode* child4;&lt;br /&gt;&lt;br /&gt; TreeNode(){&lt;br /&gt;     parent=NULL;&lt;br /&gt;     child1=NULL;&lt;br /&gt;     child2=NULL;&lt;br /&gt;     child3=NULL;&lt;br /&gt;     child4=NULL;&lt;br /&gt; }&lt;br /&gt;&lt;br /&gt; void setState(char *p){&lt;br /&gt;     for(int v=0; v&amp;lt;SIZE; v++) state[v]=*(p+v);&lt;br /&gt; }&lt;br /&gt;};&lt;br /&gt;#endif&lt;/span&gt;&lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5758484518227245221-6589156021159583536?l=8-puzzle.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://8-puzzle.blogspot.com/feeds/6589156021159583536/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=5758484518227245221&amp;postID=6589156021159583536' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5758484518227245221/posts/default/6589156021159583536'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5758484518227245221/posts/default/6589156021159583536'/><link rel='alternate' type='text/html' href='http://8-puzzle.blogspot.com/2008/05/8-puzzle-code-treenodeh.html' title='8 Puzzle Code - TreeNode.h'/><author><name>Ahyeek</name><uri>http://www.blogger.com/profile/06695600039671648941</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='33' height='26' src='http://www.geocities.com/ahyeek/Smaller-Office.jpg'/></author><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5758484518227245221.post-8736584103481832078</id><published>2008-05-09T06:47:00.003-07:00</published><updated>2008-05-09T06:47:44.758-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='8 Puzzle Code - Tree.h'/><title type='text'>8 Puzzle Code - Tree.h</title><content type='html'>Tree node processing methods code:&lt;br /&gt;&lt;p  style="font-family:courier new;"&gt;&lt;span style="font-size:85%;"&gt;#include "TreeNode.h"&lt;br /&gt;#include "LinkQueue.h"&lt;br /&gt;#include "LinkStack.h"&lt;br /&gt;#define SIZE 9&lt;br /&gt;#define TILESTEPS 1&lt;br /&gt;#define DISTANCE 2&lt;br /&gt;#define MANHATTAN 3&lt;br /&gt;#define ASTAR 4&lt;br /&gt;&lt;br /&gt;class PuzzleTree{&lt;br /&gt;public:&lt;br /&gt;TreeNode* root;&lt;br /&gt;&lt;br /&gt;PuzzleTree(){ root=NULL; }&lt;br /&gt;~PuzzleTree(){&lt;br /&gt; DeleteTree(root);&lt;br /&gt;}&lt;/span&gt;&lt;/p&gt;&lt;p  style="font-family:courier new;"&gt;&lt;span style="font-size:85%;"&gt;void SetTreeRoot(TreeNode* rootnode){&lt;br /&gt;  root=rootnode;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;//Adding in version 2&lt;br /&gt;//The generated state is no duplicated with previous state.&lt;br /&gt;void GenerateNewStateNodeNoDup(TreeNode* currnode){&lt;br /&gt;  int spcpos;&lt;br /&gt;  char *currstate;&lt;br /&gt;  char temp[SIZE];&lt;br /&gt;  currstate=currnode-&amp;gt;state;&lt;br /&gt;  spcpos=getSpacePos(currstate);&lt;br /&gt;  if( (spcpos-3)&amp;gt;=0 ){&lt;br /&gt;      newState(temp, currstate, spcpos, spcpos-3);&lt;br /&gt;      if(currnode-&amp;gt;parent==NULL)&lt;br /&gt;        {addChild(currnode, temp);}&lt;br /&gt;     else{&lt;br /&gt;        if(!isEverSameState(temp, currnode)){ addChild(currnode,temp);}&lt;br /&gt;     }&lt;br /&gt; }&lt;br /&gt;&lt;br /&gt; if( (spcpos-1)&amp;gt;=0 &amp;amp;&amp;amp; (spcpos-1)!=2 &amp;amp;&amp;amp; (spcpos-1)!=5){&lt;br /&gt;   newState(temp, currstate, spcpos, spcpos-1);&lt;br /&gt;   if(currnode-&amp;gt;parent==NULL)&lt;br /&gt;     { addChild(currnode, temp);}&lt;br /&gt;   else{&lt;br /&gt;     if(!isEverSameState(temp, currnode)){ addChild(currnode,temp);}&lt;br /&gt;  }&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;if( (spcpos+3)&amp;lt;SIZE ){&lt;br /&gt;  newState(temp, currstate, spcpos, spcpos+3);&lt;br /&gt;  if(currnode-&amp;gt;parent==NULL){ addChild(currnode, temp);}&lt;br /&gt;  else{&lt;br /&gt;    if(!isEverSameState(temp, currnode)){ addChild(currnode,temp);}&lt;br /&gt; }&lt;br /&gt;}&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;p  style="font-family:courier new;"&gt;&lt;span style="font-size:85%;"&gt;  if( (spcpos+1)&amp;lt;SIZE &amp;amp;&amp;amp; (spcpos+1)!=3 &amp;amp;&amp;amp; (spcpos+1)!=6){&lt;br /&gt;  newState(temp, currstate, spcpos, spcpos+1);&lt;br /&gt;  if(currnode-&amp;gt;parent==NULL){ addChild(currnode, temp);}&lt;br /&gt;  else{&lt;br /&gt;      if(!isEverSameState(temp, currnode)){addChild(currnode,temp); }&lt;br /&gt;  }&lt;br /&gt;}&lt;br /&gt;}//End of Generate New State with no previous duplication.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;void GenerateNewStateNode(TreeNode* currnode){&lt;br /&gt;int spcpos;&lt;br /&gt;char *currstate;&lt;br /&gt;char temp[SIZE];&lt;br /&gt;currstate=currnode-&amp;gt;state;&lt;br /&gt;spcpos=getSpacePos(currstate);&lt;br /&gt;if( (spcpos-3)&amp;gt;=0 ){&lt;br /&gt;   newState(temp, currstate, spcpos, spcpos-3);&lt;br /&gt;   if(currnode-&amp;gt;parent==NULL){addChild(currnode, temp);}&lt;br /&gt;  else{&lt;br /&gt;     if(!isSameState(temp, currnode-&amp;gt;parent-&amp;gt;state)){addChild(currnode,temp);}&lt;br /&gt;  }&lt;br /&gt;}&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;p  style="font-family:courier new;"&gt;&lt;span style="font-size:85%;"&gt;  if( (spcpos-1)&amp;gt;=0 &amp;amp;&amp;amp; (spcpos-1)!=2 &amp;amp;&amp;amp; (spcpos-1)!=5){&lt;br /&gt;   newState(temp, currstate, spcpos, spcpos-1);&lt;br /&gt;   if(currnode-&amp;gt;parent==NULL){addChild(currnode, temp);}&lt;br /&gt;  else{&lt;br /&gt;     if(!isSameState(temp, currnode-&amp;gt;parent-&amp;gt;state)){addChild(currnode,temp);}&lt;br /&gt;  }&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;  if( (spcpos+3)&amp;lt;SIZE ){&lt;br /&gt;      newState(temp, currstate, spcpos, spcpos+3);&lt;br /&gt;      if(currnode-&amp;gt;parent==NULL){ addChild(currnode, temp);}&lt;br /&gt;      else{&lt;br /&gt;          if(!isSameState(temp, currnode-&amp;gt;parent-&amp;gt;state)){ addChild(currnode,temp);}&lt;br /&gt;      }&lt;br /&gt;  }&lt;br /&gt;&lt;br /&gt;if( (spcpos+1)&amp;lt;SIZE &amp;amp;&amp;amp; (spcpos+1)!=3 &amp;amp;&amp;amp; (spcpos+1)!=6){&lt;br /&gt;newState(temp, currstate, spcpos, spcpos+1);&lt;br /&gt;if(currnode-&amp;gt;parent==NULL){ addChild(currnode, temp);}&lt;br /&gt;else{&lt;br /&gt;if(!isSameState(temp, currnode-&amp;gt;parent-&amp;gt;state)){addChild(currnode,temp);}&lt;br /&gt;}&lt;br /&gt;}&lt;br /&gt;}//End Generate New State procedure.&lt;br /&gt;&lt;br /&gt;void BackTrackTree(TreeNode* thisnode, LinkStack* s){&lt;br /&gt;TreeNode* curr;&lt;br /&gt;curr=thisnode;&lt;br /&gt;while(curr!=NULL){&lt;br /&gt;s-&amp;gt;push(curr);&lt;br /&gt;curr=curr-&amp;gt;parent;&lt;br /&gt;}&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;void ExposeNextState(TreeNode* currnode, LinkQueue* q){&lt;br /&gt;if(currnode-&amp;gt;child1!=NULL) q-&amp;gt;add(currnode-&amp;gt;child1);&lt;br /&gt;if(currnode-&amp;gt;child2!=NULL) q-&amp;gt;add(currnode-&amp;gt;child2);&lt;br /&gt;if(currnode-&amp;gt;child3!=NULL) q-&amp;gt;add(currnode-&amp;gt;child3);&lt;br /&gt;if(currnode-&amp;gt;child4!=NULL) q-&amp;gt;add(currnode-&amp;gt;child4);&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;//Add in version 3.&lt;br /&gt;//Calculate tree node heuristic value and add to q with sorted manner.&lt;br /&gt;//Sort manner will perform multi level expanding tree according to&lt;br /&gt;//good heuristic value node be expanded first.&lt;br /&gt;void ExposeNextStateHeuristic(TreeNode* currnode, LinkQueue* q, int htype){&lt;br /&gt;if(currnode-&amp;gt;child1!=NULL) {&lt;br /&gt;GetHeuristicValue(currnode-&amp;gt;child1,htype);&lt;br /&gt;q-&amp;gt;addHeuristic(currnode-&amp;gt;child1, htype);&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;if(currnode-&amp;gt;child2!=NULL) {&lt;br /&gt;GetHeuristicValue(currnode-&amp;gt;child2,htype);&lt;br /&gt;q-&amp;gt;addHeuristic(currnode-&amp;gt;child2, htype);&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;if(currnode-&amp;gt;child3!=NULL) {&lt;br /&gt;GetHeuristicValue(currnode-&amp;gt;child3,htype);&lt;br /&gt;q-&amp;gt;addHeuristic(currnode-&amp;gt;child3, htype);&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;if(currnode-&amp;gt;child4!=NULL) {&lt;br /&gt;GetHeuristicValue(currnode-&amp;gt;child4,htype);&lt;br /&gt;q-&amp;gt;addHeuristic(currnode-&amp;gt;child4, htype);&lt;br /&gt;}&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;void reset(){&lt;br /&gt;if(root==NULL) return;&lt;br /&gt;DeleteTree(root);&lt;br /&gt;root=NULL;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;void DeleteTree(TreeNode* root){&lt;br /&gt;if(root==NULL) return;&lt;br /&gt;DeleteTree(root-&amp;gt;child1);&lt;br /&gt;DeleteTree(root-&amp;gt;child2);&lt;br /&gt;DeleteTree(root-&amp;gt;child3);&lt;br /&gt;DeleteTree(root-&amp;gt;child4);&lt;br /&gt;delete root;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;UINT GetCharValue(char c){&lt;br /&gt;UINT ch;&lt;br /&gt;ch=0;&lt;br /&gt;switch(c){&lt;br /&gt;case '1': ch=1; break;&lt;br /&gt;case '2': ch=2; break;&lt;br /&gt;case '3': ch=3; break;&lt;br /&gt;case '4': ch=4; break;&lt;br /&gt;case '5': ch=5; break;&lt;br /&gt;case '6': ch=6; break;&lt;br /&gt;case '7': ch=7; break;&lt;br /&gt;case '8': ch=8; break;&lt;br /&gt;case '#': ch=9; break&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;return ch;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;//Other usage function.&lt;br /&gt;void GetHeuristicValue(TreeNode* anode, int type){&lt;br /&gt;UINT hvalue;&lt;br /&gt;int v;&lt;br /&gt;&lt;br /&gt;switch(type){&lt;br /&gt;case TILESTEPS:&lt;br /&gt;hvalue=0;&lt;br /&gt;for(v=0; v&amp;lt;SIZE; v++){&lt;br /&gt;if(anode-&amp;gt;state[v]=='#') continue;&lt;br /&gt;hvalue+=abs(v-GetCharValue(anode-&amp;gt;state[v])+1);&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;anode-&amp;gt;h=hvalue;&lt;br /&gt;break;&lt;/span&gt;&lt;/p&gt;&lt;p  style="font-family:courier new;"&gt;&lt;span style="font-size:85%;"&gt;case DISTANCE: //Number of tile that are not put in correct position.&lt;br /&gt;//Not including the space.&lt;br /&gt;&lt;br /&gt;hvalue=0;&lt;br /&gt;for(v=0; v&amp;lt;SIZE; v++){&lt;br /&gt;if(anode-&amp;gt;state[v]!='#'){&lt;br /&gt;if( (v+1)!=(int)GetCharValue(anode-&amp;gt;state[v]) )&lt;br /&gt;hvalue++;&lt;br /&gt;}&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;anode-&amp;gt;h=hvalue;&lt;br /&gt;break;&lt;br /&gt;&lt;br /&gt;case MANHATTAN:&lt;br /&gt;hvalue=GetManhattanDistance(anode-&amp;gt;state);&lt;br /&gt;anode-&amp;gt;h=hvalue;&lt;br /&gt;break;&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;p  style="font-family:courier new;"&gt;&lt;span style="font-size:85%;"&gt;case ASTAR: //Calculating A* algorithm.&lt;br /&gt;anode-&amp;gt;gn=anode-&amp;gt;parent-&amp;gt;gn+1; //cause cost for epanding node is 1.&lt;br /&gt;anode-&amp;gt;hn=GetManhattanDistance(anode-&amp;gt;state);&lt;br /&gt;hvalue= anode-&amp;gt;gn + anode-&amp;gt;hn;&lt;br /&gt;anode-&amp;gt;fn=hvalue;&lt;br /&gt;break;&lt;br /&gt;&lt;br /&gt;}//End solution switch.&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;void addChild(TreeNode* thisnode, char *state){&lt;br /&gt;TreeNode* newnode = new TreeNode();&lt;br /&gt;newnode-&amp;gt;parent=thisnode;&lt;br /&gt;newnode-&amp;gt;setState(state);&lt;br /&gt;&lt;br /&gt;if(thisnode-&amp;gt;child1==NULL) {&lt;br /&gt;thisnode-&amp;gt;child1=newnode;&lt;br /&gt;return;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;if(thisnode-&amp;gt;child2==NULL) {&lt;br /&gt;thisnode-&amp;gt;child2=newnode;&lt;br /&gt;return;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;if(thisnode-&amp;gt;child3==NULL) {&lt;br /&gt;thisnode-&amp;gt;child3=newnode;&lt;br /&gt;return;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;if(thisnode-&amp;gt;child4==NULL) {&lt;br /&gt;thisnode-&amp;gt;child4=newnode;&lt;br /&gt;return;&lt;br /&gt;}&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;void newState(char *n, char *p, int oldp, int newp){&lt;br /&gt;char hold;&lt;br /&gt;for(int v=0; v&amp;lt;SIZE; v++) *(n+v)=*(p+v);&lt;br /&gt;hold=*(n+newp);&lt;br /&gt;*(n+newp)=*(p+oldp);&lt;br /&gt;*(n+oldp)=hold;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;BOOL isEverSameState(char *s, TreeNode* thisnode){&lt;br /&gt;BOOL flag;&lt;br /&gt;TreeNode* curr;&lt;br /&gt;flag=false;&lt;br /&gt;curr=thisnode-&amp;gt;parent;&lt;br /&gt;while(curr!=NULL){&lt;br /&gt;if(isSameState(s, curr-&amp;gt;state)){&lt;br /&gt;flag=true;&lt;br /&gt;break;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;curr=curr-&amp;gt;parent;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;return flag;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;BOOL isSameState(char *s1, char *s2){&lt;br /&gt;BOOL flag;&lt;br /&gt;flag=true;&lt;br /&gt;for(int v=0; v&amp;lt;SIZE; v++){&lt;br /&gt;if(*(s1+v)!=*(s2+v)){&lt;br /&gt;flag=false;&lt;br /&gt;break;&lt;br /&gt;}&lt;br /&gt;}&lt;br /&gt;return flag;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;int getSpacePos(char *s){&lt;br /&gt;int p;&lt;br /&gt;for(int v=0; v&amp;lt;SIZE; v++){&lt;br /&gt;if(*(s+v)=='#'){&lt;br /&gt;p=v;&lt;br /&gt;break;&lt;br /&gt;}&lt;br /&gt;}&lt;br /&gt;return p;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;int GetManhattanDistance(char *s){&lt;br /&gt;&lt;br /&gt;int c, r, ap, ar, ac; //current col, current row, actual position.&lt;br /&gt;//actual col, actual row.&lt;br /&gt;&lt;br /&gt;int m; //manhattan distance value.&lt;br /&gt;m=0;&lt;br /&gt;for(int v=0; v&amp;lt;SIZE; v++){&lt;br /&gt;if(*(s+v)=='#') continue; //skip space.&lt;br /&gt;r=v/3;&lt;br /&gt;c=v%3;&lt;br /&gt;ap=GetCharValue(*(s+v))-1;&lt;br /&gt;ar=ap/3;&lt;br /&gt;ac=ap%3;&lt;br /&gt;m=m+(abs(r-ar)+abs(c-ac));&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;return m;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;};&lt;/span&gt;&lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5758484518227245221-8736584103481832078?l=8-puzzle.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://8-puzzle.blogspot.com/feeds/8736584103481832078/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=5758484518227245221&amp;postID=8736584103481832078' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5758484518227245221/posts/default/8736584103481832078'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5758484518227245221/posts/default/8736584103481832078'/><link rel='alternate' type='text/html' href='http://8-puzzle.blogspot.com/2008/05/8-puzzle-code-treeh.html' title='8 Puzzle Code - Tree.h'/><author><name>Ahyeek</name><uri>http://www.blogger.com/profile/06695600039671648941</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='33' height='26' src='http://www.geocities.com/ahyeek/Smaller-Office.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5758484518227245221.post-1404427180520918715</id><published>2008-05-09T06:47:00.001-07:00</published><updated>2008-05-09T06:47:20.347-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='8 Puzzle Code - LinkQueue.h'/><title type='text'>8 Puzzle Code - LinkQueue.h</title><content type='html'>#include "TreeNode.h"&lt;br /&gt;&lt;br /&gt;#ifndef _LINKQUEUE_H&lt;br /&gt;#define _LINKQUEUE_H&lt;br /&gt;&lt;br /&gt;#define TILESTEPS 1&lt;br /&gt;#define DISTANCE 2&lt;br /&gt;#define MANHATTAN 3&lt;br /&gt;#define ASTAR 4&lt;br /&gt;&lt;br /&gt;class QueueNode{&lt;br /&gt;public:&lt;br /&gt;   TreeNode* treenode;&lt;br /&gt;   QueueNode* next;&lt;br /&gt;   QueueNode(TreeNode* thenode){&lt;br /&gt;       treenode=thenode;&lt;br /&gt;       next=NULL;&lt;br /&gt;   }&lt;br /&gt;};&lt;br /&gt;&lt;br /&gt;class LinkQueue{&lt;br /&gt;public:&lt;br /&gt;   QueueNode* head;&lt;br /&gt;   QueueNode* tail;&lt;br /&gt;&lt;br /&gt;   LinkQueue(){&lt;br /&gt;       head=NULL;&lt;br /&gt;       tail=NULL;&lt;br /&gt;   }&lt;br /&gt;&lt;br /&gt;   BOOL isEmpty(){ return (head==NULL &amp;amp;&amp;amp; tail==NULL); }&lt;br /&gt;&lt;br /&gt;   void add(TreeNode* thenode){&lt;br /&gt;       QueueNode* newnode = new QueueNode(thenode);&lt;br /&gt;       if(isEmpty()){&lt;br /&gt;           head=newnode;&lt;br /&gt;           tail=head;&lt;br /&gt;       }&lt;br /&gt;       else{&lt;br /&gt;           tail-&amp;gt;next=newnode;&lt;br /&gt;           tail=newnode;&lt;br /&gt;       }&lt;br /&gt;   }&lt;br /&gt;&lt;br /&gt;   //Add in version 3.&lt;br /&gt;   //Adding Q with sort manner according to node heuristic value.&lt;br /&gt;   void addHeuristic(TreeNode* thenode, int type){&lt;br /&gt;       UINT currh, newh;&lt;br /&gt;       QueueNode* newnode=new QueueNode(thenode);&lt;br /&gt;&lt;br /&gt;       if(isEmpty()){&lt;br /&gt;           head=newnode;&lt;br /&gt;           tail=head;&lt;br /&gt;       }&lt;br /&gt;       else{&lt;br /&gt;           QueueNode* prevnode;&lt;br /&gt;           QueueNode* currnode;&lt;br /&gt;           BOOL addedflag;&lt;br /&gt;&lt;br /&gt;           addedflag=false;&lt;br /&gt;           currnode=head;&lt;br /&gt;           prevnode=NULL;&lt;br /&gt;&lt;br /&gt;           while(currnode!=NULL){&lt;br /&gt;               switch(type){&lt;br /&gt;                   case TILESTEPS:&lt;br /&gt;                   case DISTANCE:&lt;br /&gt;                   case MANHATTAN:&lt;br /&gt;                       currh=currnode-&amp;gt;treenode-&amp;gt;h;&lt;br /&gt;                       newh=newnode-&amp;gt;treenode-&amp;gt;h;&lt;br /&gt;                       break;&lt;br /&gt;&lt;br /&gt;                   case ASTAR:&lt;br /&gt;                       currh=currnode-&amp;gt;treenode-&amp;gt;fn;&lt;br /&gt;                       newh=newnode-&amp;gt;treenode-&amp;gt;fn;&lt;br /&gt;                       break;&lt;br /&gt;               }&lt;br /&gt;&lt;br /&gt;               if( currh&amp;gt;newh ){&lt;br /&gt;                   if(prevnode==NULL){&lt;br /&gt;                       head=newnode;&lt;br /&gt;                       head-&amp;gt;next=currnode;&lt;br /&gt;                   }&lt;br /&gt;                   else{&lt;br /&gt;                       newnode-&amp;gt;next=currnode;&lt;br /&gt;                       prevnode-&amp;gt;next=newnode;&lt;br /&gt;                   }&lt;br /&gt;&lt;br /&gt;                   addedflag=true;&lt;br /&gt;                   break;&lt;br /&gt;               }&lt;br /&gt;&lt;br /&gt;               prevnode=currnode;&lt;br /&gt;               currnode=currnode-&amp;gt;next;&lt;br /&gt;           }         &lt;br /&gt;&lt;br /&gt;           if(!addedflag){&lt;br /&gt;               tail-&amp;gt;next=newnode;&lt;br /&gt;               tail=newnode;&lt;br /&gt;           }&lt;br /&gt;       }&lt;br /&gt;   }&lt;br /&gt;&lt;br /&gt;   QueueNode* get(){      &lt;br /&gt;       QueueNode* temp;&lt;br /&gt;       temp=head;&lt;br /&gt;       head=head-&amp;gt;next;&lt;br /&gt;       if(head==NULL) tail=NULL;      &lt;br /&gt;       return temp;&lt;br /&gt;   }&lt;br /&gt;&lt;br /&gt;   void deleteNode(){&lt;br /&gt;       QueueNode* curr;&lt;br /&gt;       curr=head;&lt;br /&gt;       while(curr!=NULL){&lt;br /&gt;           head=head-&amp;gt;next;&lt;br /&gt;           delete curr;&lt;br /&gt;           curr=head;&lt;br /&gt;       }&lt;br /&gt;   }&lt;br /&gt;&lt;br /&gt;   void reset(){&lt;br /&gt;       deleteNode();&lt;br /&gt;       head=NULL;&lt;br /&gt;       tail=NULL;&lt;br /&gt;   }&lt;br /&gt;&lt;br /&gt;   ~LinkQueue(){&lt;br /&gt;       deleteNode();&lt;br /&gt;   }&lt;br /&gt;};&lt;br /&gt;#endif&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5758484518227245221-1404427180520918715?l=8-puzzle.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://8-puzzle.blogspot.com/feeds/1404427180520918715/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=5758484518227245221&amp;postID=1404427180520918715' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5758484518227245221/posts/default/1404427180520918715'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5758484518227245221/posts/default/1404427180520918715'/><link rel='alternate' type='text/html' href='http://8-puzzle.blogspot.com/2008/05/8-puzzle-code-linkqueueh.html' title='8 Puzzle Code - LinkQueue.h'/><author><name>Ahyeek</name><uri>http://www.blogger.com/profile/06695600039671648941</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='33' height='26' src='http://www.geocities.com/ahyeek/Smaller-Office.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5758484518227245221.post-7996872498120134225</id><published>2008-05-09T06:46:00.003-07:00</published><updated>2008-05-09T06:46:54.698-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='8 Puzzle Code - LinkStack.h'/><title type='text'>8 Puzzle Code - LinkStack.h</title><content type='html'>&lt;p&gt;#include "TreeNode.h"&lt;br /&gt;&lt;/p&gt;&lt;p&gt;#ifndef _LINKSTACK_H&lt;br /&gt;#define _LINKSTACK_H&lt;br /&gt;&lt;br /&gt;class LinkNode{&lt;br /&gt;public:&lt;br /&gt;TreeNode* treenode;&lt;br /&gt;LinkNode* next;&lt;br /&gt;LinkNode(TreeNode* thenode){&lt;br /&gt;treenode=thenode;&lt;br /&gt;next=NULL;&lt;br /&gt;}&lt;br /&gt;};&lt;br /&gt;&lt;br /&gt;class LinkStack{&lt;br /&gt;public:&lt;br /&gt;LinkNode* head;&lt;br /&gt;LinkStack(){ head=NULL; }&lt;br /&gt;&lt;br /&gt;~LinkStack(){&lt;br /&gt;deletenode(head);&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;void deletenode(LinkNode *n){&lt;br /&gt;if(n==NULL) return;&lt;br /&gt;deletenode(n-&amp;gt;next);&lt;br /&gt;delete n;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;BOOL isEmpty() { return (head==NULL); }&lt;br /&gt;&lt;br /&gt;void push(TreeNode* thenode){&lt;br /&gt;LinkNode* newnode = new LinkNode(thenode);&lt;br /&gt;if(isEmpty()){&lt;br /&gt;head=newnode;&lt;br /&gt;}&lt;br /&gt;else{&lt;br /&gt;newnode-&amp;gt;next=head;&lt;br /&gt;head=newnode;&lt;br /&gt;}&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;UINT NumOfNodes(){&lt;br /&gt;LinkNode* curr;&lt;br /&gt;curr=head;&lt;br /&gt;UINT temp;&lt;br /&gt;temp=0;&lt;br /&gt;while(curr!=NULL){&lt;br /&gt;temp++;&lt;br /&gt;curr=curr-&amp;gt;next;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;return temp;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;LinkNode* getNode(int nodeno){&lt;br /&gt;int i;&lt;br /&gt;LinkNode* curr;&lt;br /&gt;curr=head;&lt;br /&gt;i=0;&lt;br /&gt;while(i&amp;lt;nodeno){&lt;br /&gt;curr=curr-&amp;gt;next;&lt;br /&gt;i++;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;return curr;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;LinkNode* pop(){&lt;br /&gt;LinkNode* temp;&lt;br /&gt;temp=head;&lt;br /&gt;head=head-&amp;gt;next;&lt;br /&gt;return temp;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;void reset(){&lt;br /&gt;if(head==NULL) return;&lt;br /&gt;deletenode(head);&lt;br /&gt;head=NULL;&lt;br /&gt;}&lt;br /&gt;};&lt;br /&gt;&lt;br /&gt;#endif&lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5758484518227245221-7996872498120134225?l=8-puzzle.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://8-puzzle.blogspot.com/feeds/7996872498120134225/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=5758484518227245221&amp;postID=7996872498120134225' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5758484518227245221/posts/default/7996872498120134225'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5758484518227245221/posts/default/7996872498120134225'/><link rel='alternate' type='text/html' href='http://8-puzzle.blogspot.com/2008/05/8-puzzle-code-linkstackh.html' title='8 Puzzle Code - LinkStack.h'/><author><name>Ahyeek</name><uri>http://www.blogger.com/profile/06695600039671648941</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='33' height='26' src='http://www.geocities.com/ahyeek/Smaller-Office.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5758484518227245221.post-5931986855199808768</id><published>2008-05-09T06:46:00.001-07:00</published><updated>2008-05-09T06:46:33.496-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='8 Puzzle Code - ReadMe.txt'/><title type='text'>8 Puzzle Code - ReadMe.txt</title><content type='html'>//This program try to solve the 8-PUZZLE problem.&lt;br /&gt;&lt;br /&gt;//Program version: Version 1&lt;br /&gt;//Create date: 26 JUN 2002&lt;br /&gt;//Description: Background process the solution.&lt;br /&gt;               1) Initial the problem first stage.&lt;br /&gt;               2) Expand the problem tree space from problem state to&lt;br /&gt;                  new state.&lt;br /&gt;               3) This version got some bugs in expanding to new state.&lt;br /&gt;               4) Using Queue data structure and State Node to implement problem&lt;br /&gt;                  tree problem space and performing breath first search algo.&lt;br /&gt;               5) Did not implement step by step solutions display.&lt;br /&gt;               6) Solution to puzzle problem is performed background.&lt;br /&gt;               7) Some bugs, new state didnt be generated correctly.&lt;br /&gt;&lt;br /&gt;//Program version: Version 2&lt;br /&gt;//Create date: 28 JUN 2002&lt;br /&gt;//Description: 1) Enhance version 1.&lt;br /&gt;               2) Implement puzzle problem tree using tree data structure.&lt;br /&gt;               3) Create multi expanding tree using Tree and TreeNode data&lt;br /&gt;                  structure. Implementing maximum four child per node.&lt;br /&gt;               4) Implementing breath first search on tree using Queue data&lt;br /&gt;                  structure.&lt;br /&gt;               5) Implementing step by step solution display. Using stack to&lt;br /&gt;                  collect the state from the bottom of tree until the root&lt;br /&gt;                  of problem tree.&lt;br /&gt;               6) Limitation:&lt;br /&gt;                    ** Did not implement heuristic search technique.&lt;br /&gt;                    ** Problem is, the n number of expanded node is&lt;br /&gt;                       3 to the power of steps for solution to a certain&lt;br /&gt;                       question.&lt;br /&gt;                    ** Need a lot of time and memory space to solve certain&lt;br /&gt;                       puzzle problem.&lt;br /&gt;&lt;br /&gt;//Update 3 July 2002&lt;br /&gt;    1) Implement Heuristic search. Mahathan distance heuristic search.&lt;br /&gt;       Be able to solve certain difficult puzzle in short time.&lt;br /&gt;       Better than blind breath first search.&lt;br /&gt;&lt;br /&gt;//Update 8 July 2002&lt;br /&gt;    1) Add a pair of previous and next button for user to step through the&lt;br /&gt;       solution computer get.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;//Update 11 July 2002&lt;br /&gt;    1) Correct wrong implementation of Manhattan Distance Algorithm.&lt;br /&gt;    2) Implement correct Manhattan Distance Algorithm.&lt;br /&gt;    3) Fix some exception memory bugs.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5758484518227245221-5931986855199808768?l=8-puzzle.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://8-puzzle.blogspot.com/feeds/5931986855199808768/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=5758484518227245221&amp;postID=5931986855199808768' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5758484518227245221/posts/default/5931986855199808768'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5758484518227245221/posts/default/5931986855199808768'/><link rel='alternate' type='text/html' href='http://8-puzzle.blogspot.com/2008/05/8-puzzle-code-readmetxt.html' title='8 Puzzle Code - ReadMe.txt'/><author><name>Ahyeek</name><uri>http://www.blogger.com/profile/06695600039671648941</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='33' height='26' src='http://www.geocities.com/ahyeek/Smaller-Office.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5758484518227245221.post-7023662936456678659</id><published>2008-05-09T06:45:00.002-07:00</published><updated>2008-05-09T06:46:10.837-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='8 Puzzle Code - Queue.h'/><title type='text'>8 Puzzle Code - Queue.h</title><content type='html'>&lt;span style="font-weight: bold;"&gt;Share code: 8 Puzzle Code - Queue.h &lt;/span&gt;&lt;br /&gt;&lt;br /&gt;#include "statenode.h"&lt;br /&gt;&lt;br /&gt;class Queue{&lt;br /&gt;public:&lt;br /&gt;    StateNode* head;&lt;br /&gt;    StateNode* tail;&lt;br /&gt;&lt;br /&gt;    Queue();&lt;br /&gt;    ~Queue();&lt;br /&gt;    void deleteNode(StateNode*);&lt;br /&gt;    void add(char* , char*);&lt;br /&gt;    BOOL isEmpty();&lt;br /&gt;    StateNode* get();&lt;br /&gt;};&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5758484518227245221-7023662936456678659?l=8-puzzle.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://8-puzzle.blogspot.com/feeds/7023662936456678659/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=5758484518227245221&amp;postID=7023662936456678659' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5758484518227245221/posts/default/7023662936456678659'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5758484518227245221/posts/default/7023662936456678659'/><link rel='alternate' type='text/html' href='http://8-puzzle.blogspot.com/2008/05/8-puzzle-code-queueh.html' title='8 Puzzle Code - Queue.h'/><author><name>Ahyeek</name><uri>http://www.blogger.com/profile/06695600039671648941</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='33' height='26' src='http://www.geocities.com/ahyeek/Smaller-Office.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5758484518227245221.post-5691893592393919964</id><published>2008-05-09T06:45:00.001-07:00</published><updated>2008-05-09T06:45:49.897-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='8 Puzzle Code - StateNode.h'/><title type='text'>8 Puzzle Code - StateNode.h</title><content type='html'>&lt;p&gt;#define SIZE 9&lt;br /&gt;class StateNode{&lt;br /&gt;public:&lt;br /&gt;char puzzle[SIZE];&lt;br /&gt;char parentstate[SIZE];&lt;/p&gt;&lt;p&gt;&lt;br /&gt;&lt;/p&gt;&lt;p&gt;StateNode* next;&lt;/p&gt;&lt;p&gt;StateNode(){&lt;br /&gt;next=NULL;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;void setPuzzle(char* p){&lt;br /&gt;for(int v=0; v&amp;lt;SIZE; v++) puzzle[v]=*(p+v);&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;void setParentState(char *pp){&lt;br /&gt;for(int v=0; v&amp;lt;SIZE; v++) parentstate[v]=*(pp+v);&lt;br /&gt;}&lt;br /&gt;};&lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5758484518227245221-5691893592393919964?l=8-puzzle.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://8-puzzle.blogspot.com/feeds/5691893592393919964/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=5758484518227245221&amp;postID=5691893592393919964' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5758484518227245221/posts/default/5691893592393919964'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5758484518227245221/posts/default/5691893592393919964'/><link rel='alternate' type='text/html' href='http://8-puzzle.blogspot.com/2008/05/8-puzzle-code-statenodeh.html' title='8 Puzzle Code - StateNode.h'/><author><name>Ahyeek</name><uri>http://www.blogger.com/profile/06695600039671648941</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='33' height='26' src='http://www.geocities.com/ahyeek/Smaller-Office.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5758484518227245221.post-3384734316274153196</id><published>2008-05-09T06:44:00.000-07:00</published><updated>2008-05-09T06:45:23.437-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='8 Puzzle Code - Queue.cpp'/><title type='text'>8 Puzzle Code - Queue.cpp</title><content type='html'>&lt;p&gt;#include "stdafx.h"&lt;br /&gt;#include "queue.h"&lt;br /&gt;&lt;br /&gt;Queue::Queue(){&lt;br /&gt;   head=NULL;&lt;br /&gt;   tail=NULL;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;BOOL Queue::isEmpty(){&lt;br /&gt;&lt;br /&gt;   return (head==NULL &amp;amp;&amp;amp; tail==NULL);&lt;br /&gt;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;void Queue::add(char* p, char* pp){&lt;br /&gt;&lt;br /&gt;   StateNode* newnode = new StateNode();&lt;br /&gt;   newnode-&amp;gt;setPuzzle(p);&lt;br /&gt;   newnode-&amp;gt;setParentState(pp);&lt;br /&gt;&lt;br /&gt;   if(isEmpty()){&lt;br /&gt;       head=newnode;&lt;br /&gt;       tail=head;&lt;br /&gt;   }&lt;br /&gt;   else{      &lt;br /&gt;       tail-&amp;gt;next=newnode;&lt;br /&gt;       tail=newnode;&lt;br /&gt;   }&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;StateNode* Queue::get(){&lt;br /&gt;   StateNode* temp;&lt;br /&gt;   temp=head;&lt;br /&gt;   head=head-&amp;gt;next;&lt;br /&gt;   if(head==NULL) tail=NULL;&lt;br /&gt;   return temp;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;void Queue::deleteNode(StateNode* n){&lt;br /&gt;   StateNode* curr=head;&lt;br /&gt;   while(curr!=NULL){&lt;br /&gt;       head=head-&amp;gt;next;&lt;br /&gt;       delete curr;&lt;br /&gt;       curr=head;&lt;br /&gt;   }&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;Queue::~Queue(){&lt;br /&gt;   TRACE(_T("Delete Q...\n"));&lt;br /&gt;   deleteNode(head);&lt;br /&gt;}&lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5758484518227245221-3384734316274153196?l=8-puzzle.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://8-puzzle.blogspot.com/feeds/3384734316274153196/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=5758484518227245221&amp;postID=3384734316274153196' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5758484518227245221/posts/default/3384734316274153196'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5758484518227245221/posts/default/3384734316274153196'/><link rel='alternate' type='text/html' href='http://8-puzzle.blogspot.com/2008/05/8-puzzle-code-queuecpp.html' title='8 Puzzle Code - Queue.cpp'/><author><name>Ahyeek</name><uri>http://www.blogger.com/profile/06695600039671648941</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='33' height='26' src='http://www.geocities.com/ahyeek/Smaller-Office.jpg'/></author><thr:total>0</thr:total></entry></feed>
