<?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>Slyfox &#187; programming</title>
	<atom:link href="http://slyfox.za.net/tag/programming/feed/" rel="self" type="application/rss+xml" />
	<link>http://slyfox.za.net</link>
	<description>Concentrated awesome</description>
	<lastBuildDate>Sun, 30 Aug 2009 18:29:10 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Ugly Code And Why It&#8217;s Good</title>
		<link>http://slyfox.za.net/2009/02/ugly-code-and-why-its-good/</link>
		<comments>http://slyfox.za.net/2009/02/ugly-code-and-why-its-good/#comments</comments>
		<pubDate>Tue, 17 Feb 2009 18:49:50 +0000</pubDate>
		<dc:creator>slyfox</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[programming]]></category>
		<category><![CDATA[Work]]></category>

		<guid isPermaLink="false">http://slyfox.za.net/?p=78</guid>
		<description><![CDATA[While helping a colleague with a defect regarding things that should not happen but were and caused the whole tower of sticks to come tumbling down, I noticed a block of code that follows more or less the gist of the pseudo-sample below:
if(lots of conditions)
{
&#160;&#160;&#160;&#160;doSomeStringCopies();
&#160;&#160;&#160;&#160;if(a certain condition)
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;doSomething();
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;doSomethingElse();
&#160;&#160;&#160;&#160;doFinalStringCopies();
}
Bear in mind that the consistency of indentation of [...]]]></description>
			<content:encoded><![CDATA[<p>While helping a colleague with a defect regarding things that should not happen but were and caused the whole tower of sticks to come tumbling down, I noticed a block of code that follows more or less the gist of the pseudo-sample below:</p>
<p><code>if(lots of conditions)<br />
{<br />
&nbsp;&nbsp;&nbsp;&nbsp;doSomeStringCopies();<br />
&nbsp;&nbsp;&nbsp;&nbsp;if(a certain condition)<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;doSomething();<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;doSomethingElse();<br />
&nbsp;&nbsp;&nbsp;&nbsp;doFinalStringCopies();<br />
}</code></p>
<p>Bear in mind that the consistency of indentation of the actual code was nowhere as nice as above.</p>
<p>Notice the problem? <kbd>doSomethingElse()</kbd> will be called irrespective of the secondary condition, resulting in bad things happening because a certain field does not contain a valid value for the doing of something else, but is entirely valid in terms of the business rule.</p>
<p>This is why you <em>always</em> surround your compound code structures with braces: because you never know when someone&#8217;s going to slide a &#8220;fix&#8221; into your code and neglects to add the braces. Several people (who have obviously never been burnt by this problem, and if they have, they should have their keyboard license removed from them) might think that bracing a compound structure which contains only one statement makes the code look uglier or more unreadable, but it definitely makes it a lot more maintainable.</p>
<p>(As an aside, I have a feeling that this is one of my more poorly written entries. Shame on me, I know.)</p>
]]></content:encoded>
			<wfw:commentRss>http://slyfox.za.net/2009/02/ugly-code-and-why-its-good/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>MegaTrader I: The Premise</title>
		<link>http://slyfox.za.net/2009/01/megatrader-i-the-premise/</link>
		<comments>http://slyfox.za.net/2009/01/megatrader-i-the-premise/#comments</comments>
		<pubDate>Mon, 12 Jan 2009 20:28:43 +0000</pubDate>
		<dc:creator>slyfox</dc:creator>
				<category><![CDATA[Game Development]]></category>
		<category><![CDATA[Games]]></category>
		<category><![CDATA[j2me]]></category>
		<category><![CDATA[mobile]]></category>
		<category><![CDATA[programming]]></category>

		<guid isPermaLink="false">http://slyfox.za.net/?p=67</guid>
		<description><![CDATA[A few months ago, I started working on a J2ME game called MegaTrader, which eventually fell by the wayside as I finished up on my honours work and settled into my new work. Lately, though, I&#8217;ve been spending some time again drafting ideas and notes on the game; notes I thought I&#8217;d write up here [...]]]></description>
			<content:encoded><![CDATA[<p>A <a href="/2008/10/megatrader/">few months ago</a>, I started working on a J2ME game called MegaTrader, which eventually fell by the wayside as I finished up on my honours work and settled into my new work. Lately, though, I&#8217;ve been spending some time again drafting ideas and notes on the game; notes I thought I&#8217;d write up here for the sake of commentary and the sake of getting it down in written form.</p>
<p><span id="more-67"></span></p>
<p>So, let&#8217;s start at the most basic iteration of the game itself, ignoring any details such as interface and representation. As I stated in the original article, the game can be summed up as <a href="http://en.wikipedia.org/wiki/Dope_Wars">Dope Wars</a> in space. Thus, the mechanics of the game may be summed up as follows:</p>
<ol>
<li><strong>Sell</strong> any inventory so as to make a profit.</li>
<li><strong>Buy</strong> more inventory at a low enough price to ensure a profit in the future (the nearer in the future and the higher the profit, the better).</li>
<li><strong>Travel</strong> to a different location, repeating the process from step 1.</li>
</ol>
<p>This process is repeated until a pre-set time limit is reached, with travelling using one time unit, and inventory actions being &#8220;free&#8221; actions. The end goal of the game is to amass as much wealth as possible within the time limit, in effect competing with yourself to better a personal best high score.</p>
<p>Each turn, the inventory prices are randomised according to a item&#8217;s base value and some measure of variance. The skill involved in the game then relies on the player&#8217;s ability to recognise the base values and variances of inventory items, such that they know when a certain item is at a &#8220;low&#8221; or a &#8220;high&#8221; price, corresponding to a &#8220;buy&#8221; or a &#8220;sell&#8221; on the part of the player.</p>
<p>To add an additional level of randomisation to the game, random events may be introduced that alter the player&#8217;s stock or money levels, or drastically alter the variation in prices. This may be implemented using non-uniform random number generation, such that smaller variations are more common than extremely large variations, which may well count for a mere fraction of the random number space, but may potentially yield vast gains for the player.</p>
<p>At this basic level, the game does not invite many opportunities for strategic play, since the game may effectively be &#8220;broken&#8221; if a player collects enough data about inventory prices, disregarding any random fluctuations/events. The next article in this series will outline some of the ideas I&#8217;ve had to expand the gameplay to make the game more interesting and challenging to a player.</p>
]]></content:encoded>
			<wfw:commentRss>http://slyfox.za.net/2009/01/megatrader-i-the-premise/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Megatrader</title>
		<link>http://slyfox.za.net/2008/10/megatrader/</link>
		<comments>http://slyfox.za.net/2008/10/megatrader/#comments</comments>
		<pubDate>Thu, 16 Oct 2008 21:25:49 +0000</pubDate>
		<dc:creator>slyfox</dc:creator>
				<category><![CDATA[Game Development]]></category>
		<category><![CDATA[j2me]]></category>
		<category><![CDATA[megatrader]]></category>
		<category><![CDATA[mobile]]></category>
		<category><![CDATA[programming]]></category>

		<guid isPermaLink="false">http://slyfox.za.net/?p=21</guid>
		<description><![CDATA[For the past week, when I haven&#8217;t been working, I&#8217;ve been spending a good deal of my free time developing a J2ME mobile game. The basic premise is Dope Wars in space, albeit with less drugs and more futuristic trade goods. The inset image is the main menu screen running in the WTK emulator. Right [...]]]></description>
			<content:encoded><![CDATA[<div id="attachment_22" class="wp-caption alignleft" style="width: 160px"><a href="http://slyfox.za.net/wp-content/uploads/2008/10/mtemu1.jpg" rel="shadowbox[post-21];player=img;"><img src="http://slyfox.za.net/wp-content/uploads/2008/10/mtemu1-150x150.jpg" alt="Megatrader Main Menu" title="Megatrader Main Menu" width="150" height="150" class="size-thumbnail wp-image-22" /></a><p class="wp-caption-text">Megatrader Main Menu</p></div>
<p>For the past week, when I haven&#8217;t been working, I&#8217;ve been spending a good deal of my free time developing a <a href="http://java.sun.com/javame/index.jsp">J2ME</a> mobile game. The basic premise is Dope Wars in space, albeit with less drugs and more futuristic trade goods. The inset image is the main menu screen running in the <acronym title="Wireless ToolKit">WTK</acronym> emulator. Right now, I&#8217;m more or less at the point where I can actually start on getting the game up and running, having spent the time thus far on getting all the support functionality down (such as drawing text using my custom fonts and being able to easily support different resolutions, since I&#8217;ll be targeting at least <a href="http://en.wikipedia.org/wiki/Quarter_VGA">QVGA</a> and <a href="http://en.wikipedia.org/wiki/Common_Intermediate_Format">QCIF+</a> displays).</p>
<p>Initially, the game will be fairly simple, featuring only simple trading: buy at planet A, travel to planet B and sell, rinse and repeat until the time limit is hit, with random price fluctuations as per the drug busts in Dope Wars. In the future, there are a couple of distinguishing features I want to add to the game, such as competing against computer-controlled traders and being able to buy different ships which affect their cargo space and travel speed, amongst other things.</p>
<p><span id="more-21"></span></p>
<div id="attachment_23" class="wp-caption alignright" style="width: 160px"><a href="http://slyfox.za.net/wp-content/uploads/2008/10/mtemu2.jpg" rel="shadowbox[post-21];player=img;"><img src="http://slyfox.za.net/wp-content/uploads/2008/10/mtemu2-150x150.jpg" alt="Megatrader: Planet Screen WIP" title="Megatrader: Planet Screen WIP" width="150" height="150" class="size-thumbnail wp-image-23" /></a><p class="wp-caption-text">Megatrader: Planet Screen WIP</p></div>
<p>For the ship travel speed to be meaningful, a distance matrix of the distances between the planets will be calculated at game initialisation, with the distance and travel speed affecting the number of days that elapse when travelling from one planet to the other. To make this an attractive option to the player, distant planets will have to have a higher bias for delivering higher yields (meaning prices are inflated or reduced more than normal), making trips to distant planets a potentially lucrative expedition, but on the other hand, may end up causing the player to lose precious time; and in this game, time is indeed money.</p>
<p>Another idea I toyed with was that of having a simple economy built in, especially if other traders are taken into account as well. If a trader reaches a planet before you and sells an enormous amount of one cargo, the demand will experience a sharp drop, causing the price to plummet. On the other hand, if you get to a planet and fill your ship&#8217;s cargo hold with a cargo type, supply decreases, and the price will increase to the next trader&#8217;s detriment.</p>
<p>An old favourite I&#8217;d thought about when designing an earlier trading game is that of black market goods. These goods perform a function similar to the distant planet idea, in that they are a potential source of a higher than normal income. Whereas distant planets are not guaranteed to have a higher price, black market goods will <em>always</em> fetch a higher price. The risk involved with black market goods is that the player stands a random chance of being caught by the authorities, resulting in the cargo being seized and the player receiving a hefty fine for their transgression.</p>
<p>There are a couple of other ideas on the whiteboard, so to speak, but for now I&#8217;ll be concentrating on getting the basics done and working, and figuring out the One And True game balance for the basic trade goods (i.e. pricing, fluctuation biases, etc.). Another thing that will limit the implementation of all these ideas is the possible limitations on code/data size on the mobile phone platforms: at the moment the QVGA version of Megatrader already weighs in 357KB. Most of the JAR&#8217;s size is caused by the background screens, which are rather varied in terms of their colour content. Since J2ME applications use PNG as image format, images that are not uniformly coloured and that do not feature consecutive strings of the same colour tend not to compress that well. Depending on how many screens I still have to add, this may or may not become an issue. If it does, I&#8217;ll have to drop a fair amount of the detail present in the screens, something I am loathe to do, since it&#8217;s about damn time we have a mobile Java game that looks <em>good</em>, for fuck&#8217;s sake.</p>
<p>Hopefully I&#8217;ll have a playable version of the game by the end of next week. And after that&#8230; well, maybe I&#8217;ll have a gander at that iPhone SDK. Or, considering I might be looking at getting a Windows Mobile phone soon, I&#8217;ll see what that old beast we call the .NET Compact Framework can do for the world. But that&#8217;s getting ahead of myself. I have to finish one version of the game first!</p>
]]></content:encoded>
			<wfw:commentRss>http://slyfox.za.net/2008/10/megatrader/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Terra</title>
		<link>http://slyfox.za.net/2008/10/terra/</link>
		<comments>http://slyfox.za.net/2008/10/terra/#comments</comments>
		<pubDate>Thu, 16 Oct 2008 20:11:58 +0000</pubDate>
		<dc:creator>slyfox</dc:creator>
				<category><![CDATA[University]]></category>
		<category><![CDATA[programming]]></category>

		<guid isPermaLink="false">http://slyfox.za.net/?p=14</guid>
		<description><![CDATA[One of the homework assignments for our Graphics course was to implement a terrain renderer using a quadtree structure. After reading up on it a bit, I attempted to implement the method described by Ulrich&#8217;s article (although I won&#8217;t lie: the working demo code given in the article helped a good deal with that part). [...]]]></description>
			<content:encoded><![CDATA[<div id="attachment_15" class="wp-caption aligncenter" style="width: 310px"><a href="http://slyfox.za.net/wp-content/uploads/2008/10/terra1.jpg" rel="shadowbox[post-14];player=img;"><img src="http://slyfox.za.net/wp-content/uploads/2008/10/terra1-300x233.jpg" alt="Terra: Full Heightfield" title="Terra" width="300" height="233" class="size-medium wp-image-15" /></a><p class="wp-caption-text">Terra: Full Heightfield</p></div>
<p>One of the homework assignments for our Graphics course was to implement a terrain renderer using a quadtree structure. After <a href="http://www.gamasutra.com/features/20000228/ulrich_01.htm">reading</a> up on it a bit, I attempted to implement the method described by Ulrich&#8217;s article (although I won&#8217;t lie: the working demo code given in the article helped a good deal with that part). The image above is the end result of the terrain renderer, along with the quaternion-based camera library I implemented for the previous assignment.</p>
<div id="attachment_16" class="wp-caption alignleft" style="width: 160px"><a href="http://slyfox.za.net/wp-content/uploads/2008/10/terra2.jpg" rel="shadowbox[post-14];player=img;"><img src="http://slyfox.za.net/wp-content/uploads/2008/10/terra2-150x150.jpg" alt="Terra: Wireframe Heightfield" title="Terra" width="150" height="150" class="size-thumbnail wp-image-16" /></a><p class="wp-caption-text">Terra: Wireframe Heightfield</p></div>
<p>The random terrain in this example was created by generating a 1024&#215;1024 image in GIMP using the Solid Noise filter and saving it as a PNG, which Terra uses to generate the heightmap. The image used to texture the terrain was created by applying a gradient map to the grayscale heightmap, and adding an embossed version of the grayscale heightmap on top of the gradient mapped heightmap to give the illusion of a directional light source.</p>
<p>The inset image is the same scene as the first image in this post, but rendered in wireframe mode. If one looks closely, one can see how the adaptive quadtree algorithm uses more triangles for high-detail parts of the heightmap, and less (&#8221;bigger&#8221;) triangles for less detailed parts.</p>
<p>Finally, the last image below is also the same scene as the other two images, but with a detail factor 2¼ times higher than the first two images, also rendered in wireframe, highlighting the increased number of triangles.</p>
<div id="attachment_17" class="wp-caption aligncenter" style="width: 310px"><a href="http://slyfox.za.net/wp-content/uploads/2008/10/terra3.jpg" rel="shadowbox[post-14];player=img;"><img src="http://slyfox.za.net/wp-content/uploads/2008/10/terra3-300x233.jpg" alt="Terra: High Detail Heightfield" title="Terra" width="300" height="233" class="size-medium wp-image-17" /></a><p class="wp-caption-text">Terra: High Detail Heightfield</p></div>
]]></content:encoded>
			<wfw:commentRss>http://slyfox.za.net/2008/10/terra/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Acceptance Testing With Selenium I</title>
		<link>http://slyfox.za.net/2008/10/acceptance-testing-with-selenium-i/</link>
		<comments>http://slyfox.za.net/2008/10/acceptance-testing-with-selenium-i/#comments</comments>
		<pubDate>Mon, 13 Oct 2008 19:38:30 +0000</pubDate>
		<dc:creator>slyfox</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[programming]]></category>

		<guid isPermaLink="false">http://slyfox.za.net/?p=12</guid>
		<description><![CDATA[The freelance work I&#8217;m currently doing called for some testing after I significantly changed the underlying framework&#8217;s internals. Considering I&#8217;d been spoilt with the idea of automating any and all testing when I was going through my Ruby on Rails phase, I started looking around for something similar in the PHP camp. The most important [...]]]></description>
			<content:encoded><![CDATA[<p>The freelance work I&#8217;m currently doing called for some testing after I significantly changed the <a href="http://edcms.net/">underlying framework</a>&#8217;s internals. Considering I&#8217;d been spoilt with the idea of automating any and all testing when I was going through my <a href="http://rubyonrails.org/">Ruby on Rails</a> phase, I started looking around for something similar in the <a href="http://php.net/">PHP camp</a>. The most important thing I had to keep in mind was that it needed to be something that was JavaScript aware, since the website utilises a <em>lot</em> of JavaScript fanciness.</p>
<p>Enter <a href="http://selenium.openqa.org/">Selenium</a>. More specifically, the combination of <a href="http://selenium-rc.openqa.org/">Selenium Remote Control</a> (RC) and <a href="http://www.phpunit.de/">PHPUnit</a>.</p>
<p>Selenium RC is a Java server application which launches instances of the browser(s) you specify, and then puts them through the paces of the tests that you define using plain old PHP and PHPUnit, checking the assertions you define. In other words, you get the effect of a real user using a real browser, without having to do all the grunt work yourself. Win-win.</p>
<p>The current version of Selenium RC (henceforth referred to as SRC) I&#8217;m using (version 0.9.2) works like a charm, but requires a small tweak to work with Firefox 3. When SRC instantiates a new instance of Firefox, it creates a temporary profile and installs a Selenium extension into the profile. This extension&#8217;s maximum Firefox version is still set to the Firefox 2 versions, so it will silently fail under Firefox 3, leaving you to gnash your teeth in frustration while you sift through Google to find out why the damn thing isn&#8217;t working.</p>
<p>Fortunately, the fix is simple. It involves unpacking the <kbd>selenium-server.jar</kbd> file, and changing the <kbd>install.rdf</kbd> located under the <kbd>customProfileDirCUSTFF</kbd> directory, so that the <kbd>maxVersion</kbd> element contains the value <kbd>3.0.*</kbd> to work with Firefox 3.0.</p>
<p>From there on, you can either pack everything up again into a new JAR (which I didn&#8217;t bother with), or simply run the server in its unpacked form.</p>
<p>Next time, I&#8217;ll dish up a small sample of how to actually go about doing that funky thing we call testing with Selenium RC and PHPUnit.</p>
]]></content:encoded>
			<wfw:commentRss>http://slyfox.za.net/2008/10/acceptance-testing-with-selenium-i/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Fun Time At The Zoo</title>
		<link>http://slyfox.za.net/2008/10/fun-time-at-the-zoo/</link>
		<comments>http://slyfox.za.net/2008/10/fun-time-at-the-zoo/#comments</comments>
		<pubDate>Wed, 08 Oct 2008 21:54:13 +0000</pubDate>
		<dc:creator>slyfox</dc:creator>
				<category><![CDATA[University]]></category>
		<category><![CDATA[programming]]></category>

		<guid isPermaLink="false">http://slyfox.za.net/?p=5</guid>
		<description><![CDATA[I finally managed to finish my implementation of a deadlock detector for my year project (a C framework with which to develop distributed model checking applications) earlier today. While writing the code to output resource usage statistics, I noticed that I&#8217;d forgotten all along to add optimisation flags to my make files.
Running the detector with [...]]]></description>
			<content:encoded><![CDATA[<p>I finally managed to finish my implementation of a <a href="http://en.wikipedia.org/wiki/Deadlock">deadlock</a> detector for my year project (a C framework with which to develop distributed <a href="http://en.wikipedia.org/wiki/Model_checking">model checking</a> applications) earlier today. While writing the code to output resource usage statistics, I noticed that I&#8217;d forgotten all along to add optimisation flags to my make files.</p>
<p>Running the detector with the <kbd>-O2</kbd> optimisation flags yielded the following statistics:</p>
<pre><code>pcronje@gecko modelchecker $ mpirun -H localhost ./deadlock -q -q
[0] Resource usage statistics:
 * Store memory (bytes) : 192000
 * User time   (work)   : 2.568160
 * User time   (total)  : 2.652165
 * System time (total)  : 0.008000
 * Page faults/reclaims : 0/1461</code></pre>
<p>Switching over to <kbd>-O3</kbd> yielded:</p>
<pre><code>pcronje@gecko modelchecker $ mpirun -H localhost ./deadlock -q -q
[0] Resource usage statistics:
 * Store memory (bytes) : 192000
 * User time   (work)   : 1.520095
 * User time   (total)  : 1.604100
 * System time (total)  : 0.016001
 * Page faults/reclaims : 0/1463</code></pre>
<p>Not bad. Force of habit running a Gentoo system makes me go <kbd>-O2</kbd> by default when optimising.</p>
<p>Interestingly enough, running the deadlock detector across two systems yielded the following statistics (the number in square brackets indicate the process ID of the printing process):</p>
<pre><code>pcronje@gecko modelchecker $ mpirun -H localhost,localhost ./deadlock -q -q
[1] Resource usage statistics:
 * Store memory (bytes) : 96000
 * User time   (work)   : 0.872055
 * User time   (total)  : 0.948059
 * System time (total)  : 0.028001
 * Page faults/reclaims : 3/1628
[0] Resource usage statistics:
 * Store memory (bytes) : 96000
 * User time   (work)   : 0.880055
 * User time   (total)  : 0.972060
 * System time (total)  : 0.008000
 * Page faults/reclaims : 7/1623</code></pre>
<p>Obviously, the memory usage is neatly halved (since that&#8217;s just how the state generator I&#8217;m using to test this sucker works), but the interesting thing is the decrease in runtime. I would&#8217;ve thought that the communications overhead involved in throwing work items around between processes would&#8217;ve made the whole thing about as fast as swimming in tar. I guess the smaller memory footprint is making the difference when the analyser reads through the work item store or something. It&#8217;s something I&#8217;ll look at once I start properly evaluating the project.</p>
]]></content:encoded>
			<wfw:commentRss>http://slyfox.za.net/2008/10/fun-time-at-the-zoo/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
