<?xml version="1.0"?>
<!-- name="generator" content="blosxom/2.0" -->
<!DOCTYPE rss PUBLIC "-//Netscape Communications//DTD RSS 0.91//EN" "http://my.netscape.com/publish/formats/rss-0.91.dtd">

<rss version="0.91">
  <channel>
    <title>zoneToRA / ToRAsConsole   </title>
    <link>http://www.zonetora.co.uk</link>
    <description>Tristan Allwood's weblog</description>
    <language>en</language>

  <item>
    <title>Lost</title>
    <link>http://www.zonetora.co.uk/2008/02/03#Kidnapped</link>
    <description>
&lt;p style=&quot;text-align: center&quot;&gt;
&lt;a href=&quot;http://www.zonetora.co.uk/NonBlog/blogImages/cambridgeLost.png&quot;&gt;&lt;img
src=&quot;http://www.zonetora.co.uk/NonBlog/blogImages/cambridgeLost.png&quot; width=320 style=&quot;text-align: center&quot; alt=&quot;Click for full version&quot;/&gt;&lt;/a&gt;
&lt;/p&gt;

&lt;p&gt;
This was a real conversation with a cabbie while trying to get to MSR for a meeting about things I could do for my PhD.  Needless to say we did find it in the end.  Next time I guess I'll have to make sure I have the address of where I'm going...
&lt;/p&gt;</description>
  </item>
  <item>
    <title>Seeing only stars...</title>
    <link>http://www.zonetora.co.uk/2008/01/22#SMG</link>
    <description>
Yes, this blog entry is late this week.  I have an excuse.

&lt;p style=&quot;text-align: center&quot;&gt;
&lt;a href=&quot;http://www.zonetora.co.uk/NonBlog/blogImages/stars.png&quot;&gt;&lt;img
src=&quot;http://www.zonetora.co.uk/NonBlog/blogImages/stars.png&quot; width=320 style=&quot;text-align: center&quot; alt=&quot;Cli
version&quot;/&gt;&lt;/a&gt;
&lt;/p&gt;


&lt;p&gt; I never claimed it was a &lt;i&gt;good&lt;/i&gt; excuse though.  &lt;b&gt;Super Mario
Galaxy&lt;/b&gt; is, however, an awesome game. It's great fun, slightly addictive, and
a great example of a simple game that works well without being overcomplex.&lt;/p&gt;

&lt;p&gt;Now there's nothing in the game thats fundamentally new.  Platforming in 3D
was done in Mario 64 and Mario Sunshine, as-well as the Tomb-Raider series and
many other games since.  Even the format of many small levels you keep
re-visiting to find different stars in was from Mario 64.  &lt;/p&gt;

&lt;p&gt; What about gravity and planets?  Well there were 2D scrollers on the NES that
had ways of swapping gravity.  In 3D?  Variable gravity was a great feature in
Prey, and Zelda had areas with magnetic boots that were tantamount to the same
thing.  Planet and platform hopping in 3D is reminiscent of the previous Mario 
games, and the likes of Monkey Ball and DK Jungle Beat.  I may concede that (as
far as I know) this is the first game I've seen where can jump between platforms
in 3D and quasi-float round them due to gravity.
&lt;/p&gt; 

&lt;p&gt; Mentioning DKJB, I should point out that quite a few things seem to have
migrated into the Mario franchise from that game - including (or perhaps
especially) enemies.  This seems sad, as there were plenty of SMB enemies that
could be used, but they seem to continually become dropped and the existing
ones are now more caricatures of their original forms from the earlier games,
and, annoyingly, becoming easier to kill as the games evolve.&lt;/p&gt;

&lt;p&gt;For example:&lt;/p&gt;

&lt;ul&gt;

&lt;li&gt;Turtles with shells are no longer a mainstay enemy,
instead they are essentially infinitely re-spawning power-ups.&lt;/li&gt;

