<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Web Plant Media &#187; C-Programming</title>
	<atom:link href="http://www.webplantmedia.com/category/c-programming/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.webplantmedia.com</link>
	<description>Lubbock Web Design and Web Development</description>
	<lastBuildDate>Wed, 28 Mar 2012 21:19:57 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.2</generator>
		<item>
		<title>Mapped File, Paging and Memory Protection – C Programming</title>
		<link>http://www.webplantmedia.com/c-programming/2010/04/mapped-file-paging-and-memory-protection-c-programming/</link>
		<comments>http://www.webplantmedia.com/c-programming/2010/04/mapped-file-paging-and-memory-protection-c-programming/#comments</comments>
		<pubDate>Mon, 19 Apr 2010 16:30:21 +0000</pubDate>
		<dc:creator>ChrisB</dc:creator>
				<category><![CDATA[C-Programming]]></category>

		<guid isPermaLink="false">http://www.webplantmedia.com/?p=401</guid>
		<description><![CDATA[This program shows use of a number of system calls such as how to map a disk file in the virtual memory of a process space, divide it into pages, set access protection code such as read_only, write_only, etc to individual pages, read/write individual pages, and copy the file back to disk page by page. [...]]]></description>
			<content:encoded><![CDATA[<p>This program shows use of a number of system calls such as how to map a disk file in the virtual memory of a process space, divide it into pages, set access protection code such as read_only, write_only, etc to individual pages, read/write individual pages, and copy the file back to disk page by page.</p>

<div class="wp_syntax"><div class="code"><pre class="c" style="font-family:monospace;"><span style="color: #339933;">#include &lt;stdio.h&gt;</span>
<span style="color: #339933;">#include &lt;stdlib.h&gt;</span>
<span style="color: #339933;">#include &lt;sys/mman.h&gt;</span>
<span style="color: #339933;">#include &lt;sys/types.h&gt;</span>
<span style="color: #339933;">#include &lt;sys/stat.h&gt;</span>
<span style="color: #339933;">#include &lt;fcntl.h&gt;</span>
<span style="color: #339933;">#include &lt;errno.h&gt;</span>
<span style="color: #339933;">#include &lt;string.h&gt;</span>
<span style="color: #339933;">#include &lt;unistd.h&gt;</span>
<span style="color: #000000; font-weight: bold;">extern</span> <span style="color: #993333;">int</span> errno<span style="color: #339933;">;</span>
&nbsp;
main<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
<span style="color: #993333;">int</span> fid1<span style="color: #339933;">,</span> fid2<span style="color: #339933;">;</span>
<span style="color: #993333;">void</span> <span style="color: #339933;">*</span>address1<span style="color: #339933;">,</span> <span style="color: #339933;">*</span>address2<span style="color: #339933;">;</span>
<span style="color: #993333;">char</span> buf<span style="color: #009900;">&#91;</span><span style="color: #0000dd;">10</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span> data<span style="color: #009900;">&#91;</span><span style="color: #0000dd;">10</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">=</span><span style="color: #ff0000;">&quot;edwin c&quot;</span><span style="color: #339933;">;</span>
<span style="color: #993333;">char</span> <span style="color: #339933;">*</span>ptr<span style="color: #339933;">,</span> <span style="color: #339933;">*</span>base<span style="color: #339933;">,</span> data1<span style="color: #009900;">&#91;</span><span style="color: #0000dd;">10</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">=</span><span style="color: #ff0000;">&quot;baldelomar&quot;</span><span style="color: #339933;">;</span>
<span style="color: #993333;">int</span> i<span style="color: #339933;">,</span> n<span style="color: #339933;">,</span> pagesize<span style="color: #339933;">;</span>
<span style="color: #993333;">struct</span> stat statbuf<span style="color: #339933;">;</span>
<span style="color: #993333;">int</span> inFileSize<span style="color: #339933;">,</span> outFileSize<span style="color: #339933;">;</span>
&nbsp;
<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #009900;">&#40;</span>fid1 <span style="color: #339933;">=</span> open<span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;alice29.txt&quot;</span><span style="color: #339933;">,</span> O_RDWR<span style="color: #339933;">,</span>  <span style="color: #208080;">0600</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">&lt;</span> <span style="color: #0000dd;">0</span><span style="color: #009900;">&#41;</span>
 <span style="color: #009900;">&#123;</span>perror<span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;alice open failed&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #000066;">printf</span> <span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot; errno=%d <span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">,</span> errno<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> 
 <span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span>fstat<span style="color: #009900;">&#40;</span>fid1<span style="color: #339933;">,</span> <span style="color: #339933;">&amp;</span>statbuf<span style="color: #009900;">&#41;</span><span style="color: #339933;">&lt;</span><span style="color: #0000dd;">0</span><span style="color: #009900;">&#41;</span> perror<span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;fstat error&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
inFileSize <span style="color: #339933;">=</span> statbuf.<span style="color: #202020;">st_size</span><span style="color: #339933;">;</span>
<span style="color: #000066;">printf</span><span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;Temp1 file size=%d<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">,</span> inFileSize<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #009900;">&#40;</span>fid2 <span style="color: #339933;">=</span> open<span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;temp2&quot;</span><span style="color: #339933;">,</span> O_RDWR <span style="color: #339933;">|</span> O_CREAT <span style="color: #339933;">|</span> O_TRUNC<span style="color: #339933;">,</span>  <span style="color: #208080;">0600</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">&lt;</span> <span style="color: #0000dd;">0</span><span style="color: #009900;">&#41;</span>
 perror<span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;temp2 open failed&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> 
&nbsp;
<span style="color: #808080; font-style: italic;">/* temp2 is empty file. It has no space. Let us make it 20000 bytes
long by setting pointer to 9999 and then writeing a byte. */</span>
<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #009900;">&#40;</span>lseek<span style="color: #009900;">&#40;</span>fid2<span style="color: #339933;">,</span> <span style="color: #0000dd;">19999</span><span style="color: #339933;">,</span> SEEK_SET<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">&lt;</span> <span style="color: #0000dd;">0</span><span style="color: #009900;">&#41;</span> perror <span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;lseek error&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span>write<span style="color: #009900;">&#40;</span>fid2<span style="color: #339933;">,</span> <span style="color: #ff0000;">&quot;X&quot;</span><span style="color: #339933;">,</span> <span style="color: #0000dd;">1</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">!=</span> <span style="color: #0000dd;">1</span><span style="color: #009900;">&#41;</span> <span style="color: #666666; font-style: italic;">//write 'X' at end</span>
  <span style="color: #009900;">&#123;</span>perror<span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;write error&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> exit<span style="color: #009900;">&#40;</span><span style="color: #339933;">-</span><span style="color: #0000dd;">1</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><span style="color: #009900;">&#125;</span>
&nbsp;
&nbsp;
<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span>fstat<span style="color: #009900;">&#40;</span>fid2<span style="color: #339933;">,</span> <span style="color: #339933;">&amp;</span>statbuf<span style="color: #009900;">&#41;</span><span style="color: #339933;">&lt;</span><span style="color: #0000dd;">0</span><span style="color: #009900;">&#41;</span> perror<span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;fstat error&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
outFileSize <span style="color: #339933;">=</span> statbuf.<span style="color: #202020;">st_size</span><span style="color: #339933;">;</span>
<span style="color: #000066;">printf</span><span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;Temp2 file size=%d<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">,</span> outFileSize<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><span style="color: #808080; font-style: italic;">/*prints size=20000*/</span>
&nbsp;
<span style="color: #808080; font-style: italic;">/*----------------------------------------------------*/</span>
<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #009900;">&#40;</span>pagesize<span style="color: #339933;">=</span>sysconf<span style="color: #009900;">&#40;</span>_SC_PAGESIZE<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">&lt;</span><span style="color: #0000dd;">0</span><span style="color: #009900;">&#41;</span> perror<span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;sysconf failed&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000066;">printf</span><span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;page size =%d<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">,</span> pagesize<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #808080; font-style: italic;">/* map source file entirely in memory for reading by possibly
multiple processed, who may share all changes. */</span>
&nbsp;
<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #009900;">&#40;</span>address1 <span style="color: #339933;">=</span> mmap<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#40;</span>caddr_t<span style="color: #009900;">&#41;</span> <span style="color: #0000dd;">0</span><span style="color: #339933;">,</span> inFileSize<span style="color: #339933;">,</span> PROT_READ<span style="color: #339933;">,</span> MAP_SHARED<span style="color: #339933;">,</span> fid1<span style="color: #339933;">,</span> <span style="color: #0000dd;">0</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">==</span>MAP_FAILED<span style="color: #009900;">&#41;</span> 
<span style="color: #009900;">&#123;</span>perror<span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;mmap failed&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #000066;">printf</span><span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;errno=%d<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">,</span> errno<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><span style="color: #009900;">&#125;</span>
<span style="color: #000066;">printf</span><span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;actual mapped address1=0x%x<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">,</span> address1<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
base <span style="color: #339933;">=</span> ptr <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span><span style="color: #993333;">char</span> <span style="color: #339933;">*</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#40;</span>address1<span style="color: #339933;">+</span><span style="color: #0000dd;">500</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">for</span> <span style="color: #009900;">&#40;</span>i<span style="color: #339933;">=</span><span style="color: #0000dd;">0</span><span style="color: #339933;">;</span> i<span style="color: #339933;">&lt;</span> <span style="color: #0000dd;">8</span><span style="color: #339933;">;</span> i<span style="color: #339933;">++</span><span style="color: #009900;">&#41;</span> buf<span style="color: #009900;">&#91;</span>i<span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #339933;">*</span>ptr<span style="color: #339933;">++;</span> buf<span style="color: #009900;">&#91;</span><span style="color: #0000dd;">8</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">=</span><span style="color: #ff0000;">'<span style="color: #006699; font-weight: bold;">\0</span>'</span><span style="color: #339933;">;</span>
<span style="color: #000066;">printf</span> <span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;Reading Source: %s<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">,</span> buf<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #808080; font-style: italic;">/* Following attempt to write to source file should cause segmentation
error, because of read_prot, although the file is onped RDWR.*/</span>
&nbsp;
<span style="color: #808080; font-style: italic;">/*
ptr = base;
for(i=0; i&lt;8; i++) *ptr++ = data[i]; 
fprintf(stderr, &quot;Writing to source: %s\n&quot;, base);
*/</span>
<span style="color: #808080; font-style: italic;">/*----------------------------------------------------*/</span>
<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #009900;">&#40;</span>address2 <span style="color: #339933;">=</span> mmap<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#40;</span>caddr_t<span style="color: #009900;">&#41;</span> address1<span style="color: #339933;">,</span> <span style="color: #0000dd;">10000</span><span style="color: #339933;">,</span> <span style="color: #009900;">&#40;</span>PROT_READ <span style="color: #339933;">|</span> PROT_WRITE<span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span>  MAP_SHARED<span style="color: #339933;">,</span> fid2<span style="color: #339933;">,</span> <span style="color: #0000dd;">0</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">==</span>MAP_FAILED<span style="color: #009900;">&#41;</span> 
<span style="color: #009900;">&#123;</span>perror<span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;mmap failed&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #000066;">printf</span><span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;errno=%d<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">,</span> errno<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><span style="color: #009900;">&#125;</span>
<span style="color: #000066;">printf</span><span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;actual address2=0x%x<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">,</span> address2<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #808080; font-style: italic;">/* Make first page write only */</span>
<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #009900;">&#40;</span>mprotect<span style="color: #009900;">&#40;</span>address2<span style="color: #339933;">,</span> pagesize<span style="color: #339933;">,</span> PROT_WRITE<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">&lt;</span><span style="color: #0000dd;">0</span><span style="color: #009900;">&#41;</span> <span style="color: #000066;">printf</span><span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;protect write error=%d<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">,</span> errno<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #808080; font-style: italic;">/* make second page read only. */</span>
<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #009900;">&#40;</span>mprotect<span style="color: #009900;">&#40;</span>address2<span style="color: #339933;">+</span>pagesize<span style="color: #339933;">,</span> pagesize<span style="color: #339933;">,</span> PROT_READ<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">&lt;</span><span style="color: #0000dd;">0</span><span style="color: #009900;">&#41;</span> <span style="color: #000066;">printf</span><span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;protect read  error=%d<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">,</span> errno<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
&nbsp;
<span style="color: #808080; font-style: italic;">/* Dump one page of memory space to output file */</span>
<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #009900;">&#40;</span>msync<span style="color: #009900;">&#40;</span>address2<span style="color: #339933;">,</span> pagesize<span style="color: #339933;">,</span> MS_SYNC<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">&lt;</span><span style="color: #0000dd;">0</span><span style="color: #009900;">&#41;</span> <span style="color: #000066;">printf</span><span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;m-sync error=%d<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">,</span> errno<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
munmap<span style="color: #009900;">&#40;</span>address1<span style="color: #339933;">,</span> inFileSize<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><span style="color: #666666; font-style: italic;">//remove memory space</span>
munmap<span style="color: #009900;">&#40;</span>address2<span style="color: #339933;">,</span> outFileSize<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
&nbsp;
<span style="color: #808080; font-style: italic;">/* I/O is possible using file descriptor, but not through alloacted space now. */</span>
close<span style="color: #009900;">&#40;</span>fid1<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
close<span style="color: #009900;">&#40;</span>fid2<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://www.webplantmedia.com/c-programming/2010/04/mapped-file-paging-and-memory-protection-c-programming/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Using A* Algorithm for solving 8-puzzle in C++</title>
		<link>http://www.webplantmedia.com/c-programming/2010/04/using-a-algorithm-for-solving-8-puzzle-in-c/</link>
		<comments>http://www.webplantmedia.com/c-programming/2010/04/using-a-algorithm-for-solving-8-puzzle-in-c/#comments</comments>
		<pubDate>Fri, 02 Apr 2010 19:21:59 +0000</pubDate>
		<dc:creator>ChrisB</dc:creator>
				<category><![CDATA[C-Programming]]></category>

		<guid isPermaLink="false">http://www.webplantmedia.com/?p=220</guid>
		<description><![CDATA[I recently had to do a project for my AI class that could solve an 8 puzzle using an A* search in C++. I have to admit that I wish I could have spent more time cleaning up my code. What&#8217;s good is my linked list structure. What&#8217;s a little sloppy are my computational methods. [...]]]></description>
			<content:encoded><![CDATA[<p>I recently had to do a project for my AI class that could solve an 8 puzzle using an A* search in C++. I have to admit that I wish I could have spent more time cleaning up my code. What&#8217;s good is my linked list structure. What&#8217;s a little sloppy are my computational methods. Regardless, I thought that this code could still be useful for people who are new or rusty on how to use classes and setting up a search tree. </p>
<p>This is an empty console project, with one source file (<a href="http://www.webplantmedia.com/wp-content/uploads/2010/04/main.cpp_.txt">main.cpp</a>), one input file (<a href="http://www.webplantmedia.com/wp-content/uploads/2010/04/in.txt">in.txt</a>), and one output file (<a href="http://www.webplantmedia.com/wp-content/uploads/2010/04/out.txt">out.txt</a>). This code has been tested, compiled, and executed under Visual Studio 2008 Professional Edition. </p>
<h3>My Algorithm</h3>
<p>I created a tree class that could handle linked lists. Every linked node could have up to 4 children. I would simply build the tree structure out. Using the first heuristic, I would build the tree according to which node had the lowest distance from the root node. This is pretty much creating a tree by a breadth depth search. My second heuristic added in a cost for how similar the current node&#8217;s state was to the goal state. This allowed the tree to be built smartly and not continue to expand down bad branches. </p>
<p>I also added a constraint that wouldn&#8217;t allow a node to be created if it was trying to make a bad move. A bad move is when the puzzle is backtracking. Backtracking is a sure sign that that branch is not an optimal solution.</p>
<h3>My Results</h3>
<p>I ran my program using two different heuristics. One was many times more efficient than the other. My first heuristic was simply just using the distance from the root node. It took 6.63 minutes to complete.</p>

<div class="wp_syntax"><div class="code"><pre class="c" style="font-family:monospace;"><span style="color: #808080; font-style: italic;">/**************OUTPUT******************/</span>
Success<span style="color: #339933;">!</span>
n <span style="color: #339933;">=</span> <span style="color: #0000dd;">12</span>
time<span style="color: #339933;">:</span> <span style="color: #0000dd;">663801</span> msecs
Press any key to <span style="color: #b1b100;">continue</span> . . .
<span style="color: #808080; font-style: italic;">/**************************************/</span></pre></div></div>

<p>My second heuristic was adding a cost to the distance for how many numbers in the current state were in the same position as the numbers in the goal state. The output was significantly faster. It computed the the same path in under 1 second.</p>

<div class="wp_syntax"><div class="code"><pre class="c" style="font-family:monospace;"><span style="color: #808080; font-style: italic;">/**************OUTPUT******************/</span>
Success<span style="color: #339933;">!</span>
n <span style="color: #339933;">=</span> <span style="color: #0000dd;">12</span>
time<span style="color: #339933;">:</span> <span style="color: #0000dd;">858</span> msecs
Press any key to <span style="color: #b1b100;">continue</span> . . .
<span style="color: #808080; font-style: italic;">/**************************************/</span></pre></div></div>

<h3>Using this Code</h3>
<p>If you are working on a similar assignment, feel free to use this code and expand on it. I would really appreciate it if someone could polish the code for me and send me an updated copy. It could use a better class structure, better name conventions, prettier computational methods, and some relevant comments. I simply didn&#8217;t have time. Feel free to leave a comment if you have any questions trying to get this to work on your computer. I hope this helps!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.webplantmedia.com/c-programming/2010/04/using-a-algorithm-for-solving-8-puzzle-in-c/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
	</channel>
</rss>

<!-- Performance optimized by W3 Total Cache. Learn more: http://www.w3-edge.com/wordpress-plugins/

Page Caching using disk: enhanced
Object Caching 240/246 objects using disk: basic

Served from: www.webplantmedia.com @ 2012-05-18 07:24:33 -->
