<?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>Raelifin.com &#187; Code</title>
	<atom:link href="http://raelifin.com/category/code/feed/" rel="self" type="application/rss+xml" />
	<link>http://raelifin.com</link>
	<description>Deus ex Machina</description>
	<lastBuildDate>Thu, 26 Apr 2012 22:59:13 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	
		<item>
		<title>I&#8217;ll Just Leave This Here</title>
		<link>http://raelifin.com/code/ill-just-leave-this-here/</link>
		<comments>http://raelifin.com/code/ill-just-leave-this-here/#comments</comments>
		<pubDate>Thu, 26 Apr 2012 22:59:13 +0000</pubDate>
		<dc:creator>Raelifin</dc:creator>
				<category><![CDATA[Code]]></category>
		<category><![CDATA[AI]]></category>
		<category><![CDATA[Cool Stuff]]></category>
		<category><![CDATA[java]]></category>
		<category><![CDATA[khanacademy]]></category>
		<category><![CDATA[OCR]]></category>
		<category><![CDATA[statistics]]></category>

		<guid isPermaLink="false">http://raelifin.com/?p=1198</guid>
		<description><![CDATA[Full rundown, including code, to come sometime in the future. (Probably.)]]></description>
			<content:encoded><![CDATA[<p><iframe width="420" height="315" src="http://www.youtube.com/embed/y_pTU1lp0R8" frameborder="0" allowfullscreen></iframe></p>
<p>Full rundown, including code, to come sometime in the future. (Probably.)</p>
]]></content:encoded>
			<wfw:commentRss>http://raelifin.com/code/ill-just-leave-this-here/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>First Flash Project</title>
		<link>http://raelifin.com/code/first-flash-project/</link>
		<comments>http://raelifin.com/code/first-flash-project/#comments</comments>
		<pubDate>Mon, 05 Mar 2012 22:58:25 +0000</pubDate>
		<dc:creator>Raelifin</dc:creator>
				<category><![CDATA[Code]]></category>
		<category><![CDATA[actionscript]]></category>
		<category><![CDATA[chess]]></category>
		<category><![CDATA[flash]]></category>
		<category><![CDATA[game]]></category>
		<category><![CDATA[programming]]></category>

		<guid isPermaLink="false">http://raelifin.com/?p=1181</guid>
		<description><![CDATA[Once upon a time Adobe Flash was locked down. To make anything in flash you had to either buy or steal Adobe&#8217;s software to do anything with it. Nowadays though it seems that has changed. Using nothing but free software from FlashDevelop and GreenSock. I was able to build this chess software in about eight [...]]]></description>
			<content:encoded><![CDATA[<p>Once upon a time Adobe Flash was locked down. To make anything in flash you had to either buy or steal Adobe&#8217;s software to do anything with it. Nowadays though it seems that has changed. Using nothing but free software from <a href="http://www.flashdevelop.org/">FlashDevelop</a> and <a href="http://www.greensock.com/tweenlite/">GreenSock</a>. I was able to build this chess software in about eight hours (knowing nothing about ActionScript at the start):</p>
<p><iframe src="http://raelifin.com/files/ChessInFlash/bin/" width="450" height="450"></iframe></p>
<p>The source code is public domain (except for GreenSock&#8217;s stuff, which is Copyright, and you&#8217;ll have to download from them), and can be downloaded here: <a href="http://raelifin.com/files/ChessInFlash/ChessInFlashSource.zip">http://raelifin.com/files/ChessInFlash/ChessInFlashSource.zip</a></p>
]]></content:encoded>
			<wfw:commentRss>http://raelifin.com/code/first-flash-project/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>K-Means Clustering in J</title>
		<link>http://raelifin.com/code/k-means-clustering-in-j/</link>
		<comments>http://raelifin.com/code/k-means-clustering-in-j/#comments</comments>
		<pubDate>Thu, 26 May 2011 17:06:34 +0000</pubDate>
		<dc:creator>Raelifin</dc:creator>
				<category><![CDATA[Code]]></category>
		<category><![CDATA[clustering]]></category>
		<category><![CDATA[J]]></category>
		<category><![CDATA[k-means]]></category>
		<category><![CDATA[perception]]></category>

		<guid isPermaLink="false">http://raelifin.com/?p=1106</guid>
		<description><![CDATA[Perception is essentially the problem of extracting high-level patterns from large amounts of raw-data (from sensors). Correctly recognizing the pattern/shape &#8220;dog&#8221; in a bitmap is one example of a tricky perceptual task. Note that the symbol &#8220;dog/not dog&#8221; is much less information than the raw image data. This compression is vital for being able to [...]]]></description>
			<content:encoded><![CDATA[<p>Perception is essentially the problem of extracting high-level patterns from large amounts of raw-data (from sensors). Correctly recognizing the pattern/shape &#8220;dog&#8221; in a bitmap is one example of a tricky perceptual task. Note that the symbol &#8220;dog/not dog&#8221; is much less information than the raw image data. This compression is vital for being able to do quick computations further on in the mental process (&#8220;if tiger: run&#8221; is a good example of a conditional that depends on very abstract patterns for both tigers and running).</p>
<p>If we imagine that each sensor is a dimension, then we can say that distinguishing between images of dogs and not-dogs is a matter of partitioning a multidimensional input-space into two areas. Perception in animals is (almost?) never guided by top-down labels, though; animals learn *common* patterns/shapes, and then use these patterns in higher-cognition.</p>
<p><span id="more-1106"></span></p>
<p>Finding common patterns in an input space is the problem of <strong>clustering</strong>. Consider the following graph:<br />
<img src="http://raelifin.com/files/pics/AnimalClusters.png" alt="Animals by Mass and Number of Eyes" /><br />
We can create 4 clusters which (due to outside knowledge) we can loosely associate with labels we&#8217;ve learned previously.</p>
<p>There are many algorithms that will do this sort of clustering task, but perhaps the simplest is <a href="http://en.wikipedia.org/wiki/K-means_clustering">K-Means</a>. Yesterday I built a K-Means clusterer in <a href="http://www.jsoftware.com/">J</a>. It picks initial cluster-centers using <a href="http://en.wikipedia.org/wiki/K-means%2B%2B">K-Means++</a>, and can scale to any number of dimensions. Here is is, chopping a bunch of random points spread over a circle into seven clusters (diamonds indicate the centroids a.k.a. &#8220;means&#8221;):<br />
<img src="http://raelifin.com/files/pics/CircleClusters.png"/></p>
<p><a href="https://github.com/Raelifin/K-Means-Clustering-in-J/blob/master/k-meansClustering.ijs">Here is the code on GitHub.</a> Everything is public domain. No need to provide credit.</p>
]]></content:encoded>
			<wfw:commentRss>http://raelifin.com/code/k-means-clustering-in-j/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Nyx</title>
		<link>http://raelifin.com/code/nyx/</link>
		<comments>http://raelifin.com/code/nyx/#comments</comments>
		<pubDate>Wed, 30 Mar 2011 17:16:57 +0000</pubDate>
		<dc:creator>Raelifin</dc:creator>
				<category><![CDATA[Code]]></category>
		<category><![CDATA[cardgame]]></category>
		<category><![CDATA[game]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[Nyx]]></category>

		<guid isPermaLink="false">http://raelifin.com/?p=987</guid>
		<description><![CDATA[I don&#8217;t usually post projects that are only mostly done, but I wanted to get this off my plate. It&#8217;s a simple cardgame built entirely in javascript called Nyx (after the Greek goddess). Each turn consists of both players secretly choosing an action. Actions consist of either drawing two cards, or playing a card. There [...]]]></description>
			<content:encoded><![CDATA[<p>I don&#8217;t usually post projects that are only mostly done, but I wanted to get this off my plate. It&#8217;s a simple cardgame built entirely in javascript called Nyx (after the Greek goddess). Each turn consists of both players secretly choosing an action. Actions consist of either drawing two cards, or playing a card.</p>
<p><a href="http://raelifin.com/files/Nyx_1/screenshot.png"><img src="http://raelifin.com/files/Nyx_1/screenshot.png" style="width: 540px"/></a></p>
<p>There are a few bugs, and it&#8217;s not at all &#8220;balanced&#8221;, but it&#8217;s mostly playable, and pretty intuitive (IMO). It&#8217;s written in HTML5, so unless you&#8217;re using Google Chrome, I can&#8217;t guarantee it&#8217;ll render properly.</p>
<p>Play it here: <a href="http://raelifin.com/files/Nyx_1/">http://raelifin.com/files/Nyx_1/</a><br />
Download it here: <a href="http://raelifin.com/files/Nyx_1/Nyx.tar.gz">http://raelifin.com/files/Nyx_1/Nyx.tar.gz</a></p>
<p>I may work on it in the future, if I get the urge. Right now I&#8217;m focused on my non-game studies, though, and I was afraid that this would just get thrown on the pile of unpublished code I have lying around.</p>
]]></content:encoded>
			<wfw:commentRss>http://raelifin.com/code/nyx/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Welcome to the Prisidium</title>
		<link>http://raelifin.com/code/welcome-to-the-prisidium/</link>
		<comments>http://raelifin.com/code/welcome-to-the-prisidium/#comments</comments>
		<pubDate>Mon, 14 Mar 2011 15:28:14 +0000</pubDate>
		<dc:creator>Raelifin</dc:creator>
				<category><![CDATA[Code]]></category>
		<category><![CDATA[communication]]></category>
		<category><![CDATA[interfaces]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[Mass Effect]]></category>

		<guid isPermaLink="false">http://raelifin.com/?p=933</guid>
		<description><![CDATA[Looks like you can&#8217;t see the iframe content. Perhaps you&#8217;re not on the blog? P.S. This post is so tall because the code is in an iframe. The code could easily integrate as a library, and I could then make this a normal post, but I want it to be encapsulated for now.]]></description>
			<content:encoded><![CDATA[<p><iframe src="http://raelifin.com/files/VIIT.html" width="540" height="540">
<p>Looks like you can&#8217;t see the iframe content. Perhaps you&#8217;re not on <a href="http://raelifin.com/thoughts/welcome-to-the-prisidium/">the blog</a>?</p>
<p></iframe></p>
<p>P.S. This post is so tall because the code is in an iframe. The code could easily integrate as a library, and I could then make this a normal post, but I want it to be encapsulated for now.</p>
]]></content:encoded>
			<wfw:commentRss>http://raelifin.com/code/welcome-to-the-prisidium/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Simple Rationality</title>
		<link>http://raelifin.com/code/simple-rationality/</link>
		<comments>http://raelifin.com/code/simple-rationality/#comments</comments>
		<pubDate>Thu, 03 Mar 2011 11:03:35 +0000</pubDate>
		<dc:creator>Raelifin</dc:creator>
				<category><![CDATA[Code]]></category>
		<category><![CDATA[Cognition]]></category>
		<category><![CDATA[AI]]></category>
		<category><![CDATA[Haskell]]></category>
		<category><![CDATA[heuristics]]></category>
		<category><![CDATA[rationality]]></category>
		<category><![CDATA[recursion]]></category>
		<category><![CDATA[utility]]></category>

		<guid isPermaLink="false">http://raelifin.com/?p=804</guid>
		<description><![CDATA[I don&#8217;t know why it&#8217;s taken me so long to post this. Several weeks ago I was playing a turn-based fighting game that I love, and I got to thinking &#8220;what would an AI that plays this game well look like?&#8221; And as I thought about it, it became clear to me that the challenge [...]]]></description>
			<content:encoded><![CDATA[<p>I don&#8217;t know why it&#8217;s taken me so long to post this. Several weeks ago I was playing <a href="http://www.kongregate.com/games/Kongregate/kongai">a turn-based fighting game that I love</a>, and I got to thinking &#8220;what would an AI that plays this game well look like?&#8221; And as I thought about it, it became clear to me that the challenge of playing a complex game is the same as reaching goals in any sufficiently understood environment.</p>
<p>Let me elaborate on that last point, because I think it&#8217;s important. Most of what artificial intelligence, as a field, focuses on (and rightly so) is building a model of an environment. This learning involves taking raw sensory data and turning (or rather, integrating) it into a set of concepts and relationships. But with the simple case of a game, we don&#8217;t really need to learn what the rules are, or learn how to take actions; we can focus entirely on how to play well.</p>
<p><span id="more-804"></span></p>
<p>Playing well involves maximizing a value, which depends on the game. In poker, this value is &#8220;money owned&#8221;, while in chess it&#8217;s &#8220;enemy kings captured*&#8221;. (In chess, the game never progresses to the point where any kings are captured, but as far as goals are concerned, checkmating the king is identical to capturing it.) Another way of putting this is to point out that each game has a distinct <strong>goal</strong>. Playing well involves maximizing the degree to which this goal is met, which I will call &#8220;<strong>utility</strong>&#8220;.</p>
<p style="color: #777">* &#8211; It&#8217;s technically a little bit more complicated than that, because it&#8217;s possible to stalemate, and that&#8217;s not as bad as an outright loss.</p>
<p>So, when presented with several possible &#8220;moves&#8221; in a game, we want to pick the move that has the highest utility. I call this searching and choosing &#8220;being rational&#8221;. To make a game-playing AI then, I needed to build a Rational Agent.</p>
<p>To be a bit more formal about the agent&#8217;s task, it must output a move when given:
<ul>
<li>A &#8220;state&#8221; where it currently is.</li>
<li>A &#8220;rulebook&#8221; (a.k.a. model) for how the game works, including what moves can be made at the given state.</li>
<li>A utility function that, given a state, returns the degree to which it meets a goal.</li>
</ul>
<p>The utility function is conceptually separate for me from the rulebook, as it specifies exactly what this agent &#8220;cares about&#8221;, where the rules are objective and unchanging regardless of who you are. (Example: the rulebook for chess doesn&#8217;t tell you which player you are.) Another reason that I think of them as conceptually distinct is because as I&#8217;m defining the utility function, it is <em>agnostic to consequences</em>. This is a fancy way of saying that the utility function doesn&#8217;t pay attention to what might happen next; it&#8217;s firmly grounded in the &#8220;present&#8221; (i.e. whatever state it&#8217;s given). Because of this agnosticism, it doesn&#8217;t actually rely on any information about game dynamics (rules).</p>
<p>The job of considering consequences is exactly what the Rational Agent is built to do. It takes each action in turn and finds the utility of its immediate consequences, then adds the utility of the next state, and the utility of next&#8230; etc. In other words, it is the limit of the infinite sum of the utility function from t=0 to infinity.</p>
<p>Or at least, it would be if it were a PERFECTLY rational agent. The unfortunate reality (from a math perspective) is that most systems are chaotic enough that it is damn near impossible (and sometimes just plain impossible) to take such an integral. As an example, consider a game (like chess or whatever) where the rule is that your opponent will play exactly as you would in the other position. If you try and compute the consequences of an action, you have to consider the moves of the opponent, which will involve considering your moves, to an infinite regression.</p>
<p>I <a href="http://raelifin.com/thoughts/recursive-escapades/">wrote a post</a> on this problem several weeks ago. It had some fancy math that lets some infinite regressions be solved, but I couldn&#8217;t figure out any fancy tricks that worked for all situations. I intuitively don&#8217;t think it makes much sense trying to compute the limits, either. If I&#8217;m resigned to building an agent that is not perfectly rational, but is only somewhat rational, than I can simply say that at some point the agent stops recursively &#8220;imagining&#8221; the future, and works on the approximate sum.</p>
<p>The problem with this, however, is that many games are not won until very late (a.k.a. after many moves). Consider a game I invented to test my agent:</p>
<blockquote><h2 style="margin-bottom: 2px; padding-bottom: 0px;">Counting</h2>
<h3 style="padding-top: 0px;">or perhaps &#8220;Lineland Treasurehunt&#8221;</h3>
<p>You are at a position, and your goal is to get to another position. Possible moves are &#8220;walk forward&#8221; and &#8220;walk backwards&#8221;. Oh, and the spot you start at is called &#8220;0&#8243; and the goal spot is called &#8220;100&#8243;. Each time you walk forward your position increases by one, and each time you walk backward, it decreases by one.</p></blockquote>
<p>The problem is that, as defined, there&#8217;s no base utility in being at &#8220;99&#8243; over &#8220;0&#8243;. The only utility in being at &#8220;99&#8243; is in the consequence of being able to go to &#8220;100&#8243; on the next turn. If each step is a move, then the agent needs to model 100 moves in the future to have any clue what to do. Now, imagine how many moves one would need to look-ahead in order to see a victory in chess. For a perfectly rational agent it&#8217;s a mathematical possibility, but for something that can be written in code it&#8217;s just impractically beyond the maximum recursion depth.</p>
<p>The only way an agent with a maximum look-ahead of 5 moves can beat the Counting game is to get the hint &#8220;high numbers are better than low ones&#8221;. According to the rules, this is not intrinsically true, but it&#8217;s an approximation of truth that allows the agent to perform under normal circumstances. It is a <em>heuristic</em>, and it is of vital importance.</p>
<p>To be more precise, a heuristic is a component of the utility function that has been added because it is a good approximation of future utility (i.e. the goal). Some heuristics in chess are &#8220;control the center of the board&#8221;, &#8220;capture (non-king) pieces&#8221;, and &#8220;threaten many squares&#8221;. Clearly you don&#8217;t want to focus on doing any of these if you have the opportunity to checkmate, but because checkmating takes time, it&#8217;s cognitively easier to aim for any of these more apparent mini-goals.</p>
<p>The learning of heuristics seems like the most important aspect of practical rationality, and it&#8217;s something I&#8217;m looking forward to thinking about more. It seems plausible to me that the emotion of happiness in humans may be a heuristic-encoding signal. When we&#8217;re happy or sad, we say &#8220;What&#8217;d I just do? Remember presence/absence of that as a heuristic!&#8221;. Just speculating&#8230;</p>
<p>Here&#8217;s my rational agent in Haskell: <a href="http://raelifin.com/files/code/rationality.tar.gz">http://raelifin.com/files/code/rationality.tar.gz</a></p>
<p>(I also wrote a version in Java with many more example games, but I&#8217;m working on tuning that, and it&#8217;s not really suitable for posting at the moment. The Haskell is also much cleaner/prettier.)</p>
<p>N.B. This is almost certainly old ground. Reinforcement learning or alpha-beta pruning almost certainly would be good things for me to study. My ignorance on the subject is not meant to imply that there&#8217;s not already a lot out there.</p>
]]></content:encoded>
			<wfw:commentRss>http://raelifin.com/code/simple-rationality/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
		<item>
		<title>Butchering Haskell</title>
		<link>http://raelifin.com/code/butchering-haskell/</link>
		<comments>http://raelifin.com/code/butchering-haskell/#comments</comments>
		<pubDate>Mon, 01 Nov 2010 20:41:26 +0000</pubDate>
		<dc:creator>Raelifin</dc:creator>
				<category><![CDATA[Code]]></category>
		<category><![CDATA[game]]></category>
		<category><![CDATA[Haskell]]></category>
		<category><![CDATA[RCRPG]]></category>
		<category><![CDATA[text-based]]></category>

		<guid isPermaLink="false">http://raelifin.com/?p=710</guid>
		<description><![CDATA[I picked up Haskell just under two weeks ago, and in my free time I&#8217;ve been implementing RCRPG in it, much like I did with Python. You can see my code at http://rosettacode.org/wiki/RCRPG/Haskell. It&#8217;s really not very pretty though. My mind is clearly still stuck on a procedural, object-oriented approach.]]></description>
			<content:encoded><![CDATA[<p>I picked up Haskell just under two weeks ago, and in my free time I&#8217;ve been implementing <a href="http://rosettacode.org/wiki/RCRPG">RCRPG</a> in it, much like I did with Python. You can see my code at <a href="http://rosettacode.org/wiki/RCRPG/Haskell">http://rosettacode.org/wiki/RCRPG/Haskell</a>. It&#8217;s really not very pretty though. My mind is clearly still stuck on a procedural, object-oriented approach.</p>
]]></content:encoded>
			<wfw:commentRss>http://raelifin.com/code/butchering-haskell/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Autocell 2</title>
		<link>http://raelifin.com/code/autocell-2/</link>
		<comments>http://raelifin.com/code/autocell-2/#comments</comments>
		<pubDate>Sat, 29 May 2010 16:42:22 +0000</pubDate>
		<dc:creator>Raelifin</dc:creator>
				<category><![CDATA[Code]]></category>
		<category><![CDATA[Autocell]]></category>

		<guid isPermaLink="false">http://raelifin.com/?p=378</guid>
		<description><![CDATA[I&#8217;ve updated Autocell to version 2. In addition to cleaning up the code, adding better error handling, and (I hope) improving the interface slightly, I&#8217;ve made the following changes to the rules: You can now set cells to be drawn as images. Defining the image a cell should use is as simple as making a [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://raelifin.com/files/autocell/autocell2/">I&#8217;ve updated Autocell to version 2</a>. In addition to cleaning up the code, adding better error handling, and (I hope) improving the interface slightly, I&#8217;ve made the following changes to the rules:</p>
<ul>
<li>You can now set cells to be drawn as images. Defining the image a cell should use is as simple as making a rule of &#8220;draw &lt;CELLTYPE&gt; &lt;URL&gt;&#8221; (See Langton&#8217;s Ant for example.)</li>
<li>The directions northeast, northwest, etc. have been added, as have fareast, farnorth, etc. The &#8220;far____&#8221; directions refer to cells two steps away.</li>
<li>The special noun &#8220;neighbors&#8221; now includes the NULL cells at the border.</li>
<li>New verbs &#8220;cellAt&#8221; and &#8220;neighborsOf&#8221; have been added. They both take a 2-by-1 array ([x,y]) of the cell in question as their right-parameter. The &#8220;cellAt&#8221; verb returns the type of the cell in question, while &#8220;neighborsOf&#8221; returns the set of neighbors.</li>
<li>A new two-parameter verb &#8220;+&#8221; has been added. Right now it only operates on the 2-by-1 coordinate arrays discussed above. (Example: [1,-10] + [23,7] = [24,-3])</li>
<li>In the same vein, a new special noun called &#8220;thisPos&#8221; has been added. It is the coordinates of the cell being evaluated.</li>
</ul>
<p>That&#8217;s all!</p>
]]></content:encoded>
			<wfw:commentRss>http://raelifin.com/code/autocell-2/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Learning Python</title>
		<link>http://raelifin.com/code/learning-python/</link>
		<comments>http://raelifin.com/code/learning-python/#comments</comments>
		<pubDate>Wed, 26 May 2010 18:10:36 +0000</pubDate>
		<dc:creator>Raelifin</dc:creator>
				<category><![CDATA[Code]]></category>
		<category><![CDATA[game]]></category>
		<category><![CDATA[python]]></category>
		<category><![CDATA[RCRPG]]></category>
		<category><![CDATA[text-based]]></category>

		<guid isPermaLink="false">http://raelifin.com/?p=375</guid>
		<description><![CDATA[It&#8217;s not that interesting, but I made a little one-player text-based RPG in python (3.1.2) this morning/last night. I&#8217;m happy with it, just because it&#8217;s the largest thing I&#8217;ve ever done in python. The whole thing is based off of this blog post. You can get the source code here: http://raelifin.com/files/code/rcrpg.py It&#8217;s all public domain, [...]]]></description>
			<content:encoded><![CDATA[<p>It&#8217;s not that interesting, but I made a little one-player text-based RPG in python (3.1.2) this morning/last night. I&#8217;m happy with it, just because it&#8217;s the largest thing I&#8217;ve ever done in python. The whole thing is <a href="http://web.archive.org/web/20080212201605/http://shortcircuit.us/muddy-kinda-like-a-mud-but-single-player/">based off of this blog post</a>. You can get the source code here: <a href="http://raelifin.com/files/code/rcrpg.py">http://raelifin.com/files/code/rcrpg.py</a><br />
It&#8217;s all public domain, but I like credit (yada, yada).</p>
]]></content:encoded>
			<wfw:commentRss>http://raelifin.com/code/learning-python/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Mini-Project: Autocell</title>
		<link>http://raelifin.com/code/mini-project-autocell/</link>
		<comments>http://raelifin.com/code/mini-project-autocell/#comments</comments>
		<pubDate>Thu, 20 May 2010 06:12:27 +0000</pubDate>
		<dc:creator>Raelifin</dc:creator>
				<category><![CDATA[Code]]></category>
		<category><![CDATA[Autocell]]></category>
		<category><![CDATA[cellular automata]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[rapid-prototype]]></category>
		<category><![CDATA[scripting]]></category>

		<guid isPermaLink="false">http://raelifin.com/?p=356</guid>
		<description><![CDATA[My latest quick project was to write a basic scripting language for building cellular automata. The framework is built on javascript, and I made a nice little interface to go with it. As long as you&#8217;re using a browser that isn&#8217;t terrible, you can check it out here. All the code on that page except [...]]]></description>
			<content:encoded><![CDATA[<p><img style="margin: 0 0 10px 10px; float: right;" src="http://raelifin.com/files/screenshots/autocell_screenshot.png"/>My latest quick project was to write a basic scripting language for building <a href="http://en.wikipedia.org/wiki/Cellular_automata">cellular automata</a>. The framework is built on javascript, and I made a nice little interface to go with it. As long as you&#8217;re using a browser that isn&#8217;t terrible, you can <a href="http://raelifin.com/files/autocell1.html">check it out here</a>. All the code on that page except the utility functions is public domain, but please give credit where credit is due. If you end up examining the source, I apologize for the mess; I was trying to fit everything in one file, and not use jQuery or other libraries.</p>
<p><span id="more-356"></span></p>
<p>For those interested in writing your own automata, here is a quick guide to the syntax:<br />
An automaton is composed of rules. Each rule is designated by a new line. Double slash (//) or pound (#) designate a commented line.<br />
Each rule looks something like <strong>BLACK->WHITE: 1 = 2</strong><br />
BLACK is the type of cell that the rule applies to, WHITE is the type of cell that it will become. After the colon is a statement that must resolve to a single value, or &#8220;noun&#8221;.<br />
Nouns can be strings, numbers, true/false, JSON arrays, &#8220;neighbors&#8221;, or any of the cardinal directions (lower-case). The noun &#8220;neighbors&#8221; is a special noun which is a JSON array with values equal to the types of the surrounding tiles (in eight directions). The special nouns &#8220;west&#8221;, &#8220;north&#8221;, &#8220;south&#8221; and &#8220;east&#8221; are equal to the type in that direction, or &#8220;NULL&#8221; if at the edge.<br />
Nouns can be acted upon by the following &#8220;verbs&#8221;:
<ul>
<li><strong>=</strong>, <strong>></strong>, <strong><</strong> &#8212; Basic comparison operators. They behave like their counterparts in javascript (except for =, which is comparison, not assignment). &#8212; example: &#8220;1 > 2 = false&#8221; (returns true)</li>
<li><strong>or</strong>, <strong>and</strong> &#8212; Low-priority logic operators. These behave like || and &#038;&#038; in most languages. Low-priority means they are evaluated after other verbs. &#8212; example: &#8220;true and false or true&#8221; (returns true)</li>
<li><strong>not</strong> &#8212; Inverts the boolean value to the right. If the value to the right is non-boolean, it is cast to a boolean just like ! in javascript. &#8212; example: &#8220;not true&#8221; (returns false)</li>
<li><strong>contains</strong>, <strong>isIn</strong> &#8212; Check if a value is contained in an array. The two verbs are identical except in the order of their parameters (&#8220;value isIn array&#8221;, or &#8220;array contains value&#8221;). &#8212; example: &#8220;[1,2,3] contains 0&#8243; (returns false)</li>
<li><strong>count</strong> &#8212; Changes the noun on the right from an array to an integer. &#8212; example: &#8220;count [0,1,2]&#8221; (returns 3)</li>
<li><strong>ofType</strong> &#8212; Filters an array on the left to only contain the value on the right. &#8212; example: &#8220;[0,0,0,1,2,3] ofType 0&#8243; (returns [0,0,0])</li>
<li><strong>echo</strong> &#8212; Makes a popup containing the value on the right. Does not change the data. This verb isn&#8217;t very useful, and can flood your browser with popups if you aren&#8217;t careful.</li>
</ul>
<p>Verbs are evaluated from left-to-right, but you can use parentheses to change the order of operations. More examples can be found by loading the prebuilt automata.</p>
<p>I know the interface is a bit hard to use, but if you make anything (even if it&#8217;s pretty trivial) please leave a comment! You can export boards as well, so feel free to share interesting formations in <a href="http://en.wikipedia.org/wiki/Conway's_Game_of_Life">Conway&#8217;s Game of Life</a>, <a href="http://en.wikipedia.org/wiki/Wireworld">Wireworld</a>, or others.</p>
<p>On a related note, this talk by Wolfram is not to be missed:<br />
<object width="446" height="326"><param name="movie" value="http://video.ted.com/assets/player/swf/EmbedPlayer.swf"></param><param name="allowFullScreen" value="true" /><param name="allowScriptAccess" value="always"/><param name="wmode" value="transparent"></param><param name="bgColor" value="#ffffff"></param><param name="flashvars" value="vu=http://video.ted.com/talks/dynamic/StephenWolfram_2010-medium.flv&#038;su=http://images.ted.com/images/ted/tedindex/embed-posters/StephenWolfram-2010.embed_thumbnail.jpg&#038;vw=432&#038;vh=240&#038;ap=0&#038;ti=843&#038;introDuration=15330&#038;adDuration=4000&#038;postAdDuration=830&#038;adKeys=talk=stephen_wolfram_computing_a_theory_of_everything;year=2010;theme=tales_of_invention;theme=bold_predictions_stern_warnings;theme=what_s_next_in_tech;theme=new_on_ted_com;theme=a_taste_of_ted2010;theme=unconventional_explanations;theme=art_unusual;theme=inspired_by_nature;event=TED2010;&#038;preAdTag=tconf.ted/embed;tile=1;sz=512x288;" /><embed src="http://video.ted.com/assets/player/swf/EmbedPlayer.swf" pluginspace="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash" wmode="transparent" bgColor="#ffffff" width="446" height="326" allowFullScreen="true" allowScriptAccess="always" flashvars="vu=http://video.ted.com/talks/dynamic/StephenWolfram_2010-medium.flv&#038;su=http://images.ted.com/images/ted/tedindex/embed-posters/StephenWolfram-2010.embed_thumbnail.jpg&#038;vw=432&#038;vh=240&#038;ap=0&#038;ti=843&#038;introDuration=15330&#038;adDuration=4000&#038;postAdDuration=830&#038;adKeys=talk=stephen_wolfram_computing_a_theory_of_everything;year=2010;theme=tales_of_invention;theme=bold_predictions_stern_warnings;theme=what_s_next_in_tech;theme=new_on_ted_com;theme=a_taste_of_ted2010;theme=unconventional_explanations;theme=art_unusual;theme=inspired_by_nature;event=TED2010;"></embed></object></p>
]]></content:encoded>
			<wfw:commentRss>http://raelifin.com/code/mini-project-autocell/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>