&lt;li&gt;Cacti, the once feared enemy that required a shell or a cape deplete in size now
just need to be &quot;span&quot; at.&lt;/li&gt;

&lt;li&gt;Where are the hammer bros or the sumo bros?&lt;/li&gt;

&lt;/ul&gt;

&lt;p&gt;At least boo's can't be trivially killed now.&lt;/p&gt;


&lt;p&gt;Anyways, I seem to have digressed.  The point is, it is a fun game, and just
when you think you've seen all the formulaic things it can throw at you, it adds
just one more new thing to try out / see / do.  Green stars, tricky (but much
overrated ;)) trial galaxies, hungry stars, hidden stars, power stars, Luigi
stars, comets, rabbits, goomba's, planets shaped like a Yoshi head...it's all
there :).&lt;/p&gt;

&lt;p&gt;The sound track is also stunning.  Apparently it's live-recorded orchestra
and disc-streamed.  A very good move, and it really sets the mood, especially
given a lot of the music are 'Mario classics' but re-recorded very nicely.&lt;/p&gt;

&lt;p&gt;And now, CSI is on...normal service may resume next weekend...or I may talk
about card magic.&lt;/p&gt;</description>
  </item>
  <item>
    <title>Simplifying Code</title>
    <link>http://www.zonetora.co.uk/2008/01/13#SimplifyTemplates1</link>
    <description>
&lt;p&gt;The process my brain goes through when programming...&lt;/p&gt;

&lt;p style=&quot;text-align: center&quot;&gt;
&lt;a href=&quot;http://www.zonetora.co.uk/NonBlog/blogImages/haskellvsjava1.png&quot;&gt;&lt;img
src=&quot;http://www.zonetora.co.uk/NonBlog/blogImages/haskellvsjava1.png&quot; width=320 style=&quot;text-align: center&quot; alt=&quot;Click for full
version&quot;/&gt;&lt;/a&gt;
&lt;/p&gt;

&lt;p&gt;And now to prove the point of the diagram...&lt;/p&gt;

&lt;p&gt; A task I've come across several times while programming is taking a list
describing a template, and completing it with input from elsewhere.&lt;/p&gt;

&lt;p&gt;Let me describe further (this post is a literate Haskell file...)&lt;/p&gt;

&lt;div class=&quot;code&quot;&gt;
&gt; import Data.Maybe           
&gt; import Control.Monad       
&gt; import Control.Monad.State
&gt; import Control.Arrow        

&lt;/div&gt;

&lt;p&gt;For example, the list:&lt;/p&gt;

&lt;div class=&quot;code&quot;&gt;
&gt; testTemplate = [Just &quot;This&quot;, Nothing, Just &quot;a&quot;, Nothing, Nothing]

&lt;/div&gt;

&lt;p&gt; describes a template, where the first and third elements are fixed, but the
remaining (second, fourth and fifth) elements come from external input.  &lt;/p&gt;

&lt;p&gt;So if &lt;span class=&quot;code&quot;&gt;testTemplate&lt;/span&gt; was used with the following filling...&lt;/p&gt;

&lt;div class=&quot;code&quot;&gt;
&gt; testFilling = [&quot;is&quot;, &quot;simple&quot;, &quot;test&quot;]

&lt;/div&gt;

&lt;p&gt;
The result we expect would be:
&lt;/p&gt;

&lt;div class=&quot;code&quot;&gt;
&gt; testResult = words &quot;This is a simple test&quot;

&lt;/div&gt;

&lt;p&gt; So we need to implement a function of type &lt;span class=&quot;code&quot;&gt;[Maybe
String] -&gt; [String] -&gt; [String]&lt;/span&gt;, and it should make our test give back
&lt;span class=&quot;code&quot;&gt;True&lt;/span&gt;.  &lt;/p&gt;

&lt;div class=&quot;code&quot;&gt;
&gt; test :: ([Maybe String] -&gt; [String] -&gt; [String]) -&gt; Bool       
&gt; test combiner = testResult == combiner testTemplate testFilling

