<?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>Binary Thought &#187; Design</title>
	<atom:link href="http://www.rebz.org/category/design/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.rebz.org</link>
	<description>Scratching the surface of my mind.</description>
	<lastBuildDate>Mon, 09 Aug 2010 00:40:23 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<item>
		<title>Basic AI: Building a Finite State Machine (FSM) in C#</title>
		<link>http://www.rebz.org/2010/02/basic-ai-building-a-finite-state-machine-fsm-in-c/</link>
		<comments>http://www.rebz.org/2010/02/basic-ai-building-a-finite-state-machine-fsm-in-c/#comments</comments>
		<pubDate>Fri, 19 Feb 2010 05:39:39 +0000</pubDate>
		<dc:creator>Michael</dc:creator>
				<category><![CDATA[A.I.]]></category>
		<category><![CDATA[Code]]></category>
		<category><![CDATA[Design]]></category>
		<category><![CDATA[Games]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[fsm]]></category>
		<category><![CDATA[xna]]></category>

		<guid isPermaLink="false">http://www.rebz.org/?p=154</guid>
		<description><![CDATA[I figured this information may benefit a few people, as well as allow me to get my thoughts out, I&#8217;ll be documenting the process to building a finite state machine (FSM). My main use out of this project will allow me to assign an object a FSM, assign that object specific states, and allow the [...]]]></description>
			<content:encoded><![CDATA[<p>I figured this information may benefit a few people, as well as allow me to get my thoughts out, I&#8217;ll be documenting the process to building a finite state machine (FSM). My main use out of this project will allow me to assign an object a FSM, assign that object specific states, and allow the object to make weighted decisions through a transition table. I plan on using this decision-system to aid in both creating a foundation for the AI of my games, as well as aid in the animation systems that I concoct.</p>
<p><span id="more-154"></span></p>
<h3>Intro</h3>
<p>When creating an A.I. system for your game, you&#8217;re going to want objects to be able to make decisions on their own, or at the very least have some sort of flowchart-like interaction. What if you were able to easily set up those basic interactions, and simply have your objects detect when certain stimuli change their states, and have actions and reactions dependent on the states of an object? We can create seemingly more intelligent objects, and a potentially more immersive game.</p>
<h3>The Individual State</h3>
<p>Each of the states in our machine will have the following information:</p>
<ul>
<li>State Name</li>
<li>Minimum Duration</li>
<li>Maximum Duration</li>
<li>Transitions</li>
</ul>
<p>This way, we can define the state with a human name that would make sense to a designer and something that could be easily scripted, and we can specify a range at which the state can last. With random state lengths, we can make objects seem a bit more organic. For objects that we need specific lengths, we can simply set the two to equal each other! Lastly, we need to know all the different states into which an individual state can transition.</p>
<h3>The Transition Table</h3>
<p>Each State will carry it&#8217;s own &#8220;Transition Table&#8221;, will include two important bits of information per entry:</p>
<ul>
<li>State Name</li>
<li>Weighted Percentage</li>
</ul>
<p>This way, we know which state we are going to transition to, and we are going to allow the definition of a weighted percentage of the states that are chosen. This will allow us to introduce rarity with our transitions.</p>
<h3>The Machine</h3>
<p>Our FSM will have several important actions which we will need to consider:</p>
<p style="padding-left: 30px;"><strong>Add State</strong></p>
<p style="padding-left: 30px;">After our FSM is created for an individual object, we will add the different states that will be valid for this particular object. We will give the option to add a min/max duration of the state, in case we want to attempt to make certain states less predictable than others.</p>
<p style="padding-left: 30px;"><strong>Remove </strong><strong>State</strong></p>
<p style="padding-left: 30px;">We may see a need to remove a state from our object. Consider  enemies that after being provoked will not stop engaging/attacking the player until they kill the player or are destroyed themselves. We could get this feature &#8216;automatically&#8217; if we removed the idle state from this object, and any transitions that may have brought us to this state.</p>
<p style="padding-left: 30px;"><strong>Add Transition</strong></p>
<p style="padding-left: 30px;">In order for a state to transition from one state to the next, we are going to want to add these connections in individually, with a weighted percentage at which they have the possibility of being picked. This can allow for balancing the choosing of states. We will also have this action update transition if it already exists in the table.</p>
<p style="padding-left: 30px;"><strong>Remove Transition</strong></p>
<p style="padding-left: 30px;">We may want to implement conditional transitions, or remove transitions for states that no longer exist.</p>
<p style="padding-left: 30px;"><strong>Set State</strong></p>
<p style="padding-left: 30px;">For setting an initial state on our object, or forcing the object into a specific state.</p>
<p style="padding-left: 30px;"><strong>Choose Next State</strong></p>
<p style="padding-left: 30px;">When the current state expires, the FSM will need to select a transition and set the next state</p>
<p style="padding-left: 30px;">
<h3>Usage</h3>
<p>Usage is fairly simple. You&#8217;ll first want to include the code in your Solution. To every object file you wish to use the FiniteStateMachine in, you need to add a:</p>
<pre class="brush:csharp">using Zapdot;</pre>
<p>At the header with your other using statements.</p>
<p>You will then want to add a class level variable.</p>
<pre class="brush:csharp">class Enemy
{
   FiniteStateMachine mFSM;

   public Enemy()
   {
      setupStateMachine();
   }
}</pre>
<p>Now, for tidiness-sake, create a method that you&#8217;ll use to store the setup for this particular object, to be called once during initialization.</p>
<pre class="brush:csharp"> private void setupStateMachine()
 {
 mFSM = new FiniteStateMachine();
 mFSM.AddState("idle", 2, 3);
 mFSM.AddState("walk", 2, 2);
 mFSM.AddState("run", 1, 3);
 mFSM.AddTransition("idle", "walk", .5);
 mFSM.AddTransition("idle", "run", .5);
 mFSM.AddTransition("walk", "idle", .5);
 mFSM.AddTransition("walk", "run", .5);
 mFSM.AddTransition("run", "idle", .5);
 mFSM.AddTransition("run", "walk", .5);
 // Pick our first state.
 mFSM.SetState("idle");
 }</pre>
<p>This instantiates the new object, and adds three states to the Enemy object. (&#8220;walk&#8221;, &#8220;run&#8221;, and &#8220;idle&#8221;). Both idle and run will have random time between their respective min and maximums, but walk will always be 2 seconds long, no matter what.</p>
<p>We then add the transitions for these states, essentially saying that every state can transition to the other, and that they have equal weight to do so.</p>
<p>Lastly, we tell the object what state to start in.</p>
<p>After this object is setup, we can add it to our update class:</p>
<pre class="brush:csharp">mFSM.Update(gameTime);</pre>
<p>And do some tests on it to affect gameplay.</p>
<pre class="brush:csharp">if ( mFSM.CurrentState.Equals("idle") )
   mVelocity = kIdleSpeed;</pre>
<p>And so on.</p>
<h3>The Code</h3>
<p><a href="http://www.rebz.org/wp-content/uploads/2010/02/FiniteStateMachine.zip">Download</a> (MIT License)</p>
<p>The code is available below, and being released under the MIT License. Feel free to do whatever you want with it, just don&#8217;t blame me. <img src='http://www.rebz.org/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p>If for some crazy reason you do start using the code, please tell me what you think, or what cool things you&#8217;re doing with it. <img src='http://www.rebz.org/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<h3>Future Additions!</h3>
<p>This is only the starting point from here, and I hope to be able to add much more. Future additions include wonderful things like multiple concurrent states to give a little more depth to our objects and add for some interesting decision-making!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.rebz.org/2010/02/basic-ai-building-a-finite-state-machine-fsm-in-c/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>When functionality supercedes mimicry</title>
		<link>http://www.rebz.org/2009/06/when-functionality-supercedes-mimicry/</link>
		<comments>http://www.rebz.org/2009/06/when-functionality-supercedes-mimicry/#comments</comments>
		<pubDate>Sat, 13 Jun 2009 13:00:39 +0000</pubDate>
		<dc:creator>Michael</dc:creator>
				<category><![CDATA[Design]]></category>
		<category><![CDATA[google]]></category>
		<category><![CDATA[opinion]]></category>

		<guid isPermaLink="false">http://www.rebz.org/?p=120</guid>
		<description><![CDATA[In watching the presentation for Google Wave, a new product in the works by Google, a feature that was demonstrated (and applauded) made me question when designing features for users undoes some of the benefits that individual terminals affords the user. For those of you who don’t know, Google Wave is aiming to be the [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.rebz.org/wp-content/uploads/2009/06/google-wave-logo.jpg"><img class="size-thumbnail wp-image-125 alignleft" style="margin: 5px 10px;" title="Google Wave Logo" src="http://www.rebz.org/wp-content/uploads/2009/06/google-wave-logo-150x150.jpg" alt="Google Wave Logo" width="150" height="150" /></a>In watching the presentation for Google Wave, a new product in the works by Google, a feature that was demonstrated (and applauded) made me question when designing features for users undoes some of the benefits that individual terminals affords the user.</p>
<p>For those of you who don’t know, Google Wave is aiming to be the next evolution of online communication. From what I have seen so far, it seems to be a consummation of email, message boards, and chat, forcing users to no longer think of online communication as individual collections of messages and responses, but a cluster of ongoing conversations, where individuals can enter and leave at will.</p>
<p>The feature that piqued my interest, was the feature that turns the conversation into a chat, and allows both users to see the conversations being typed by each other in real time. While this could be very useful for conversing with someone who typed painfully slowly, it changes the way users have generally used instant messaging up until now.</p>
<p>Instant Messaging serves as a platform to allow generally, two people to have a conversation with each other in “real time”, where one user sends a message, the other responds, etc, in the same way that you and I may have a face-to-face conversation. If you wanted to map the features one-to-one, then while you are talking to me in person, I will be listening to your statement, and thinking about what I want to say in response, this is the same as reading your message in an IM, and typing my response in my client.</p>
<p>However, lets say you and I are having an in-depth conversation, or debate, on either medium. We make take our time to collect our thoughts, to consider our responses, and figure out what we want to say next. We may even completely change our response we had originally planned in order to answer some new topic that has come up. Either way, this can be afforded to us in IM clients by typing out our responses and looking them over before we send them off.</p>
<p>While I agree that when talking to someone over instant message, the time waiting for a response can seem length. However, almost all clients today will notify the receiving person that you are typing, alerting that there is indeed a conversation taking place. The question begs then, how do users react to a feature that allows us to see the response of a person, as it is being created?</p>
<p>While this is an interesting feature in it of itself, it could do one of a few things:</p>
<ul>
<li>Bring users closer to the experience of having a true conversation through text.</li>
<li>Users would be distracted by the other person typing a response, or follow up message to what they just sent, and it would cause confusion.</li>
<li>A new rule of “internet etiquette” would appear within the use of this tool, and you would patiently wait for others to finish their thought before you start typing your response.</li>
</ul>
<p>Google will offer a checkbox to turn this feature off, and it will be interesting to see how the response to this feature is received. Within innovation, one will ultimately be forcing adopters to rethink or retool their processes in order to adopt a new technology. It&#8217;s important to consider what the processes you are &#8220;fixing&#8221;, because maybe they weren&#8217;t broken, but a matter of course from the translation of a process from one medium to the next.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.rebz.org/2009/06/when-functionality-supercedes-mimicry/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>
