<?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>TinyRobot</title>
	<atom:link href="http://tinyrobot.co.uk/blog/feed/" rel="self" type="application/rss+xml" />
	<link>http://tinyrobot.co.uk/blog</link>
	<description></description>
	<lastBuildDate>Fri, 27 Jan 2012 16:19:41 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>Making Games in Javascript with Underscore.js and FP</title>
		<link>http://tinyrobot.co.uk/blog/making-games-in-javascript-with-underscore-js-and-fp/</link>
		<comments>http://tinyrobot.co.uk/blog/making-games-in-javascript-with-underscore-js-and-fp/#comments</comments>
		<pubDate>Fri, 27 Jan 2012 15:57:23 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[functional programming]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[partial application]]></category>

		<guid isPermaLink="false">http://tinyrobot.co.uk/blog/?p=47</guid>
		<description><![CDATA[I&#8217;ve been toying with the idea of creating games using a functional approach recently. I had a lot of fun last year writing a cut down PushButton Engine clone in Javascript, (which I&#8217;ve started rewriting) but since I&#8217;ve started learning Haskell recently I&#8217;ve really wanted to try out a more functional approach to making games. [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve been toying with the idea of creating games using a functional approach recently. I had a lot of fun last year writing a cut down <a href="http://pushbuttonengine.com/" title="PushButtonEngine" target="_blank">PushButton Engine</a> clone in Javascript, (which I&#8217;ve started <a href="https://github.com/tinyrobot/TinyGE" title="TinyGE" target="_blank">rewriting</a>) but since I&#8217;ve started learning Haskell recently I&#8217;ve really wanted to try out a more functional approach to making games.</p>
<p>First of all I should probably list some resources that I&#8217;ve found helpful so far with some descriptions:</p>
<p><a href="http://isi.uni-bremen.de/~cxl/habil/papers/jfp03.pdf" title="Haskell In Space" target="_blank">Haskell In Space (pdf)</a> &#8211; Has information and examples for moving spatials around and event handling (Haskell)<br />
<a href="http://prog21.dadgum.com/23.html" title="Purely Functional Retrogames" target="_blank">Purely Functional Retrogames</a> &#8211; Has examples about how to handle state; in these articles state is threaded around.<br />
<a href="http://www.lisperati.com/casting.html" title="Casting SPELS" target="_blank">Casting SPELs</a> &#8211; Make an adventure game in LISP.</p>
<p>What I&#8217;ll present is just very early playing around and shouldn&#8217;t be taken as a &#8216;right&#8217; way to do it as I&#8217;m still finding my feet with these concepts. I have a feeling that my keyboard handling code should use a Monad (as Haskell uses an IO Monad), and I&#8217;m not sure about using map and function composition in place of a traditional &#8216;update&#8217;, so any comments are welcomed!</p>
<p>This little program, when used in a page with a canvas element #canvas, and an image #image, will make some #images move around. W,A,S and D will affect their movement. <a href="https://gist.github.com/1689178" title="Gist" target="_blank">Gist Here</a>.</p>
<p>I&#8217;m just going to break down the more important parts of it here:</p>
<p>1. Replacement &#8216;update/render&#8217; loop:</p>
<pre class="prettyprint lang-javascript">
//we return a function here that closes over the initial local variables
//also means we can call _.delay with the same or different args to potentially evolve the loop
function iterate(input,spatials,context,image){
	return function(){
		context.clearRect(0,0,500,500); //still need to figure out where to move this
		var _spatials = _.map(spatials,_.compose(processEvents(input),move,render(context,image)));
		_spatials = _.filter(_spatials,inViewport);
		_.delay(iterate(input,_spatials,context,image),1000/60);
	};
}
</pre>
<p>In this snippet I&#8217;m using underscore&#8217;s _.delay, which works much like setTimeout. I&#8217;m currently combining updating and rendering for simplicity&#8217;s sakes, and so our main &#8216;iterate&#8217; function takes everything it needs to update and render the spatial list. This is good in several ways, because it means we can modify the parameters to _.delay if we want to during execution, it allows for a neater recursive structure and it potentially allows us to create multiple iterate()&#8217;s with differing initial state (eg. var iterate1 = iterate(mouseinput,enemyspatials,otherrenderer,etc)). Further it means we can defer starting this loop if we want to. </p>
<p>So those are my initial thoughts about the structure &#8211; the next decision I&#8217;ve made is to use _.map on my list of spatials, and then make the functions that operate on those spatials composeable (via partial application in some cases). This makes the operations performed on each spatial clear and easily readable (and a one-liner), which I like. I&#8217;m not sure about the use of filter() for culling as particularly it means iterating over the list again. I would also like to move the context stuff out somewhere (a Render monad perhaps?).</p>
<p>2. Event processing and Rendering (but still taking and returning a spatial):</p>
<pre class="prettyprint lang-javascript">
function processEvents(keys){
	return function(spatial){
		if(keys[68]){ spatial.vx += 0.1; }
		if(keys[83]){ spatial.vy += 0.1; }
		if(keys[65]){ spatial.vx -= 0.1; }
		if(keys[87]){ spatial.vy -= 0.1; }
		return spatial;
	};
}

function render(context,image){
	return function(spatial){
		context.drawImage(image,spatial.x,spatial.y);
		return spatial;
	};
}
</pre>
<p>In both of these cases I&#8217;m using partial application to fix two inital bound variables and return a function that uses them, but itself takes only one parameter. This makes these functions composeable since render(ctx,img) returns f(spatial) -> spatial. I would like to make the &#8216;keys&#8217; object more formally defined, and obviously it shouldn&#8217;t have hardcoded keyCodes &#8211; I would also like to try and implement some kind of IO Monad that would abstract this (once I&#8217;ve understood monads better!). Also this code should really create a new spatial and return that new spatial.</p>
<p>3. Move/Generic update rules:</p>
<pre class="prettyprint lang-javascript">
function move(spatial){
	spatial.x += spatial.vx;
	spatial.y += spatial.vy;
	return spatial;
}
</pre>
<p>Finally, this bit just moves a spatial by incrementing its 2d position vector by its 2d velocity vector. This part is likely to become far more complex once other rules are considered, but hopefully keeping the interface Spatial -> Spatial should mean that writing composeable update rules should be easier.</p>
<p>So that&#8217;s all really for this initial play around with the concepts, I&#8217;ll add more posts as I improve upon these initial concepts. Any comments would be welcomed, since material on functional programming in games seems sparse from my googling. So far I&#8217;m quite happy with the approach, since just by looking at the four core functions you can figure out what the program is doing fairly easily, and I find it structually and aesthetically quite pleasing <img src='http://tinyrobot.co.uk/blog/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
]]></content:encoded>
			<wfw:commentRss>http://tinyrobot.co.uk/blog/making-games-in-javascript-with-underscore-js-and-fp/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Python in Terminal IDE for Android</title>
		<link>http://tinyrobot.co.uk/blog/python-in-terminal-ide-for-android/</link>
		<comments>http://tinyrobot.co.uk/blog/python-in-terminal-ide-for-android/#comments</comments>
		<pubDate>Thu, 26 Jan 2012 23:12:33 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://tinyrobot.co.uk/blog/?p=43</guid>
		<description><![CDATA[I wanted to see if I could get access to the python interpreter used by SL4A in Terminal IDE so that I could, obviously, use a terminal environment to create and run scripts since then I can use vim, and I can use tmux to give me a decent working environment with my tablet in [...]]]></description>
			<content:encoded><![CDATA[<p>I wanted to see if I could get access to the python interpreter used by <a href="http://code.google.com/p/android-scripting/" title="SL4A" target="_blank">SL4A</a> in <a href="http://www.spartacusrex.com/terminalide.htm" title="Terminal IDE" target="_blank">Terminal IDE</a> so that I could, obviously, use a terminal environment to create and run scripts since then I can use vim, and I can use <a href="http://tmux.sourceforge.net/" title="tmux" target="_blank">tmux</a> to give me a decent working environment with my tablet in landscape mode. I googled around for awhile and didn&#8217;t manage to find anything explicit on how to set this up, and then figured out how to use google and found this <a href="http://blog.anantshri.info/android-standalone-python/" title="Android Standalone Python" target="_blank">blog post</a> which links to a <a href="http://code.google.com/p/python-for-android/source/browse/python-build/standalone_python.sh" title="script" target="_blank">script</a> from the p4a (python for android) repository. I&#8217;ve reduced the script a bit (shown below), removing the egg cache and adding a constant for the base path. I&#8217;ve also not bothered exporting the external storage environment variable. If you want these things, see the original script mentioned previously <img src='http://tinyrobot.co.uk/blog/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p>Please note the below takes into account just using python with Terminal IDE, and I&#8217;ve not linked anything to /system/bin because not everyone who has Terminal IDE installed will want to have root, so our python script is kept in Terminal IDE&#8217;s home, which in turn is added to the path in .bashrc.</p>
<p>So I created the below file as ~/python:</p>
<pre class="prettyprint lang-bash">
#!/system/bin/sh
BASE=/data/data/com.googlecode.pythonforandroid/files/python
export PYTHONPATH=${PYTHONPATH}:${BASE}/lib/python2.6/lib-dynload
export PYTHONHOME=${BASE}
export LD_LIBRARY_PATH=${BASE}/lib
${BASE}/bin/python &quot;$@&quot;
</pre>
<p>Then made it executable and added ~/ to my $PATH in ~/.bashrc:</p>
<pre class="prettyprint lang-bash">
terminal++@127.0.0.1:~$ chmod +x ~/python
terminal++@127.0.0.1:~$ echo export PATH=$PATH:~/ &gt;&gt; ~/.bashrc
</pre>
<p>And now when you restart Terminal IDE, you should be able to type &#8216;python&#8217; to get the interactive python interpreter!</p>
]]></content:encoded>
			<wfw:commentRss>http://tinyrobot.co.uk/blog/python-in-terminal-ide-for-android/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>SSH and GIT on Android with Terminal IDE</title>
		<link>http://tinyrobot.co.uk/blog/ssh-and-git-on-android-with-terminal-ide/</link>
		<comments>http://tinyrobot.co.uk/blog/ssh-and-git-on-android-with-terminal-ide/#comments</comments>
		<pubDate>Thu, 26 Jan 2012 17:28:38 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://tinyrobot.co.uk/blog/?p=37</guid>
		<description><![CDATA[I just discovered Terminal IDE, which is a nice package for Android containing a useful collection of tools like ssh, git, tmux, vim and more! However, I came up against a slight issue since I have configured my VPS to only use public key authentication for SSH. This also caused me some issues using GIT [...]]]></description>
			<content:encoded><![CDATA[<p>I just discovered <a href="http://www.spartacusrex.com/terminalide.htm" title="Terminal IDE" target="_blank">Terminal IDE</a>, which is a nice package for Android containing a useful collection of tools like ssh, git, tmux, vim and more! However, I came up against a slight issue since I have configured my VPS to only use public key authentication for SSH. This also caused me some issues using GIT with it and with GitHub. Funnily enough I couldn&#8217;t find much information about it on google, particularly about using dropbear as an SSH client &#8211; I eventually stumbled on <a href="http://tumblelog.jauderho.com/post/151678345/using-dropbear-with-git" title="Using Dropbear with Git" target="_blank">Using dropbear with git</a>, which is useful after reading <a href="http://yorkspace.wordpress.com/2009/04/08/using-public-keys-with-dropbear-ssh-client/" title="Using Public Keys with Dropbear SSH client" target="_blank">Using Public Keys with Dropbear SSH client</a>. I&#8217;m going to briefly combine the two mini-tutorials into one place, more for my own sanity than anything else (and also to test my lovely syntax highlighter):</p>
<p><span id="more-37"></span></p>
<p>Create your key (assumes ~/.ssh exists, it did for me):</p>
<pre class="prettyprint lang-bash">
terminal++@127.0.0.1:~$ dropbearkey -t rsa -f ~/.ssh/id_rsa
</pre>
<p>Convert the key to openssh format, outputting to the file my_key in the same directory:</p>
<pre class="prettyprint lang-bash">
terminal++@127.0.0.1:~$ dropbearkey -y -f ~/.ssh/id_rsa | grep &quot;^ssh-rsa&quot; &gt;&gt; my_key
</pre>
<p>At this point, you should probably copy up the contents of my_key to your server&#8217;s authorized_keys file (or add to your GitHub keys, for example).</p>
<p>Now we will create a simple shell script as per the first tutorial linked above, but we are going to amend it slightly &#8211; if you are using the Terminal IDE one of the benefits to users who haven&#8217;t rooted is that, well, they don&#8217;t have to root &#8211; so we&#8217;re going to create our script in ~/sssh instead of anywhere else:</p>
<pre class="prettyprint lang-bash">
#!/bin/sh
#location is ~/sssh
ssh -i ~/.ssh/id_rsa $*
</pre>
<p>Finally, we&#8217;re just going to change our GIT_SSH environment variable:</p>
<pre class="prettyprint lang-bash">
terminal++@127.0.0.1:~$ echo export GIT_SSH=~/sssh &gt;&gt; .bashrc
</pre>
<p>Now you should be good to go!</p>
]]></content:encoded>
			<wfw:commentRss>http://tinyrobot.co.uk/blog/ssh-and-git-on-android-with-terminal-ide/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Migrated to Linode</title>
		<link>http://tinyrobot.co.uk/blog/migrated-to-linode/</link>
		<comments>http://tinyrobot.co.uk/blog/migrated-to-linode/#comments</comments>
		<pubDate>Wed, 25 Jan 2012 14:05:37 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://tinyrobot.co.uk/blog/?p=8</guid>
		<description><![CDATA[Finally migrated most stuff to Linode and cancelled other accounts! Yay]]></description>
			<content:encoded><![CDATA[<p>Finally migrated most stuff to Linode and cancelled other accounts! Yay</p>
]]></content:encoded>
			<wfw:commentRss>http://tinyrobot.co.uk/blog/migrated-to-linode/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