&lt;/div&gt;

&lt;p&gt; Now the most explicit way to do this is to use pattern matching, and just
work through the cases on the template list...  &lt;/p&gt;

&lt;div class=&quot;code&quot;&gt;
&gt; combinerRec :: [Maybe String] -&gt; [String] -&gt; [String]            
&gt; combinerRec [] _                      = []                      
&gt; combinerRec ((Just t):ts) filling     = t:combinerRec ts filling
&gt; combinerRec (Nothing:ts) (f:filling)  = f:combinerRec ts filling

&lt;/div&gt;

&lt;p&gt; Thing is, I rarely ever use explicit pattern matching nowadays (especially
when it comes to lists and maybe), as there are a whole host of combinators
that do it for you.  Also using combinators over pattern matching can make your
code a lot more readable.  And anyways, explicitly writing out the recursion
fills me with an ill feeling.&lt;/p&gt;

&lt;p&gt; So what are we to do?  Well one trick is to notice that the filling is
actually some state in the algorithm.  For each template element, we peel the
next element off the state or just carry it across, depending on whether the
template element is &lt;span class=&quot;code&quot;&gt;Nothing&lt;/span&gt; or &lt;span
class=&quot;code&quot;&gt;Just&lt;/span&gt;.  &lt;/p&gt;

&lt;div class=&quot;code&quot;&gt;
&gt; combinerState1 :: [Maybe String] -&gt; [String] -&gt; [String]
&gt; combinerState1 = evalState . mapM (maybe getNext return)
&gt;   where                                                
&gt;     getNext = do                                      
&gt;       (h:tl) &lt;- get                                  
&gt;       put tl                                        
&gt;       return h                                     

&lt;/div&gt;

&lt;p&gt; Well that's concise-ish, and (assuming you know the standard libraries) is
quite clear / reads well.  Of course &lt;span class=&quot;code&quot;&gt;getNext&lt;/span&gt;'s
definition is a bit verbose, but it's hidden by a meaningful name.&lt;p&gt;

&lt;p&gt;But wait, there's more!  If you stare at &lt;span class=&quot;code&quot;&gt;getNext&lt;/span&gt;
for a while, with the definition of &lt;span class=&quot;code&quot;&gt;State&lt;/span&gt; next to it,
  you'll realise that &lt;span class=&quot;code&quot;&gt;State (\(h:tl) -&gt; (h,tl))&lt;/span&gt; does
the same thing. So we can rewrite inlining &lt;span class=&quot;code&quot;&gt;getNext&lt;/span&gt; and using arrow
combinators instead of the explicit lambda...&lt;/p&gt;

&lt;div class=&quot;code&quot;&gt;
&gt; combinerState2 :: [Maybe String] -&gt; [String] -&gt; [String]
&gt; combinerState2 = evalState . mapM (maybe (State (head &amp;&amp;&amp; tail)) return)

&lt;/div&gt;

&lt;p&gt; Arn't we clever?  Possibly too clever, while it is a 1-liner, it doesn't
(to me) read like psuedo-english. I'd probably use something like this in
reality, as (I think) it reads slightly better.  &lt;/p&gt;

&lt;div class=&quot;code&quot;&gt;
&gt; combinerState3 :: [Maybe String] -&gt; [String] -&gt; [String]
&gt; combinerState3 template = evalState $ forM template (maybe getNext return)
&gt;   where                                                                  
&gt;     getNext = State (head &amp;&amp;&amp; tail)                                     

&lt;/div&gt;

&lt;p&gt; So there you have it, how to spend at least an hour and a half blogging
about how you can simplify a 3 line haskell function down to one line, and then
realising that a different 3 line function reads better if you know lots of
esoteric parts of the Haskell standard libraries.  At least I havn't tried to
write a monad tutorial...&lt;/p&gt;</description>
  </item>
  </channel>
</rss>