<?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>JADBOX: Web Application Musings &#187; Artificial Intelligence (AI)</title>
	<atom:link href="http://www.jadbox.com/category/artificial-intelligence-ai/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.jadbox.com</link>
	<description>Programming, Visualization and Game Development Theory</description>
	<lastBuildDate>Tue, 05 Jan 2010 15:28:32 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>What&#8217;s New, Doc?</title>
		<link>http://www.jadbox.com/2009/05/whats-new-doc/</link>
		<comments>http://www.jadbox.com/2009/05/whats-new-doc/#comments</comments>
		<pubDate>Tue, 05 May 2009 15:20:26 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Artificial Intelligence (AI)]]></category>
		<category><![CDATA[Flash/Flex/AIR]]></category>
		<category><![CDATA[Showcase]]></category>

		<guid isPermaLink="false">http://www.jadbox.com/?p=1190</guid>
		<description><![CDATA[
I have had some people asking me what I have been scheming lately which in honest hasn&#8217;t been much. The weather here in Michigan has been finally nice for a change so I have been spending most of my free time cycling. However, I did go out last weekend and finally bought the fabulous Gang [...]


Related posts:<ol><li><a href='http://www.jadbox.com/2009/04/detroit-design-patterns-lecture-pt-2/' rel='bookmark' title='Permanent Link: Detroit Design Patterns Lecture pt. 2'>Detroit Design Patterns Lecture pt. 2</a> <small>This Thursday, April 30th, I will be continuing my lecture...</small></li>
<li><a href='http://www.jadbox.com/2009/03/further-reading-on-design-patterns/' rel='bookmark' title='Permanent Link: Further Reading on Design Patterns'>Further Reading on Design Patterns</a> <small>As a followup on my Wednesday lecture on design patterns,...</small></li>
<li><a href='http://www.jadbox.com/2010/01/nownew-year2010/' rel='bookmark' title='Permanent Link: Now=new Year(2010)'>Now=new Year(2010)</a> <small>As the new decade begins, millions of people reflect on...</small></li>
</ol>]]></description>
			<content:encoded><![CDATA[<p style="text-align: center;"><img class="size-medium wp-image-1192" title="design-patterns-book-cover" src="http://www.jadbox.com/wp-content/uploads/2009/05/design-patterns-book-cover-229x300.png" alt="design-patterns-book-cover" width="180" height="230" /><img class="size-full wp-image-1193" title="wacom-bamboo-fun-medium-tablet-cte650k-300" src="http://www.jadbox.com/wp-content/uploads/2009/05/wacom-bamboo-fun-medium-tablet-cte650k-300.gif" alt="wacom-bamboo-fun-medium-tablet-cte650k-300" width="232" height="219" /></p>
<p>I have had some people asking me what I have been scheming lately which in honest hasn&#8217;t been much. The weather here in Michigan has been finally nice for a change so I have been spending most of my free time cycling. However, I did go out last weekend and finally bought the fabulous Gang of Four book Design Patterns to add to my library. I know enough C++, JAVA, and Smalltalk to decipher the examples and apply it to whatever language I might be using these days (which has been lots of AS3, haXe, C#, and Unity3D).  I also decided to join the tablet bandwagon and added a Wacom Bamboo to my collection in hopes that it will inspire me to work on my art portfolio that I have been neglecting. The surface really feels (and sounds) like you are drawing on paper!</p>
<p>In the next coming weeks I will be working on <a href="http://www.jadbox.com/flashmvc">FlashMVC</a> to do some cleanup and perhaps add more examples to the repository.<br />
Lastly, I have been experimenting on AI development with local unit world data deresolution and querying. Such a system I am building will allow NPCs to explore large environments while meta tagging locations of interests for latter lookups. Usually this isn&#8217;t as complicated as the process I am developing, but I have to design something that is agile and performs well in the Flash player environment. I will blog more about this soon most likely.</p>
<p>O, and thank you to the people who came to my lecture on design patterns last week! I hope everyone was able to walk away with some practical knowledge to apply to their own projects. There is a good chance that I might continue this lecture in the future to dive deeper into a variety of AS3-applicable development pattens. The video camera we had in the room had some issues (we lost the second half of the lecture), but I hope to get the recording compressed and posted here soon.</p>


<p>Related posts:<ol><li><a href='http://www.jadbox.com/2009/04/detroit-design-patterns-lecture-pt-2/' rel='bookmark' title='Permanent Link: Detroit Design Patterns Lecture pt. 2'>Detroit Design Patterns Lecture pt. 2</a> <small>This Thursday, April 30th, I will be continuing my lecture...</small></li>
<li><a href='http://www.jadbox.com/2009/03/further-reading-on-design-patterns/' rel='bookmark' title='Permanent Link: Further Reading on Design Patterns'>Further Reading on Design Patterns</a> <small>As a followup on my Wednesday lecture on design patterns,...</small></li>
<li><a href='http://www.jadbox.com/2010/01/nownew-year2010/' rel='bookmark' title='Permanent Link: Now=new Year(2010)'>Now=new Year(2010)</a> <small>As the new decade begins, millions of people reflect on...</small></li>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://www.jadbox.com/2009/05/whats-new-doc/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>A New Kind of Science, Indeed</title>
		<link>http://www.jadbox.com/2009/01/a-new-kind-of-science-indeed/</link>
		<comments>http://www.jadbox.com/2009/01/a-new-kind-of-science-indeed/#comments</comments>
		<pubDate>Wed, 07 Jan 2009 20:52:04 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Artificial Intelligence (AI)]]></category>
		<category><![CDATA[General Programming]]></category>

		<guid isPermaLink="false">http://www.jadbox.com/?p=787</guid>
		<description><![CDATA[ After reading Stephen Wolfram&#8217;s A New Kind of Science, I was impressed by the conjecture of the book (it has since been awarded several scientific awards), and I thought I would share here some musings I had after finishing it. The core ideology of the book is Reductionism which describes using simple programs to [...]


Related posts:<ol><li><a href='http://www.jadbox.com/2009/05/whats-new-doc/' rel='bookmark' title='Permanent Link: What&#8217;s New, Doc?'>What&#8217;s New, Doc?</a> <small> I have had some people asking me what I...</small></li>
<li><a href='http://www.jadbox.com/2009/03/further-reading-on-design-patterns/' rel='bookmark' title='Permanent Link: Further Reading on Design Patterns'>Further Reading on Design Patterns</a> <small>As a followup on my Wednesday lecture on design patterns,...</small></li>
<li><a href='http://www.jadbox.com/2009/07/engineering-2-0/' rel='bookmark' title='Permanent Link: Engineering 2.0'>Engineering 2.0</a> <small>One of major benefits of working with computers and internet-based...</small></li>
</ol>]]></description>
			<content:encoded><![CDATA[<p><img class="alignright size-large wp-image-788" title="51mdq4arggl" src="http://www.jadbox.com/wp-content/uploads/2009/01/51mdq4arggl-246x300.jpg" alt="51mdq4arggl" width="246" height="300" /> After reading Stephen Wolfram&#8217;s <strong><em><a href="http://en.wikipedia.org/wiki/A_New_Kind_of_Science" target="_new">A New Kind of Science</a></em></strong>, I was impressed by the conjecture of the book (it has since been awarded several scientific awards), and I thought I would share here some musings I had after finishing it. The core ideology of the book is <a href="http://en.wikipedia.org/wiki/Scientific_reductionism">Reductionism</a> which describes using simple programs to explain and reproduce complex systems that occur both in the virtual and physical world. As listed in the book, the definition of a &#8220;simple problem&#8221; is as follows:</p>
<ol>
<li>Its operation can be completely explained by a simple graphical illustration.</li>
<li>It can be completely explained in a few sentences of human language.</li>
<li>It can be implemented in a computer language using just a few lines of code.</li>
<li>The number of its possible variations is small enough so that all of them can be computed.</li>
</ol>
<p><span id="more-787"></span><br />
He explains complicated encryption, data compression, image recognition, turing machines, sociology and biology concepts, and other things with the use of simple programs that build complexity based on rules. These rules are applied to a pattern or the generation of a pattern based on each iteration step in its construction and its surrounding environment of steps. This is not something to dismiss lightly as it takes a clever mind to brake apart these systems into patters that can be logically broken down into a set of interlocking rules. <a href="http://en.wikipedia.org/wiki/Chaos_theory">Chaos Theory</a> is similar to this concept except that Chaos Theory states that the end result of a pattern must be derived or seeded by its environment. However, many of the pattern generation methods used by Stephen Wolfram ignore the initial condition of its environment when building its matrix. </p>
<p>On the other hand, if I had to play devil&#8217;s advocate, I do not see how some problems can be researched and developed using simple program patterns. I say this as these patterns are usually derived once one has observed a complex system and found its atomic pieces from understanding the whole structure. It would be like telling a group of people about a store that they have no idea how to get to and asking them to find it since they&#8217;ve been told what the store is like. They might be able to reach it by taking random directions, but it would not nearly be as efficient as having a detailed map with the location marked. Same thing applies here, how do you really hope to build a complex system with a simplistic set of rules when you lack the understanding of the complexity as a whole? On the other hand, perhaps the point that the author was trying to make is not how to understand the complex by solely its atomic parts, but how to simulate the complex once it has been fully understood using a simplistic set of instructions.</p>
<p>My personal interest in this subject ranges from several projects I am working on; however, I have been developing a neural network replacement mechanism for use in game simulations that would reduce processing overhead and generate a higher range of dynamic actions versus a simple AI weighted conditional system.</p>


<p>Related posts:<ol><li><a href='http://www.jadbox.com/2009/05/whats-new-doc/' rel='bookmark' title='Permanent Link: What&#8217;s New, Doc?'>What&#8217;s New, Doc?</a> <small> I have had some people asking me what I...</small></li>
<li><a href='http://www.jadbox.com/2009/03/further-reading-on-design-patterns/' rel='bookmark' title='Permanent Link: Further Reading on Design Patterns'>Further Reading on Design Patterns</a> <small>As a followup on my Wednesday lecture on design patterns,...</small></li>
<li><a href='http://www.jadbox.com/2009/07/engineering-2-0/' rel='bookmark' title='Permanent Link: Engineering 2.0'>Engineering 2.0</a> <small>One of major benefits of working with computers and internet-based...</small></li>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://www.jadbox.com/2009/01/a-new-kind-of-science-indeed/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Theory: AI Directives</title>
		<link>http://www.jadbox.com/2008/08/theory-ai-directives/</link>
		<comments>http://www.jadbox.com/2008/08/theory-ai-directives/#comments</comments>
		<pubDate>Fri, 08 Aug 2008 14:52:35 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Artificial Intelligence (AI)]]></category>
		<category><![CDATA[Game Development]]></category>
		<category><![CDATA[theory]]></category>

		<guid isPermaLink="false">http://www.jadbox.com/?p=248</guid>
		<description><![CDATA[I have been musing about the best practical way for giving NPCs (non player characters) a clear set of directives for living in its environment using simple AI logic. Based on the notion that any character&#8217;s environment is dynamic, en-queuing a character&#8217;s broad set of daily actions seems impractical. Instead, it would seem more logical [...]


Related posts:<ol><li><a href='http://www.jadbox.com/2009/06/flashmvc-2-0-released/' rel='bookmark' title='Permanent Link: FlashMVC 2.0 Released!'>FlashMVC 2.0 Released!</a> <small> I am very pleased to announce a major update...</small></li>
</ol>]]></description>
			<content:encoded><![CDATA[<p><img src="http://www.jadbox.com/wp-content/uploads/2008/08/stenstoutarm-189x300.jpg" alt="" title="NPC" width="189" height="300" class="alignleft size-medium wp-image-249" />I have been musing about the best practical way for giving <a href="http://en.wikipedia.org/wiki/Non-player_character" target="_blank">NPCs (non player characters)</a> a clear set of directives for living in its environment using simple <a href="http://en.wikipedia.org/wiki/Artificial_intelligence" target="_blank">AI</a> logic. Based on the notion that any character&#8217;s environment is dynamic, en-queuing a character&#8217;s broad set of daily actions seems impractical. Instead, it would seem more logical that a NPC is assigned a range of actions they are able or willing to perform and given a rule on when they are &#8216;prone&#8217; to each action based on different weights. For example, instead of having a NPC eat exactly three times a day, the NPC would have a hunger counter and when the value reached so high- they would seek out food. This would allow a higher dynamic range of actions for the character as they could eat more or less during the day based on things like how much physical activity they where doing or if they ate something that reduced their hunger for the next meal.</p>


<p>Related posts:<ol><li><a href='http://www.jadbox.com/2009/06/flashmvc-2-0-released/' rel='bookmark' title='Permanent Link: FlashMVC 2.0 Released!'>FlashMVC 2.0 Released!</a> <small> I am very pleased to announce a major update...</small></li>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://www.jadbox.com/2008/08/theory-ai-directives/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>JADRAD engine</title>
		<link>http://www.jadbox.com/2008/07/jadrad-engine/</link>
		<comments>http://www.jadbox.com/2008/07/jadrad-engine/#comments</comments>
		<pubDate>Thu, 31 Jul 2008 19:57:48 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Artificial Intelligence (AI)]]></category>
		<category><![CDATA[Game Development]]></category>
		<category><![CDATA[General Programming]]></category>
		<category><![CDATA[Showcase]]></category>

		<guid isPermaLink="false">http://www.jadbox.com/?p=54</guid>
		<description><![CDATA[I programmed these examples several years ago&#8230; I&#8217;ll edit this blog to explain more but JADRAD is rather impressive for a newbie start in game programming at the time.
This is an RPG engine I programmed using C++ libs and BlitzMax. It is all hand-made as I was doing it for learning purposes. This includes graphics [...]


Related posts:<ol><li><a href='http://www.jadbox.com/2009/04/haxe-vs-unity3d-vs-xna-vs-others/' rel='bookmark' title='Permanent Link: HaXe vs Unity3D vs XNA vs others'>HaXe vs Unity3D vs XNA vs others</a> <small>For the past couple months, I have been trying to...</small></li>
<li><a href='http://www.jadbox.com/2009/11/rise-of-the-languages/' rel='bookmark' title='Permanent Link: Rise of the languages'>Rise of the languages</a> <small>This month has been a very interesting/exciting for programmers of...</small></li>
</ol>]]></description>
			<content:encoded><![CDATA[
<a href="http://www.jadbox.com/wp-content/gallery/screenshots/jadrad_engine_by_dcaster.jpg" title="Screenshot from my Jadrad game engine" rel="lightbox[singlepic51]" >
	<img class="ngg-singlepic ngg-left" src="http://www.jadbox.com/wp-content/plugins/nextgen-gallery/nggshow.php?pid=51&amp;width=240&amp;height=&amp;mode=" alt="jadrad_engine_by_dcaster.jpg" title="jadrad_engine_by_dcaster.jpg" />
</a>
I programmed these examples <strong>several</strong> years ago&#8230; I&#8217;ll edit this blog to explain more but JADRAD is rather impressive for a newbie start in game programming at the time.</p>
<p>This is an RPG engine I programmed using C++ libs and BlitzMax. It is all hand-made as I was doing it for learning purposes. This includes graphics engine, AI, pathfinding, rpg system, map system, and more.<br />
<a href="http://www.jadbox.com/wp-content/uploads/2008/07/jadrad.zip">JADRAD RPG Engine</a> (ZIP &#8211; 3megs)</p>
<p>On the flip-side, here is another very very simple AI test for swarming:<br />
<a href="http://www.jadbox.com/wp-content/uploads/2008/07/aiants.zip">AIants</a> (ZIP &#8211; 600k)</p>

<div class="ngg-galleryoverview" id="ngg-gallery-3-54">

	<!-- Slideshow link -->
	<div class="slideshowlink">
		<a class="slideshowlink" href="http://www.jadbox.com/2008/07/jadrad-engine/?show=slide">
			[Show as slideshow]		</a>
	</div>

	
	<!-- Thumbnails -->
		
	<div id="ngg-image-51" class="ngg-gallery-thumbnail-box"  >
		<div class="ngg-gallery-thumbnail" >
			<a href="http://www.jadbox.com/wp-content/gallery/screenshots/jadrad_engine_by_dcaster.jpg" title="Screenshot from my Jadrad game engine" rel="lightbox[set_3]" >
								<img title="jadrad_engine_by_dcaster.jpg" alt="jadrad_engine_by_dcaster.jpg" src="http://www.jadbox.com/wp-content/gallery/screenshots/thumbs/thumbs_jadrad_engine_by_dcaster.jpg" width="100" height="75" />
							</a>
		</div>
	</div>
	
		
 		
	<div id="ngg-image-52" class="ngg-gallery-thumbnail-box"  >
		<div class="ngg-gallery-thumbnail" >
			<a href="http://www.jadbox.com/wp-content/gallery/screenshots/jadrad2.jpg" title="Screenshot from my Jadrad game engine" rel="lightbox[set_3]" >
								<img title="jadrad2.jpg" alt="jadrad2.jpg" src="http://www.jadbox.com/wp-content/gallery/screenshots/thumbs/thumbs_jadrad2.jpg" width="100" height="75" />
							</a>
		</div>
	</div>
	
		
 		
	<div id="ngg-image-53" class="ngg-gallery-thumbnail-box"  >
		<div class="ngg-gallery-thumbnail" >
			<a href="http://www.jadbox.com/wp-content/gallery/screenshots/jadrad3.jpg" title="Screenshot from my Jadrad game engine" rel="lightbox[set_3]" >
								<img title="jadrad3.jpg" alt="jadrad3.jpg" src="http://www.jadbox.com/wp-content/gallery/screenshots/thumbs/thumbs_jadrad3.jpg" width="100" height="75" />
							</a>
		</div>
	</div>
	
		
 		
	<div id="ngg-image-54" class="ngg-gallery-thumbnail-box"  >
		<div class="ngg-gallery-thumbnail" >
			<a href="http://www.jadbox.com/wp-content/gallery/screenshots/jadrad4.jpg" title="Screenshot from my Jadrad game engine" rel="lightbox[set_3]" >
								<img title="jadrad4.jpg" alt="jadrad4.jpg" src="http://www.jadbox.com/wp-content/gallery/screenshots/thumbs/thumbs_jadrad4.jpg" width="100" height="75" />
							</a>
		</div>
	</div>
	
		
 	 	
	<!-- Pagination -->
 	<div class='ngg-clear'></div>
 	
</div>



<p>Related posts:<ol><li><a href='http://www.jadbox.com/2009/04/haxe-vs-unity3d-vs-xna-vs-others/' rel='bookmark' title='Permanent Link: HaXe vs Unity3D vs XNA vs others'>HaXe vs Unity3D vs XNA vs others</a> <small>For the past couple months, I have been trying to...</small></li>
<li><a href='http://www.jadbox.com/2009/11/rise-of-the-languages/' rel='bookmark' title='Permanent Link: Rise of the languages'>Rise of the languages</a> <small>This month has been a very interesting/exciting for programmers of...</small></li>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://www.jadbox.com/2008/07/jadrad-engine/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Simple AI Flash test (old)</title>
		<link>http://www.jadbox.com/2008/07/simple-walking-ai-test-way-old/</link>
		<comments>http://www.jadbox.com/2008/07/simple-walking-ai-test-way-old/#comments</comments>
		<pubDate>Thu, 31 Jul 2008 19:30:37 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Artificial Intelligence (AI)]]></category>
		<category><![CDATA[Flash/Flex/AIR]]></category>
		<category><![CDATA[Showcase]]></category>
		<category><![CDATA[AI]]></category>
		<category><![CDATA[flash]]></category>

		<guid isPermaLink="false">http://www.jadbox.com/?p=39</guid>
		<description><![CDATA[This is a simple AI example that I had made for a speed programming challenge.


Related posts:<ol><li><a href='http://www.jadbox.com/2009/06/why-html-5-is-not-a-flash-killer/' rel='bookmark' title='Permanent Link: Why HTML 5 is NOT a Flash killer'>Why HTML 5 is NOT a Flash killer</a> <small>The RSS feeds are abuzz lately about the new W3C...</small></li>
</ol>]]></description>
			<content:encoded><![CDATA[<p><strong>This is a carry-over post from my last blog and is ages old.</strong></p>
<p>This application was created from scratch (without any 3rd party libraries) for a speed ActionScript 3 programming challenge. At the time, I have used AS2 but wanted to write this to see how well AS3 can utilize<br />
advanced class constructs and other methods found in today&#8217;s mature OOP languages.</p>
<p>It was great fun to write, and it truly illustrates the speed boost AS3 delivers!<br />
<span id="more-39"></span></p>
<p>Version 0.85:</p>
<p>* Separation between NPC class and document class more defined<br />
* +25% Speed increase<br />
* NPCs now have sprite animations depending on the current state.</p>
<p>AS3 Demo &#8211; SWF<br />
Modified: June 27, 2007: 3:10pm</p>
<p>[kml_flashembed movie="http://www.jadbox.com/wp-content/uploads/2008/07/jd_as3demo.swf" height="400" width="550" /]</p>
<p>MainAI.as<br />
Modified: June 27, 2007: 3:10pm</p>
<pre lang="actionscript">
// Demonstration (c) to Jonathan A Dunlap

// jonathanadunlap@gmail.com

package {

import flash.display.*;

import flash.text.TextField;

import flash.events.*;

import flash.utils.*;

public class MainAI extends MovieClip { // Main game initialization

public var group:Array = new Array();

public var game:Sprite = new Sprite();

public function MainAI():void {

game.blendMode = BlendMode.MULTIPLY;

this.stop();addChild(game); // General starters

for (var i:int=0; i &lt; 20; i++) create_npc();

addEventListener(Event.ENTER_FRAME, ai_handler);

setInterval(create_npc, 1050);

}

public function create_npc():void {group.push(new npc(this.game));}

public function ai_handler(evt:Event):void { // Handle NPC movement and collision

for(var i:int=0;i&lt;group.length-1;i++){

if (group[i]!=null &amp;&amp; !group[i].is_saying_hello()) {

group[i].action();

for(var o:int=i+1;o&lt;group.length;o++)

if (group[o]!=null &amp;&amp; o != i &amp;&amp; group[i].distanceToNpc(group[o])&lt;=65 )

if(group[i].hitTestObject(group[o])) {

group[i].revert();group[o].revert();

group[i].actionMoveAway(group[o]);

group[o].actionMoveAway(group[i]);

group[i].actionSayHi();

}

if(group[i].alpha &lt;= 0) { // Delete NPCs will several collisions

group[i].del();

group[group.indexOf(group[i])]=null; // Remove reference to object to clean memory

group.splice(group.lastIndexOf(null),1); // Clean up array

}

}

}

}

}

}

npc.as
Modified: June 27, 2007: 3:10pm

// See MainAI.as for notes.

//

// Tip: NPC stands for Non-Player Character

//

package {

import flash.display.*;

import flash.text.TextField;

import flash.events.TimerEvent;

import flash.utils.*;

public class npc extends MovieClip { // Initialize NPC unit

private var toy:int, tox:int,oldx:int,oldy:int,targetTimer:Timer,myparent:DisplayObjectContainer;

public const stateWonder:int=0;public const stateSayHi:int=1;

public function npc(aparent:DisplayObjectContainer):void {

myparent = aparent;

myparent.addChild(this);

this.blendMode = BlendMode.DARKEN;

this.posx = rand(this.poswidth,stage.stageWidth-this.poswidth);

this.posy = rand(this.posheight,stage.stageHeight-this.posheight);

targetTimer = new Timer(1800, 0);

targetTimer.addEventListener("timer", findtarget);

targetTimer.start();

}

public function action():void {

this.followWavePoint();

}

private function followWavePoint():void {

var oldx:int = this.posx;

this.posx -=point_axis_dist(this.x, this.tox, 5);

if(oldx==this.x) this.posy -= point_axis_dist(this.y, this.toy, 5);

}

private function point_axis_dist(axis1:int,axis2:int,distance:int):int
{ // Find if NPC is roughly on the correct traveling path

var subaxis:int = axis1-axis2;

var absaxis:int = Math.abs(subaxis);

if(absaxis &gt;= distance) {if(absaxis==subaxis) return 1; else return -1;}

return 0;

}

public function del():void {

this.targetTimer.stop();

this.myparent.removeChild(this);

}

public function get poswidth():int {

return this.width/2;

}

public function get posheight():int {

return this.height/2;

}

public function findtarget(event:TimerEvent):void { // Find a new random location to travel to

this.tox = rand(this.poswidth,stage.stageWidth-this.poswidth);

this.toy = rand(this.posheight,stage.stageHeight-this.posheight);

}

public function actionSayHi():void {

this.alpha -= 0.25;

this.bump_say();

}

public function actionMoveAway(offender:npc):void {

if(Math.random() &lt; 0.5) {

if(this.x &gt;= offender.x) this.tox += this.width*2;

else if(this.x &lt; offender.x) this.tox -= this.width*2;

} else {

if(this.y &gt;= offender.y) this.toy += this.height*2;

else if(this.y &lt; offender.y) this.toy -= this.height*2;

}

}

public function revert():void {

this.posx = this.oldx;this.posy=this.oldy;

}

public function set posx(x:int):void{

if(x &gt; stage.stageWidth-this.poswidth) x = stage.stageWidth-this.poswidth;

else if(x &lt; this.poswidth) x = this.poswidth;

else if(x &lt; this.x) this.walk_left();

else if(x &gt; this.x) this.walk_right();

this.oldx = this.x;

this.x = x;

}

public function set posy(y:int):void{

if(y &gt; stage.stageHeight-this.posheight) y = stage.stageHeight-this.posheight;

else if(y &lt; this.posheight) y = this.posheight;

else if(y &lt; this.y) this.walk_up();

else if(y &gt; this.y) this.walk_down();

this.oldy = this.y;

this.y = y;

}

public function get posx():int{return this.x;}

public function get posy():int{return this.y;}

private function walk_left():void{ // NPC animation trigger states

if(this.currentFrame &lt; 24 || this.currentFrame &gt; 34) this.gotoAndPlay(24);

}

private function walk_right():void{

if(this.currentFrame &lt; 35 || this.currentFrame &gt; 45) this.gotoAndPlay(35);

}

private function walk_down():void{

if(this.currentFrame &gt; 12) this.gotoAndPlay(1);

}

private function walk_up():void{

if(this.currentFrame &lt; 13 || this.currentFrame &gt; 23) this.gotoAndPlay(13);

}

private function bump_say():void{

this.gotoAndPlay(46)

}

public function is_saying_hello():Boolean{

if(this.currentFrame &gt; 45 &amp;&amp; this.currentFrame &lt; 57) return true;

return false;

}

public function distanceToNpc(other:npc):int {

return Math.abs(this.x-other.x)+Math.abs(this.y-other.y);

}

private function rand(min:int, max:int):int

{

return min + Math.floor(Math.random() * (max - min + 1));

}

private namespace npcNS;

}

}</pre>


<p>Related posts:<ol><li><a href='http://www.jadbox.com/2009/06/why-html-5-is-not-a-flash-killer/' rel='bookmark' title='Permanent Link: Why HTML 5 is NOT a Flash killer'>Why HTML 5 is NOT a Flash killer</a> <small>The RSS feeds are abuzz lately about the new W3C...</small></li>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://www.jadbox.com/2008/07/simple-walking-ai-test-way-old/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
