<?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/"
	xmlns:georss="http://www.georss.org/georss" xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#" xmlns:media="http://search.yahoo.com/mrss/"
	>

<channel>
	<title>gvxDev</title>
	<atom:link href="http://gvxdev.wordpress.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://gvxdev.wordpress.com</link>
	<description>A blog from the future, and yet somehow horribly outdated.</description>
	<lastBuildDate>Fri, 07 Oct 2011 12:30:27 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.com/</generator>
<cloud domain='gvxdev.wordpress.com' port='80' path='/?rsscloud=notify' registerProcedure='' protocol='http-post' />
<image>
		<url>http://s2.wp.com/i/buttonw-com.png</url>
		<title>gvxDev</title>
		<link>http://gvxdev.wordpress.com</link>
	</image>
	<atom:link rel="search" type="application/opensearchdescription+xml" href="http://gvxdev.wordpress.com/osd.xml" title="gvxDev" />
	<atom:link rel='hub' href='http://gvxdev.wordpress.com/?pushpress=hub'/>
		<item>
		<title>The Déjà Vu virtual machine</title>
		<link>http://gvxdev.wordpress.com/2011/10/07/the-deja-vu-virtual-machine/</link>
		<comments>http://gvxdev.wordpress.com/2011/10/07/the-deja-vu-virtual-machine/#comments</comments>
		<pubDate>Fri, 07 Oct 2011 07:54:29 +0000</pubDate>
		<dc:creator>Robin Wellner</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[Language by me]]></category>
		<category><![CDATA[c]]></category>
		<category><![CDATA[déjà vu]]></category>
		<category><![CDATA[virtual machine]]></category>

		<guid isPermaLink="false">http://gvxdev.wordpress.com/?p=801</guid>
		<description><![CDATA[It has been a while since I posted here. Not that I&#8217;ve been sitting on my hands. A lot has happened the past three months. For example, I took up Déjà Vu again. The implementation had some problems, or rather one big problem: the C stack. You see, the Déjà interpreter has two functions step_eval [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=gvxdev.wordpress.com&amp;blog=5303508&amp;post=801&amp;subd=gvxdev&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>It has been a while since I posted here. Not that I&#8217;ve been sitting on my hands. A lot has happened the past three months.</p>
<p>For example, I took up Déjà Vu again. The <a href="http://gvxdev.wordpress.com/2011/03/08/how-i-implemented-deja-vu-in-two-days/">implementation</a> had some problems, or rather one big problem: the C stack.</p>
<p>You see, the Déjà interpreter has two functions <code>step_eval</code> and <code>getnextnode</code> which call each other recursively, while walking the source tree. A simple function in Déjà Vu is often three or four nodes deep, so calling a function in Déjà Vu can easily add eight functions that are called recursively. CPython uses the C stack for that. The C stack is rather limited in size, so the interpreter usually can&#8217;t handle more than a node depth of a few hundred nodes, and that includes recursive function calls.</p>
<p>Now, there are other implementations of Python that don&#8217;t have that limitation, but I don&#8217;t want to require the user to use Stackless or PyPy or something else. It is possible to increase the size of the C stack, but that&#8217;s a workaround and only works for applications of less than an arbitrary size. I deemed neither solution acceptable.</p>
<p>So what then?</p>
<p>My reasoning was as follows: the recursion of the interpreter is the problem, so I have to make it not recurse any more. Thus I wrote a function called <code>flatten</code>, which made the tree a list of instructions. (Actually, some parts kept a tree shape, but those were limited and unlikely to cause problems). Then I did nothing with it for several months.</p>
<p>When I got started on it again, I decided the code to flatten the tree could easily be used to generate byte code. I then spent a while thinking of useful opcodes and other low-level decisions. When that was done, I had a pretty good idea how I wanted to do the byte code and the virtual machine. I wrote several functions and adapted flatten, to produce proper byte code.</p>
<p>Although this byte code is a binary format, I wrote it for portability, so the compiler would not be needed by users of Déjà Vu programs.</p>
<p>I started writing a virtual machine in C, in code as clean and portable as possible.</p>
<p>As regular readers* will know, I am a high-level thinking guy, so C isn&#8217;t my forte, especially for writing virtual machines. I found a sensible way to implement stacks and values that can have multiple types, and I think I know how I can handle return stacks and closure stacks, but there&#8217;s still a long road ahead.</p>
<p>At the current state, it has a garbage collector: reference counting plus the synchronous method of cycle collection described in <a href="http://citeseerx.ist.psu.edu/viewdoc/summary?doi=10.1.1.18.9603">Concurrent Cycle Collection in Reference Counted Systems</a>.</p>
<p>* Ha! As if!</p>
<br />Filed under: <a href='http://gvxdev.wordpress.com/category/development/'>Development</a>, <a href='http://gvxdev.wordpress.com/category/development/language-by-me/'>Language by me</a> Tagged: <a href='http://gvxdev.wordpress.com/tag/c/'>c</a>, <a href='http://gvxdev.wordpress.com/tag/deja-vu/'>déjà vu</a>, <a href='http://gvxdev.wordpress.com/tag/virtual-machine/'>virtual machine</a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/gvxdev.wordpress.com/801/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/gvxdev.wordpress.com/801/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/gvxdev.wordpress.com/801/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/gvxdev.wordpress.com/801/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/gvxdev.wordpress.com/801/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/gvxdev.wordpress.com/801/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/gvxdev.wordpress.com/801/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/gvxdev.wordpress.com/801/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/gvxdev.wordpress.com/801/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/gvxdev.wordpress.com/801/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/gvxdev.wordpress.com/801/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/gvxdev.wordpress.com/801/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/gvxdev.wordpress.com/801/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/gvxdev.wordpress.com/801/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=gvxdev.wordpress.com&amp;blog=5303508&amp;post=801&amp;subd=gvxdev&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://gvxdev.wordpress.com/2011/10/07/the-deja-vu-virtual-machine/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/41a9c3304eed6c695c3dfe70b4e4399c?s=96&#38;d=http%3A%2F%2F0.gravatar.com%2Favatar%2Fad516503a11cd5ca435acc9bb6523536%3Fs%3D96&#38;r=G" medium="image">
			<media:title type="html">gvx</media:title>
		</media:content>
	</item>
		<item>
		<title>The Path to Philosophy</title>
		<link>http://gvxdev.wordpress.com/2011/06/14/the-wikipedia-path/</link>
		<comments>http://gvxdev.wordpress.com/2011/06/14/the-wikipedia-path/#comments</comments>
		<pubDate>Tue, 14 Jun 2011 17:49:32 +0000</pubDate>
		<dc:creator>Robin Wellner</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[philosophy]]></category>
		<category><![CDATA[python]]></category>
		<category><![CDATA[wikipedia]]></category>
		<category><![CDATA[xkcd]]></category>

		<guid isPermaLink="false">http://gvxdev.wordpress.com/?p=759</guid>
		<description><![CDATA[Wikipedia trivia: if you take any article, click on the first link in the article text not in parentheses or italics, and then repeat, you will eventually end up at &#8220;Philosophy&#8221;. &#8212; Randall Munroe, title text of xkcd/903. The method described in the quote at the top of this page is actually away to make [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=gvxdev.wordpress.com&amp;blog=5303508&amp;post=759&amp;subd=gvxdev&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<blockquote><p>Wikipedia trivia: if you take any article, click on the first link in the article text not in parentheses or italics, and then repeat, you will eventually end up at &#8220;Philosophy&#8221;.<br />
&mdash; Randall Munroe, title text of <a href="http://xkcd.com/903">xkcd/903<a />.</p></blockquote>
<p><a href="http://gvxdev.files.wordpress.com/2011/06/i-may-have.png"><img src="http://gvxdev.files.wordpress.com/2011/06/i-may-have.png?w=595" alt="I may have written a script inspired by the alt-text of http://xkcd.com/903/ --- blog post and GitHub Gist will follow whenever." title="Yes, I tweeted alt-text instead of title text. Get over it."   class="alignnone size-full wp-image-768" /></a></p>
<p><span id="more-759"></span></p>
<p>The method described in the quote at the top of this page is actually away to make a graph out of Wikipedia, I realized. Some sort of reverse tree. Not exactly the right description, since cycles are possible (and do exist on Wikipedia).</p>
<p>I wondered whether it would be possible to write a script that starts from some article on Wikipedia and goes on until it finds Philosophy or ends up in a cycle.</p>
<p>As it turns out, it is. Once you get past the parsing of HTML, it is not that hard, even. For that, I avoided regular expressions, and went straight to <code>html.parser.HTMLParser</code>. Can&#8217;t say I used it before, but it was a breeze. 90% of the code in the parser is concerned with keeping track of all the conditions whether it is the right time to follow a link. Surprisingly, handling the &#8220;not in parentheses&#8221; condition was the simplest. I want to keep the code out of this post and in a Gist, but I can&#8217;t resist sharing this snippet beforehand:</p>
<pre>	def handle_data(self, data):
		self.open_parens += data.count('(') - data.count(')')</pre>
<p>For my walker, I ran into the problem of redirects: this could cause problems &mdash; or at least redundancy &mdash; for cycles. I solved the problem by making what can be described as a dictionary of sets. I sought <a href="http://stackoverflow.com/questions/6205476">help</a> from Stack Overflow, and got a <a href="http://twitter.com/gvxdev/status/76011621402673152">neat new toy</a> out of it, but in the end I just went with what I had already.</p>
<p>Long story short: most articles seem to end up in Philosophy eventually (often in ~20 steps), but some end up in a cycle. It is possible that there is some article in there without a valid link, which means there could be dead ends (I don&#8217;t check for that, only for Philosophy and cycles), but I haven&#8217;t found one yet.</p>
<p>I thought of building an extensive network of Wikipedia articles, but decided against it because of the high volume of requests I would need to send to Wikipedia for it.</p>
<p>And finally, for those of you craving code, <a href="https://gist.github.com/1025436">here it is</a>. Requires Python 3.</p>
<br />Filed under: <a href='http://gvxdev.wordpress.com/category/development/'>Development</a> Tagged: <a href='http://gvxdev.wordpress.com/tag/philosophy/'>philosophy</a>, <a href='http://gvxdev.wordpress.com/tag/python/'>python</a>, <a href='http://gvxdev.wordpress.com/tag/wikipedia/'>wikipedia</a>, <a href='http://gvxdev.wordpress.com/tag/xkcd/'>xkcd</a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/gvxdev.wordpress.com/759/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/gvxdev.wordpress.com/759/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/gvxdev.wordpress.com/759/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/gvxdev.wordpress.com/759/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/gvxdev.wordpress.com/759/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/gvxdev.wordpress.com/759/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/gvxdev.wordpress.com/759/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/gvxdev.wordpress.com/759/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/gvxdev.wordpress.com/759/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/gvxdev.wordpress.com/759/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/gvxdev.wordpress.com/759/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/gvxdev.wordpress.com/759/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/gvxdev.wordpress.com/759/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/gvxdev.wordpress.com/759/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=gvxdev.wordpress.com&amp;blog=5303508&amp;post=759&amp;subd=gvxdev&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://gvxdev.wordpress.com/2011/06/14/the-wikipedia-path/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/41a9c3304eed6c695c3dfe70b4e4399c?s=96&#38;d=http%3A%2F%2F0.gravatar.com%2Favatar%2Fad516503a11cd5ca435acc9bb6523536%3Fs%3D96&#38;r=G" medium="image">
			<media:title type="html">gvx</media:title>
		</media:content>

		<media:content url="http://gvxdev.files.wordpress.com/2011/06/i-may-have.png" medium="image">
			<media:title type="html">Yes, I tweeted alt-text instead of title text. Get over it.</media:title>
		</media:content>
	</item>
		<item>
		<title>Mastermind Solver</title>
		<link>http://gvxdev.wordpress.com/2011/05/16/mastermind-solver/</link>
		<comments>http://gvxdev.wordpress.com/2011/05/16/mastermind-solver/#comments</comments>
		<pubDate>Mon, 16 May 2011 20:22:23 +0000</pubDate>
		<dc:creator>Robin Wellner</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[artificial intelligence]]></category>
		<category><![CDATA[functional programming]]></category>
		<category><![CDATA[knuth]]></category>
		<category><![CDATA[mastermind]]></category>
		<category><![CDATA[programming]]></category>
		<category><![CDATA[python]]></category>

		<guid isPermaLink="false">http://gvxdev.wordpress.com/?p=753</guid>
		<description><![CDATA[Last week, our assignment for Object Orientation was to implement a version of Mastermind in Java. The implementation of the AI was okay, but it could have been better. It was a strategy I wrote as a temporary solution. Sometimes it won &#8212; sometimes in four or five times &#8212; but other times it lost. [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=gvxdev.wordpress.com&amp;blog=5303508&amp;post=753&amp;subd=gvxdev&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Last week, our assignment for Object Orientation was to implement a version of <a href="http://en.wikipedia.org/wiki/Mastermind_(board_game)">Mastermind</a> in Java. The implementation of the AI was okay, but it could have been better. It was a strategy I wrote as a temporary solution. Sometimes it won &mdash; sometimes in four or five times &mdash; but other times it lost. This was the entire reasoning of the AI:</p>
<ol>
<li>Each position gets a list with all possible values (A, B, C, D, E, F).</li>
<li>I choose a random value from each list to select the next attempt.</li>
<li>If the score I get for attempt the attempt (for example ABCD) has no red points, I know that:
<ul>
<li>A cannot be in the first list, so I remove it.</li>
<li>B cannot be in the second list, so I remove it.</li>
<li>C cannot be in the third list, so I remove it.</li>
<li>D cannot be in the fourth list, so I remove it.</li>
</ul>
</li>
<li>If the score I get for the attempt has no white points either, I know that all the colours in the attempt must be removed from all the lists.
<li>If the right solution hasn&#8217;t been found yet, go to 2.</li>
</ol>
<p>That&#8217;s it. That&#8217;s the whole of the algorithm. I didn&#8217;t think it would work. But sometimes, it did. It was more luck than wisdom, but still.</p>
<p>As you might know, our major is Artificial Intelligence, so I wanted to make it smarter, once we dealt with the annoyance of <a href="http://en.wikipedia.org/wiki/Model%E2%80%93view%E2%80%93controller">MVC</a> &mdash; I can see how that can be useful in certain situations, but we never have practical assignments that do the pattern justice.</p>
<p>Anyway, the Wikipedia page I linked to earlier had an <a href="http://en.wikipedia.org/wiki/Mastermind_(board_game)#Algorithms">interesting section</a> on algorithms. I wanted to implement one of them, but we soon abandoned the idea. Firstly, the computer playing a near-perfect game each time seemed boring. Secondly and more importantly, Java couldn&#8217;t let us do it easily or elegantly.</p>
<p>The problem seemed to be object orientation to me. It simply wasn&#8217;t cut out for this. I thought functional implementation would be much better. Java really sucks at this, so I made up my mind to write an implementation of <a href="http://en.wikipedia.org/wiki/Mastermind_(board_game)#Five-guess_algorithm" title="Read it if you haven't already">Knuth&#8217;s five-guess algorithm</a> in Python, using every functional trick I could think of.</p>
<p>That&#8217;s exactly what I did last weekend. The complete program, with CLI, is only 42 lines long (yes, that was intentional). And it works. You can supply a code as a command line argument, or enter it later. The first attempt is always AABB. The second attempt takes a while. Depending on the score at the first attempt, it may take twenty or forty seconds on my machine, but I have seen it take only three.</p>
<p>At first, it didn&#8217;t work. It took me some time to find the problem: the search space was too limited. Because of careless reading, I used the wrong function to generate the list of all possibilities. It actually generated a list of permutations of ABCDEF of length four, meaning codes containing duplicates (AABC or DABD, for example) could not be found. Using the right function solved all that.</p>
<p>I made a Gist, <a href="https://gist.github.com/975276">enjoy</a>.</p>
<p>PS: I don&#8217;t like using a global to keep track of the number of attempts. If you know of an elegant and functional solution, please let me know!</p>
<br />Filed under: <a href='http://gvxdev.wordpress.com/category/development/'>Development</a> Tagged: <a href='http://gvxdev.wordpress.com/tag/artificial-intelligence/'>artificial intelligence</a>, <a href='http://gvxdev.wordpress.com/tag/functional-programming/'>functional programming</a>, <a href='http://gvxdev.wordpress.com/tag/knuth/'>knuth</a>, <a href='http://gvxdev.wordpress.com/tag/mastermind/'>mastermind</a>, <a href='http://gvxdev.wordpress.com/tag/programming/'>programming</a>, <a href='http://gvxdev.wordpress.com/tag/python/'>python</a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/gvxdev.wordpress.com/753/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/gvxdev.wordpress.com/753/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/gvxdev.wordpress.com/753/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/gvxdev.wordpress.com/753/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/gvxdev.wordpress.com/753/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/gvxdev.wordpress.com/753/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/gvxdev.wordpress.com/753/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/gvxdev.wordpress.com/753/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/gvxdev.wordpress.com/753/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/gvxdev.wordpress.com/753/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/gvxdev.wordpress.com/753/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/gvxdev.wordpress.com/753/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/gvxdev.wordpress.com/753/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/gvxdev.wordpress.com/753/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=gvxdev.wordpress.com&amp;blog=5303508&amp;post=753&amp;subd=gvxdev&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://gvxdev.wordpress.com/2011/05/16/mastermind-solver/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/41a9c3304eed6c695c3dfe70b4e4399c?s=96&#38;d=http%3A%2F%2F0.gravatar.com%2Favatar%2Fad516503a11cd5ca435acc9bb6523536%3Fs%3D96&#38;r=G" medium="image">
			<media:title type="html">gvx</media:title>
		</media:content>
	</item>
		<item>
		<title>Modelling Agent Beliefs in Games</title>
		<link>http://gvxdev.wordpress.com/2011/04/26/modelling-agent-beliefs-in-games/</link>
		<comments>http://gvxdev.wordpress.com/2011/04/26/modelling-agent-beliefs-in-games/#comments</comments>
		<pubDate>Tue, 26 Apr 2011 18:15:06 +0000</pubDate>
		<dc:creator>Robin Wellner</dc:creator>
				<category><![CDATA[Artificial intelligence]]></category>
		<category><![CDATA[Development]]></category>
		<category><![CDATA[agents]]></category>
		<category><![CDATA[artificial intelligence]]></category>
		<category><![CDATA[belief]]></category>
		<category><![CDATA[games]]></category>

		<guid isPermaLink="false">http://gvxdev.wordpress.com/?p=666</guid>
		<description><![CDATA[Kicking of with a bit of a warning: this post is rather theoretical compared to its usual content. The post proper starts with a generic question: how does one model belief states for NPCs/agents in games? Why would you want to model belief states? I&#8217;m not talking about things like &#8220;last know position&#8221; here, which [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=gvxdev.wordpress.com&amp;blog=5303508&amp;post=666&amp;subd=gvxdev&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Kicking of with a bit of a warning: this post is rather theoretical compared to its usual content.</p>
<p>The post proper starts with a generic question: how does one model belief states for NPCs/agents in games?<br />
<span id="more-666"></span><br />
Why would you want to model belief states? I&#8217;m not talking about things like &#8220;last know position&#8221; here, which is neat but not what I want to discuss.</p>
<p>This is about social simulation games, where it is important for agents to act believably. Letting the agents have subjective models of the world in their &#8220;heads&#8221; could potentially be a huge benefit.</p>
<p>In the game series <em>The Sims</em>, little attention is paid to agent world view: the Sims have relationships with other Sims, but that&#8217;s still rather one-dimensional. There are different elements in the different games in the series, but other world view elements are given rather limited attention. For instance, interests in <em>The Sims 2</em>, which decide what the Sims like to talk about, but they don&#8217;t influence game play very much.</p>
<p>In <em>OpenTown</em>, I want to do things rather differently. Relationships consist of multiple elements, for example: how much John trusts Jack is independent from how much John likes Jack. Although they are independent properties, they are related and mutually connected. Also related is how much John trusts Suzie and how much Suzie trusts Jack (or at least: what she tells John about that). So relations are complex, dynamic and influenced by groupthink.<br />
What more: people prefer to talk to people that agree with them. I expect groups to form, hopefully preventing the town to become a homogeneous paste. In <em>The Sims</em>, this is resolved by letting Sims do stupid and rather OOC things like randomly picking fights with strangers, which I really don&#8217;t like.</p>
<p>There is a lot to <em>OpenTown</em> belief state which I&#8217;m glossing over, one thing I do like to mention is Doubt. Every believe has a Conviction and a Doubt quantity attached. The Conviction is simply how much the person believes a certain claim to be true. -1 is &#8220;most certainly false&#8221;, 1 is &#8220;most certainly true&#8221;, 0 is &#8220;I have no clue whatsoever either way&#8221; and the rest sits somewhere in-between. Doubt is more of a meta-belief: it goes from 0 to 1, it says how much the person suspects their own belief is false.</p>
<p>How does that work in theoretical practice?<br />
Put a firm believer in Red Is Better Than Blue (R&gt;B) in a circle of people who all believe Blue Is Better Than Red (B&gt;R). When they converse, sometimes the subject of Red vs Blue comes up. The Conviction of either party is raised, because that is the typical response of humans. But the Doubt is raised too. The kind hosts can lower their Doubt by talking amongst themselves about B&gt;R, while their guest has no such luxury. After a while, the Doubt of the guest begins to overtake their Conviction, and the latter starts dropping, while the Doubt starts rising even faster (of course, once Doubt reaches 1, it will not rise anymore). Once Conviction crosses the 0, their Doubt starts dropping, and it won&#8217;t take long now before the guy who thought R&gt;B at first now completely believes B&gt;R.</p>
<p>This is all very complicated and, if implemented, might provide for very interesting situations.</p>
<p>For another game, I wanted to do something similar, but less complicated, since (believable) social dynamics was not the primary goal of that game.</p>
<p>The working title of that game is <em>Tribe</em>. In it, you lead a tribe, consisting of unique individuals. There is more to it, but I&#8217;ll just discuss the belief system I want to use there. That system uses <a href="http://en.wikipedia.org/wiki/Expert_system#Certainty_factors">certainty factors</a>. The tally there is how much the receiving person trusts the claimant. This does away with the whole double Conviction/Doubt system and I have no justification for it as I have for the <em>OpenTown</em> system.</p>
<p>This post is getting a bit long, and there is so much more to say on this subject. You can consider this the first part of a series. Probably.</p>
<br />Filed under: <a href='http://gvxdev.wordpress.com/category/artificial-intelligence-2/'>Artificial intelligence</a>, <a href='http://gvxdev.wordpress.com/category/development/'>Development</a> Tagged: <a href='http://gvxdev.wordpress.com/tag/agents/'>agents</a>, <a href='http://gvxdev.wordpress.com/tag/artificial-intelligence/'>artificial intelligence</a>, <a href='http://gvxdev.wordpress.com/tag/belief/'>belief</a>, <a href='http://gvxdev.wordpress.com/tag/games/'>games</a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/gvxdev.wordpress.com/666/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/gvxdev.wordpress.com/666/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/gvxdev.wordpress.com/666/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/gvxdev.wordpress.com/666/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/gvxdev.wordpress.com/666/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/gvxdev.wordpress.com/666/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/gvxdev.wordpress.com/666/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/gvxdev.wordpress.com/666/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/gvxdev.wordpress.com/666/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/gvxdev.wordpress.com/666/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/gvxdev.wordpress.com/666/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/gvxdev.wordpress.com/666/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/gvxdev.wordpress.com/666/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/gvxdev.wordpress.com/666/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=gvxdev.wordpress.com&amp;blog=5303508&amp;post=666&amp;subd=gvxdev&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://gvxdev.wordpress.com/2011/04/26/modelling-agent-beliefs-in-games/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/41a9c3304eed6c695c3dfe70b4e4399c?s=96&#38;d=http%3A%2F%2F0.gravatar.com%2Favatar%2Fad516503a11cd5ca435acc9bb6523536%3Fs%3D96&#38;r=G" medium="image">
			<media:title type="html">gvx</media:title>
		</media:content>
	</item>
		<item>
		<title>Lazy-Lith</title>
		<link>http://gvxdev.wordpress.com/2011/04/22/lazy-lith/</link>
		<comments>http://gvxdev.wordpress.com/2011/04/22/lazy-lith/#comments</comments>
		<pubDate>Fri, 22 Apr 2011 12:21:56 +0000</pubDate>
		<dc:creator>Robin Wellner</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[Language by me]]></category>
		<category><![CDATA[esoteric programming language]]></category>
		<category><![CDATA[lazy-lith]]></category>
		<category><![CDATA[lith]]></category>
		<category><![CDATA[programming language]]></category>

		<guid isPermaLink="false">http://gvxdev.wordpress.com/?p=735</guid>
		<description><![CDATA[As I was trying to make a proper programming language out of Lith, I noticed something: it became less and less elegant. And although it now had functions, to truly work as a programming language, I needed to add even more inelegant cruft. When reading about the history of Haskell, I had an idea: I [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=gvxdev.wordpress.com&amp;blog=5303508&amp;post=735&amp;subd=gvxdev&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>As I was trying to make a <a href="http://gvxdev.wordpress.com/2011/04/10/lith-revisited/">proper programming language</a> out of <a href="http://gvxdev.wordpress.com/2010/10/29/programming-language-lith/">Lith</a>, I noticed something: it became less and less elegant. And although it now had <a href="http://gvxdev.wordpress.com/2011/04/10/lith-revisited/#comment-156">functions<a>, to truly work as a programming language, I needed to add even more inelegant cruft.</p>
<p>When reading about the history of <a href="http://en.wikipedia.org/wiki/Haskell_(programming_language)">Haskell</a>, I had an idea: I would return Lith to a former state, without functions, so that it could be used to describe data and nothing more, while guaranteeing any valid source code has an equivalent canonical form (only containing <code>T</code> and <code>[ ]</code>). This could not be guaranteed when using functions, which have no canonical representation. The other part of the idea was that I would copy the Lith project to a new project named Lazy-Lith, which would be a lazily evaluated superset of Lith. Functions (in the form of <code>( )</code>) are completely gone now: Lith does not have a way to suspend evaluation, while in Lazy-Lith, <em>every</em> list is a lazy list.</p>
<p>This means I have to let go of the idea of a stack, rendering the -th in Lith obsolete, because when all lists are lazily evaluated, there is no way of knowing beforehand when the stack will be used.</p>
<p>I have added alphabetical names and assignment with <code>=</code> in the parser, they&#8217;re not yet evaluated.</p>
<p>That&#8217;s pretty much all there is to say about Lazy-Lith at the moment.</p>
<br />Filed under: <a href='http://gvxdev.wordpress.com/category/development/'>Development</a>, <a href='http://gvxdev.wordpress.com/category/development/language-by-me/'>Language by me</a> Tagged: <a href='http://gvxdev.wordpress.com/tag/esoteric-programming-language/'>esoteric programming language</a>, <a href='http://gvxdev.wordpress.com/tag/lazy-lith/'>lazy-lith</a>, <a href='http://gvxdev.wordpress.com/tag/lith/'>lith</a>, <a href='http://gvxdev.wordpress.com/tag/programming-language/'>programming language</a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/gvxdev.wordpress.com/735/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/gvxdev.wordpress.com/735/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/gvxdev.wordpress.com/735/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/gvxdev.wordpress.com/735/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/gvxdev.wordpress.com/735/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/gvxdev.wordpress.com/735/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/gvxdev.wordpress.com/735/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/gvxdev.wordpress.com/735/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/gvxdev.wordpress.com/735/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/gvxdev.wordpress.com/735/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/gvxdev.wordpress.com/735/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/gvxdev.wordpress.com/735/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/gvxdev.wordpress.com/735/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/gvxdev.wordpress.com/735/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=gvxdev.wordpress.com&amp;blog=5303508&amp;post=735&amp;subd=gvxdev&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://gvxdev.wordpress.com/2011/04/22/lazy-lith/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/41a9c3304eed6c695c3dfe70b4e4399c?s=96&#38;d=http%3A%2F%2F0.gravatar.com%2Favatar%2Fad516503a11cd5ca435acc9bb6523536%3Fs%3D96&#38;r=G" medium="image">
			<media:title type="html">gvx</media:title>
		</media:content>
	</item>
		<item>
		<title>Lith revisited</title>
		<link>http://gvxdev.wordpress.com/2011/04/10/lith-revisited/</link>
		<comments>http://gvxdev.wordpress.com/2011/04/10/lith-revisited/#comments</comments>
		<pubDate>Sun, 10 Apr 2011 09:37:57 +0000</pubDate>
		<dc:creator>Robin Wellner</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[Language by me]]></category>
		<category><![CDATA[esoteric programming language]]></category>
		<category><![CDATA[lith]]></category>
		<category><![CDATA[programming language]]></category>

		<guid isPermaLink="false">http://gvxdev.wordpress.com/?p=708</guid>
		<description><![CDATA[A while back, I wrote about Lith, a minimalistic language. Yesterday, I decided to implement the rest of the language, which was surprisingly easy. (Of course, Lith is still a simple language, and I have more experience with this sort of thing now.) It&#8217;s up on GitHub now. In today&#8217;s post, I discuss the theory [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=gvxdev.wordpress.com&amp;blog=5303508&amp;post=708&amp;subd=gvxdev&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>A while back, I <a href="/2010/10/29/programming-language-lith/">wrote</a> about Lith, a minimalistic language.</p>
<p>Yesterday, I decided to implement the rest of the language, which was surprisingly easy. (Of course, Lith is still a simple language, and I have more experience with <a href="/2011/03/08/how-i-implemented-deja-vu-in-two-days/">this sort of thing</a> now.) It&#8217;s up on <a href="https://github.com/gvx/lith">GitHub</a> now.</p>
<p>In today&#8217;s post, I discuss the theory and implementation of the latest version of Lith.<br />
<span id="more-708"></span></p>
<p>First, I added numbers, such that <code>5</code> was recognised as <code>[ T T T T T ]</code>. Next up, strings. <code>"Hi"</code> turns into <code>[ [ T T T &hellip; T ] [ T T T &hellip; T ] ]</code>. After that, I added operations (head, tail, test, length, concat, and later flatten), with a generic Special class, which takes as argument the next element in the source.</p>
<p>Now, the operations were not processed, only parsed. I wrote an evaluator, similar in structure to the parser, which took its input from the output of the parser.</p>
<p>An overview of the operations:<br />
<strong><code>!</code>, head</strong><br />
Takes the first element of a list. Is the identity function for <code>T</code> and <code>[ ]</code>.</p>
<pre>! [ T ]             # = T
! [ [ T T ] [ T ] ] # = [ T T ]
! 34                # = 1
! [ ]               # = [ ]
! "Hello"           # = 72</pre>
<p><strong><code>$</code>, tail</strong><br />
Returns everything but the first element of a list. Is the identity function for <code>T</code> and <code>[ ]</code>.</p>
<pre>$ [ T ]             # = [ ]
$ [ [ T T ] [ T ] ] # = [ T ]
$ 34                # = 33
$ [ ]               # = [ ]
$ "Hello"           # = [ 101 108 108 111 ]</pre>
<p><strong><code>?</code>, test</strong><br />
Tests for truth. <code>T</code> is true, <code>[ ]</code> is false and any non-empty list is true.</p>
<pre>? [ ]  # = [ ]
? T    # = T
? 3    # = T
? "Hi" # = T</pre>
<p><strong><code>&amp;</code>, length</strong><br />
Returns the length of a list. This means that for any number, including zero, length is the identity function. The length of <code>T</code> is defined as <code>[ ]</code>.</p>
<pre>&amp; [ ]                     # = [ ]
&amp; T                       # = [ ]
&amp; 3                       # = 3
&amp; "Hi"                    # = 2
&amp; [ T [ T T [ T T T ] ] ] # = 2</pre>
<p><strong><code>:</code>, concat</strong><br />
A bit of a weird operator, as it is infix instead of prefix. Concat is a bit like cons in Lisp: it prepends an element to a list,</p>
<pre>T : [ ]   # = [ T ]
[ ] : [ ] # = [ [ ] ]
[ T ] : 4 # = [ [ T ] T T T T ]
T : 4     # = 5
!"H":"i"  # = "Hi"</pre>
<p><strong><code>_</code>, flatten</strong><br />
Flatten can be understood to return the total number of <code>T</code>s in its argument.</p>
<pre>_ T                   # = [ T ] = 1
_ [ 4 T T [ [ 1 ] ] ] # = 7
_ [ ]                 # = [ ] = 0</pre>
<p>When that was done, I wanted to simplify the tree I had to text the original parser could understand (so only <code>T</code> and <code>[ ]</code>). So I did.</p>
<p>Although the original parser ignored whitespace¹, several separator characters and <code>#comments</code>, I decided to skip all that, and just pasted all the elements together. That output is what I call the canonical form of a tree: the simplest form, free from any syntactic sugar or operation.</p>
<p>As of now, Lith doesn&#8217;t have any flow control (I still haven&#8217;t found a way to do functions), so it is actually more of a data description language than a programming language.</p>
<hr />
<p>¹ There are two places whitespaces matter: between two numbers: <code>1 1</code> is entirely different from <code>11</code>, and inside strings, for obvious reasons. But the original parser didn&#8217;t recognise numbers or strings, so all&#8217;s good.</p>
<br />Filed under: <a href='http://gvxdev.wordpress.com/category/development/'>Development</a>, <a href='http://gvxdev.wordpress.com/category/development/language-by-me/'>Language by me</a> Tagged: <a href='http://gvxdev.wordpress.com/tag/esoteric-programming-language/'>esoteric programming language</a>, <a href='http://gvxdev.wordpress.com/tag/lith/'>lith</a>, <a href='http://gvxdev.wordpress.com/tag/programming-language/'>programming language</a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/gvxdev.wordpress.com/708/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/gvxdev.wordpress.com/708/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/gvxdev.wordpress.com/708/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/gvxdev.wordpress.com/708/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/gvxdev.wordpress.com/708/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/gvxdev.wordpress.com/708/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/gvxdev.wordpress.com/708/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/gvxdev.wordpress.com/708/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/gvxdev.wordpress.com/708/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/gvxdev.wordpress.com/708/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/gvxdev.wordpress.com/708/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/gvxdev.wordpress.com/708/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/gvxdev.wordpress.com/708/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/gvxdev.wordpress.com/708/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=gvxdev.wordpress.com&amp;blog=5303508&amp;post=708&amp;subd=gvxdev&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://gvxdev.wordpress.com/2011/04/10/lith-revisited/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/41a9c3304eed6c695c3dfe70b4e4399c?s=96&#38;d=http%3A%2F%2F0.gravatar.com%2Favatar%2Fad516503a11cd5ca435acc9bb6523536%3Fs%3D96&#38;r=G" medium="image">
			<media:title type="html">gvx</media:title>
		</media:content>
	</item>
		<item>
		<title>Writing a Tic-Tac-Toe Minimax</title>
		<link>http://gvxdev.wordpress.com/2011/03/29/writing-a-tic-tac-toe-minimax/</link>
		<comments>http://gvxdev.wordpress.com/2011/03/29/writing-a-tic-tac-toe-minimax/#comments</comments>
		<pubDate>Tue, 29 Mar 2011 17:08:00 +0000</pubDate>
		<dc:creator>Robin Wellner</dc:creator>
				<category><![CDATA[Artificial intelligence]]></category>
		<category><![CDATA[artificial intelligence]]></category>
		<category><![CDATA[github]]></category>
		<category><![CDATA[heuristics]]></category>
		<category><![CDATA[minimax]]></category>
		<category><![CDATA[tic-tac-toe]]></category>

		<guid isPermaLink="false">http://gvxdev.wordpress.com/?p=681</guid>
		<description><![CDATA[Last Sunday, I decided to write an implementation of tic-tac-toe, complete with computer opponent. I ended up implementing a minimax algorithm, which worked well enough. The relatively small amount of states in tic-tac-toe (3⁹ = 19 683, but this includes unreachable states) made this rather simple. I pitted two minimax players against each other. Predictably [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=gvxdev.wordpress.com&amp;blog=5303508&amp;post=681&amp;subd=gvxdev&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Last Sunday, I decided to write an implementation of <a href="http://en.wikipedia.org/wiki/Tic-tac-toe">tic-tac-toe</a>, complete with computer opponent. I ended up implementing a <a href="http://en.wikipedia.org/wiki/Minimax">minimax</a> algorithm, which worked well enough. The relatively small amount of states in tic-tac-toe (3⁹ = 19 683, but this includes unreachable states) made this rather simple.</p>
<p>I pitted two minimax players against each other. Predictably enough, it resulted in a draw. Always the same, since the algorithm is deterministic:</p>
<pre>X X O
O O X
X O X</pre>
<p>The total running time was consistently just under 3 seconds.</p>
<p>That got me thinking, surely a heuristic could do things faster? So I drew up some heuristic rules the enhanced computer player would use:</p>
<ol>
<li>If the board is empty, just play the top-left corner.</li>
<li>If you can win, play the winning move.</li>
<li>If your opponent can win, prevent them from winning.</li>
<li>If you can find a nice corner you can use to force a win (a number means it is empty, a period means it doesn&#8217;t matter), that is:
<pre>X 2 3
. . 6
. . X</pre>
<p>or</p>
<pre>X 2 3
. 5 .
X . .</pre>
<p>(possibly rotated), do that move.</li>
<li>If the opponent has above opportunity, prevent them from doing so.</li>
</ol>
<p>I tried the heuristics, and sure enough, they helped. Drasticly. But only when the heuristic went first (total time: just over 0.2 seconds). Otherwise, the timing didn&#8217;t change <em>at all</em>. Not even just a little bit. They did nothing.</p>
<p>After a bit of experimenting &mdash; not too much, you can probably tell what&#8217;s going on here just by reading the previous paragraph, I just wanted to confirm it &mdash; I found out what was going on:</p>
<p>None of the heuristics did anything. Except for the one for the empty field. You see, the further you get in the game, the smaller the number of possible future game states gets. Reduction early on is likely to matter more. Especially if you can throw away <sup>8</sup>/<sub>9</sub> of the search space.</p>
<p>The nature of minimax did the rest: if you can win in one move, it will already be selected immediately by the algorithm. If your opponent can win in one move, the algorithm will find you lose quickly after choosing anything but that one soon enough. And those fancy heuristics for finding ways to trick the opponent into inevitable failure won&#8217;t be needed, because the opponent won&#8217;t let you get that far (remember, this is minimax vs minimax).</p>
<p>So I removed all but the first heuristic.</p>
<p>I put it up on <a href="https://gist.github.com/888216#file_tictactoe.py">GitHub as a Gist</a>. If you scroll up, you can see the old implementation of the heuristic (much longer, a lot less elegant, and not a bit faster than the new one).</p>
<p>What have we learned? I&#8217;d say the lesson is that, when relying on a minimax as fall-back, you only need to implement heuristics for the opening moves, which will dramatically decrease the search space.</p>
<br />Filed under: <a href='http://gvxdev.wordpress.com/category/artificial-intelligence-2/'>Artificial intelligence</a> Tagged: <a href='http://gvxdev.wordpress.com/tag/artificial-intelligence/'>artificial intelligence</a>, <a href='http://gvxdev.wordpress.com/tag/github/'>github</a>, <a href='http://gvxdev.wordpress.com/tag/heuristics/'>heuristics</a>, <a href='http://gvxdev.wordpress.com/tag/minimax/'>minimax</a>, <a href='http://gvxdev.wordpress.com/tag/tic-tac-toe/'>tic-tac-toe</a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/gvxdev.wordpress.com/681/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/gvxdev.wordpress.com/681/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/gvxdev.wordpress.com/681/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/gvxdev.wordpress.com/681/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/gvxdev.wordpress.com/681/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/gvxdev.wordpress.com/681/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/gvxdev.wordpress.com/681/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/gvxdev.wordpress.com/681/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/gvxdev.wordpress.com/681/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/gvxdev.wordpress.com/681/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/gvxdev.wordpress.com/681/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/gvxdev.wordpress.com/681/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/gvxdev.wordpress.com/681/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/gvxdev.wordpress.com/681/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=gvxdev.wordpress.com&amp;blog=5303508&amp;post=681&amp;subd=gvxdev&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://gvxdev.wordpress.com/2011/03/29/writing-a-tic-tac-toe-minimax/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/41a9c3304eed6c695c3dfe70b4e4399c?s=96&#38;d=http%3A%2F%2F0.gravatar.com%2Favatar%2Fad516503a11cd5ca435acc9bb6523536%3Fs%3D96&#38;r=G" medium="image">
			<media:title type="html">gvx</media:title>
		</media:content>
	</item>
		<item>
		<title>How I implemented Déjà Vu in two days</title>
		<link>http://gvxdev.wordpress.com/2011/03/08/how-i-implemented-deja-vu-in-two-days/</link>
		<comments>http://gvxdev.wordpress.com/2011/03/08/how-i-implemented-deja-vu-in-two-days/#comments</comments>
		<pubDate>Tue, 08 Mar 2011 00:18:07 +0000</pubDate>
		<dc:creator>Robin Wellner</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[Language by me]]></category>
		<category><![CDATA[déjà vu]]></category>
		<category><![CDATA[late night blog]]></category>

		<guid isPermaLink="false">http://gvxdev.wordpress.com/?p=667</guid>
		<description><![CDATA[I&#8217;ve been thinking a lot about Déjà Vu (the programming language I invented) lately. A while ago, I&#8217;ve written a post about it. I couldn&#8217;t quite get it to work. After much distress and failed attempts to fix things, I let it rest. Once in a while I revisited it. For example, when I (re)discovered [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=gvxdev.wordpress.com&amp;blog=5303508&amp;post=667&amp;subd=gvxdev&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve been thinking a lot about Déjà Vu (the programming language I invented) lately.</p>
<p><a href="http://gvxdev.wordpress.com/2010/06/16/again-deja-vu/">A while ago</a>, I&#8217;ve written a post about it. I couldn&#8217;t quite get it to work. After much distress and failed attempts to fix things, I let it rest.</p>
<p>Once in a while I revisited it. For example, when I (re)discovered <a href="http://duckduckgo.com/Parrot_virtual_machine">Parrot</a>, it seemed like a good idea to implement it that way. The problem was that you pretty much need to do each part in one of Perl, some variant of Perl, or Parrot assembly. Perl is horribly opaque and I never learned it, which was problematic. I&#8217;m a high-level thinker, so assembly works against me. But the worst of all is that writing grammars and parsers and whatnot is just plain hard. No, scratch that: the absolute worst is the combination of those things. Learning a language you&#8217;ll probably never like is much harder if your equivalent to a &#8220;hello world&#8221; is a top-down grammar parser.</p>
<p>So I let <em>that</em> rest as well.</p>
<p>But I kept thinking about Déjà Vu. Not on how to implement it — I&#8217;m a high-level thinker, remember? No, I was thinking about concepts, about constructs, about connotations…</p>
<p>All ideas were kept in a file called &#8220;idea&#8221;. The language grew and matured, even though it had no implementation. I added new kinds of statements, full lexical scoping and new datatypes, and improved the function definition syntax.</p>
<p>This spring break, I decided to try it one more time last Sunday. Following the success of implementing a tree parser for <a href="http://gvxdev.wordpress.com/2010/10/29/programming-language-lith/">Lith</a>, (by the way, the answer to the question posed in that post, &#8220;Will I ever implement more?&#8221;, is &#8220;No, I will not.&#8221;) I decided to start simple: read the file line by line, perform a series of simple text transformations to deal with indentation, strings, comments, words and statements (it had to be in that order &mdash; I did spend <em>some</em> time thinking about implementation). After the transformations, produce a tree. I&#8217;d see what would happen next if I finished it.</p>
<p>I finished it within a day. I was shocked. Sure, Déjà Vu is not a large language &mdash; I kept the amount of syntax and the number of statements purposefully small &mdash; but I had so much problems with it before, and now it worked! In a day! It had everything. It had full lexical scoping! It took Lua 8 years to get that, and this implementation of Déjà Vu had it within a day! All I had to do now is find some way to deal with that parsed tree.</p>
<p>Let&#8217;s see. I had a tree filled with conveniently semantically typed nodes. Why not just traverse it, instead of struggling to convert it to byte code? (And probably back again at that.) So I started on that. When I went to bed that day, the first bits where in place for interpreting trees and what&#8217;s more: it looked like it was going to work.</p>
<p>The following day, Monday (it is past midnight as I&#8217;m writing this post), I implemented the interpreter. It was unbelievably easy. After figuring out some minor problems, I was even able to implement the For statement without much trouble, and I had expected that to hold up the project for a while.</p>
<p>It was the second day, and the language worked. It just worked. I had hastily added an interactive interpreter, modeled after Python&#8217;s. That worked too. I have written a neat standard library, implemented in Python. My idea file is over 400 lines, and I had implemented everything I proposed in it, save for those that were superseded by other ideas.</p>
<p>It&#8217;s all up on <a href="https://github.com/gvx/deja">GitHub</a>.</p>
<p>Tomorrow, I will write the much-needed documentation.</p>
<p>One more thing: the implementation as a whole defines <strong>40 classes</strong> to parse, interpret, and represent Déjà Vu source. 26 of which are subclasses of the Node class alone. I think that&#8217;s the highest number of classes I&#8217;ve ever used for a single project.</p>
<br />Filed under: <a href='http://gvxdev.wordpress.com/category/development/'>Development</a>, <a href='http://gvxdev.wordpress.com/category/development/language-by-me/'>Language by me</a> Tagged: <a href='http://gvxdev.wordpress.com/tag/deja-vu/'>déjà vu</a>, <a href='http://gvxdev.wordpress.com/tag/late-night-blog/'>late night blog</a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/gvxdev.wordpress.com/667/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/gvxdev.wordpress.com/667/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/gvxdev.wordpress.com/667/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/gvxdev.wordpress.com/667/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/gvxdev.wordpress.com/667/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/gvxdev.wordpress.com/667/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/gvxdev.wordpress.com/667/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/gvxdev.wordpress.com/667/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/gvxdev.wordpress.com/667/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/gvxdev.wordpress.com/667/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/gvxdev.wordpress.com/667/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/gvxdev.wordpress.com/667/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/gvxdev.wordpress.com/667/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/gvxdev.wordpress.com/667/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=gvxdev.wordpress.com&amp;blog=5303508&amp;post=667&amp;subd=gvxdev&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://gvxdev.wordpress.com/2011/03/08/how-i-implemented-deja-vu-in-two-days/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/41a9c3304eed6c695c3dfe70b4e4399c?s=96&#38;d=http%3A%2F%2F0.gravatar.com%2Favatar%2Fad516503a11cd5ca435acc9bb6523536%3Fs%3D96&#38;r=G" medium="image">
			<media:title type="html">gvx</media:title>
		</media:content>
	</item>
		<item>
		<title>The Power of LÖVE</title>
		<link>http://gvxdev.wordpress.com/2011/01/28/the-power-of-love/</link>
		<comments>http://gvxdev.wordpress.com/2011/01/28/the-power-of-love/#comments</comments>
		<pubDate>Fri, 28 Jan 2011 19:23:24 +0000</pubDate>
		<dc:creator>Robin Wellner</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[failure of journalism]]></category>
		<category><![CDATA[löve]]></category>
		<category><![CDATA[love-2d]]></category>
		<category><![CDATA[propaganda]]></category>
		<category><![CDATA[technical review]]></category>

		<guid isPermaLink="false">http://gvxdev.wordpress.com/?p=314</guid>
		<description><![CDATA[If you&#8217;ve been reading my blog (and if you&#8217;re reading this, chances are you have), you&#8217;ll know how closely I&#8217;m involved with the world of LÖVE. For those unaware, LÖVE is a game framework, aimed at rapid prototyping, extreme cross-platformness and unlimited awesomeness. It brings in a lot of people who never programmed before as [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=gvxdev.wordpress.com&amp;blog=5303508&amp;post=314&amp;subd=gvxdev&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>If you&#8217;ve been reading my blog (and if you&#8217;re reading this, chances are you have), you&#8217;ll know how closely I&#8217;m involved with the world of <a href="http://love2d.org/">LÖVE</a>.</p>
<p>For those unaware, LÖVE is a game framework, aimed at rapid prototyping, extreme cross-platformness and unlimited awesomeness. It brings in a lot of people who never programmed before as well as professionals.</p>
<p>And recently, version 0.7.0 of it was released. It is the second major release since I joined the community, and while it manges to break almost nowhere in the API with the previous version, it has many, many improvements. Sound is much less problematic now, and we have frame buffers and threads at our disposal.</p>
<p>I won&#8217;t talk about the many fun and successful games made with it nor shall I spew more propaganda, aimed at bringing new souls to the friendly and fun-loving community.</p>
<p>Instead I will give a technical review of LÖVE 0.7.0.<br />
<span id="more-314"></span><br />
The changelog containing changes from 0.6.2 to 0.70 lists:</p>
<blockquote><h2>Additions</h2>
<ul>
<li>Added love.thread.</li>
<li>Added love.font.</li>
<li>Added love.graphics.Framebuffer.</li>
<li>Added Source:play, Source:pause, etc.</li>
<li>Added Source:isStatic().</li>
<li>Added get/setPosition, get/setVelocity, and get/setDirection to Source.</li>
<li>Added get/setGroupIndex to CircleShape and PolygonShape.</li>
<li>Added Font:getWrap.</li>
<li>Added identity field to love.conf.</li>
<li>Added love.quit callback.</li>
<li>Added love.focus callback.</li>
<li>Added extra meter parameter to love.physics.newWorld.</li>
<li>Added love.graphics.setIcon.</li>
<li><em>—Snip</em></li>
</ul>
</blockquote>
<p>Truth be told, I have no idea what I should write here. I can only compare it to <a href="http://www.pygame.org/news.html">PyGame</a>, wich is completely different. For example, PyGame expects you to take control of the main loop yourself, while LÖVE doesn&#8217;t (although you can if you want to, since 0.6.0).</p>
<p>Back to propaganda it is.</p>
<p>Aside from all the cool new things in 0.7.0 (you&#8217;ve seen some of them in the changelog), the next version will bring loads of candy. Video playback (Theora and/or WebM) is on the list, but it is hard to tell how close it really is, since it needs a back end and the good ones tend to be gigantic Eldritch abominations.</p>
<p>What more is there to say? I&#8217;ve mentioned that it makes making games and other programs ridiculously easy, haven&#8217;t I?</p>
<p>Thus ends this blog post on a rather uninspired note. How about this: when the time comes for version 1.0.0 to be released, I will cover it, properly. Until that time, this blog will feature mad ravings and whatnot, like it always has done.</p>
<p>You know it will anyway.</p>
<br />Filed under: <a href='http://gvxdev.wordpress.com/category/development/'>Development</a> Tagged: <a href='http://gvxdev.wordpress.com/tag/failure-of-journalism/'>failure of journalism</a>, <a href='http://gvxdev.wordpress.com/tag/love/'>löve</a>, <a href='http://gvxdev.wordpress.com/tag/love-2d/'>love-2d</a>, <a href='http://gvxdev.wordpress.com/tag/propaganda/'>propaganda</a>, <a href='http://gvxdev.wordpress.com/tag/technical-review/'>technical review</a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/gvxdev.wordpress.com/314/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/gvxdev.wordpress.com/314/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/gvxdev.wordpress.com/314/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/gvxdev.wordpress.com/314/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/gvxdev.wordpress.com/314/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/gvxdev.wordpress.com/314/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/gvxdev.wordpress.com/314/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/gvxdev.wordpress.com/314/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/gvxdev.wordpress.com/314/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/gvxdev.wordpress.com/314/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/gvxdev.wordpress.com/314/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/gvxdev.wordpress.com/314/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/gvxdev.wordpress.com/314/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/gvxdev.wordpress.com/314/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=gvxdev.wordpress.com&amp;blog=5303508&amp;post=314&amp;subd=gvxdev&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://gvxdev.wordpress.com/2011/01/28/the-power-of-love/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/41a9c3304eed6c695c3dfe70b4e4399c?s=96&#38;d=http%3A%2F%2F0.gravatar.com%2Favatar%2Fad516503a11cd5ca435acc9bb6523536%3Fs%3D96&#38;r=G" medium="image">
			<media:title type="html">gvx</media:title>
		</media:content>
	</item>
		<item>
		<title>I have the worst blog post titles</title>
		<link>http://gvxdev.wordpress.com/2010/12/26/i-have-the-worst-blog-post-titles/</link>
		<comments>http://gvxdev.wordpress.com/2010/12/26/i-have-the-worst-blog-post-titles/#comments</comments>
		<pubDate>Sun, 26 Dec 2010 09:49:25 +0000</pubDate>
		<dc:creator>Robin Wellner</dc:creator>
				<category><![CDATA[Other]]></category>
		<category><![CDATA[anarchy-tagging]]></category>
		<category><![CDATA[anarchytagging]]></category>
		<category><![CDATA[worst titles]]></category>
		<category><![CDATA[you're not reading any of this are you?]]></category>

		<guid isPermaLink="false">http://gvxdev.wordpress.com/?p=637</guid>
		<description><![CDATA[You can see it for yourself in the archive. In addition, these are the posts I am currently writing: The Power of LÖVE Along comes the Stork And yes, this post is mainly intended to get myself to finish them. Filed under: Other Tagged: anarchy-tagging, anarchytagging, worst titles, you're not reading any of this are [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=gvxdev.wordpress.com&amp;blog=5303508&amp;post=637&amp;subd=gvxdev&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>You can see it for yourself in the archive. In addition, these are the posts I am currently writing:</p>
<ul>
<li>The Power of LÖVE</li>
<li>Along comes the Stork</li>
</ul>
<p>And yes, this post is mainly intended to get myself to finish them.</p>
<br />Filed under: <a href='http://gvxdev.wordpress.com/category/other/'>Other</a> Tagged: <a href='http://gvxdev.wordpress.com/tag/anarchy-tagging/'>anarchy-tagging</a>, <a href='http://gvxdev.wordpress.com/tag/anarchytagging/'>anarchytagging</a>, <a href='http://gvxdev.wordpress.com/tag/worst-titles/'>worst titles</a>, <a href='http://gvxdev.wordpress.com/tag/youre-not-reading-any-of-this-are-you/'>you're not reading any of this are you?</a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/gvxdev.wordpress.com/637/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/gvxdev.wordpress.com/637/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/gvxdev.wordpress.com/637/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/gvxdev.wordpress.com/637/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/gvxdev.wordpress.com/637/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/gvxdev.wordpress.com/637/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/gvxdev.wordpress.com/637/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/gvxdev.wordpress.com/637/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/gvxdev.wordpress.com/637/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/gvxdev.wordpress.com/637/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/gvxdev.wordpress.com/637/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/gvxdev.wordpress.com/637/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/gvxdev.wordpress.com/637/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/gvxdev.wordpress.com/637/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=gvxdev.wordpress.com&amp;blog=5303508&amp;post=637&amp;subd=gvxdev&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://gvxdev.wordpress.com/2010/12/26/i-have-the-worst-blog-post-titles/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/41a9c3304eed6c695c3dfe70b4e4399c?s=96&#38;d=http%3A%2F%2F0.gravatar.com%2Favatar%2Fad516503a11cd5ca435acc9bb6523536%3Fs%3D96&#38;r=G" medium="image">
			<media:title type="html">gvx</media:title>
		</media:content>
	</item>
	</channel>
</rss>
