Sep 02

# Programming Puzzle no. 1

On the train to work a few days ago, I came up with the following little puzzle, based on several real-life programming experiences of working on code recently. See what you think.

The following method works correctly and produces the correct output. However, after several years of modifications by numerous different software engineers, nobody knows quite what it does any more, and everybody is too scared to modify it.

Simplify the method without altering the output of the program. the method as it stands can be considered bug free, and logically correct. Also, the method is called in a single threaded application – there are no worries with concurrency.
```// global variable, holds it's value between calls of func
int a = 0;

int func(int b, unsigned int c)
{
int d = 0;
int n = 1;

if(c < 0)
{
d = a * (0 - c);
}
else
{
d = a;
}

a = a * a;

if(b == -1)
{
for(int e = 0; e < n; ++e)
{
++d;
}
}
else
{
d = b * n;
}

a = d;

return a;
}```
Feb 05

# Fun with Stats

A few days ago, I came across the Club Form Guide on the EPL website. After getting over the shock of just how badly West Brom have been doing recently, it gave me an idea. I like playing with various metrics to come up with ultimately pointless statistics about what the league table will look like at the end of season, normally concerned with who will get relegated, or what teams have to do to avoid being relegated.

For example, if you extrapolate the number of points needed on a given date to finish outside of relegation (regardless of which teams are in the relegation zone), after the first couple of games have been played the graph remains remarkably straight – you could reasonably predict that the the team in 18th place will get 32-34 points at the end of the season. Last season, this almost worked – but in the last few matches the bottom teams had a point spurt – presumably as the realisation of relegation kicked in.

With the club form data, I had an idea – why not extrapolate the current forms of each clubs until the end of the season and see what the league table would end up looking like? Simply put, I assume that the form of the last 6 games will remain constant for the remaining 13 games, and add the points on to the current league positions.

TEAM
Current Points
Points in last 6 Games
Predicted Points
Man Utd621697
Man City531483
Tottenham451271
Chelsea46863
Everton42962
Liverpool361160
Arsenal41858
Swansea34954
West Ham30745
Sunderland29744
Fulham28743
Newcastle27742
Southampton24739
West Brom34136
Norwich28335
Stoke30234
Wigan21634
QPR17732
Aston Villa21328

Using either metric, it looks that, even given West Brom’s current bad form, they are *just* safe from relegation!

Jan 15

# Far Cry 3 Review

Far Cry 3 is a game I approached with a some apprehension. The first Far Cry was made by Crytech and was a fantastic and at the time relatively unique take on the first person shooter, with stealth elements but mostly memorable for it’s lush island setting. In comparison Far Cry 2 was a huge dissapointment for me. It was made by Ubisoft, by a completely different development studio, and had very different game mechanics to the original that didn’t quite work.

So I was expecting to be dissapointed. But great news, it’s actually rather good.

You play Jason Brody, a tourist to the Rook Islands. You start the game in a cage after you and your friends are captured by pirates after skydiving. After being introduced to Vaas, the leader of the pirates on this island, you escape with your army trained brother who (fairly typically) teaches you the basic controls of the game before being killed by Vaas, leaving you to fend for yourself. You quickly find yourself in a village, where the game starts properly.

The game itself is open – the story line consists of a set of linear missions that you complete in order to finish the game, but you can also ignore these missions for long periods of time and go and do side quests that give you various benefits.For example, you start the game capable of only carrying one weapon at a time and a limited amount of ammo, but by hunting and skinning the local wildlife, you can upgrade your kit to hold up to four weapons, more ammo, larger amounts of money, etc.

The weapons available to you are varied, with various pistols, smg’s, assault rifles, light machine guns and sniper rifles. There are also some more interesting weapons. You can plant mines to take out enemy vehicles, use C4 explosive to boobytrap buildings, burn enemies alive with a flame thrower, or be silent and deadly from a distance with a surprisingly effective bow and arrow.

At the start of the game, the entire island is unexplored. To reveal the map, you have to climb rickety radio towers in order to press a button to descramble the signals. If this sounds familiar to you, it is almost identical to the way you unveil the map in Assasians Creed. As well as revealing the map, the radio towers give you ownership of various weapons, meaning that you don’t need to spend your hard earned cash buying them.

After the map is revealed, it will still be in enemy control. In order to wrest control from the pirates, you have to attack their outposts. Taking these out is a lot of fun. My usual tactic is to find a high lookout point that overlooks the camp, Use your binoculars to pick out all of the enemy soldiers, and then work out how to sneak up on them, taking them out one by one so nobody ever knows the camp is under attack. Alternatively, when you are a little further on in the game, armed like Rambo and loaded up with health packs, you can go in all guns blazing, albeit for a smaller experience award. Or you can just sit on the ledge and wait for a passing leopard to wipe out the camp.

Um, yes. That wasn’t a joke, the wildlife is vicious. The first time that you are hunting deer, hear a growl and suddenly have a tiger leap out of nowhere and try and rip out your throat comes as quite a shock, but there is an element of exhilaration to it. Sometimes animals will wander into an enemy camp that you are storming and viciously slaughter everyone, giving you an easy and amusin victory. The fifth time that it happens, it becomes an annoyance, especially when you have spent minutes scouting the camp out only for a leopard to do the fun bit for you. It is only during the second half of the game where the soldiers get their act together and this becomes less of an issue.

Other than that, the gameplay is solid. It is a very pleasant mix of stealth and shooting, There are a lot of vehicles to play around with, including hand gliders, and a number of sub quests give variety when you get board of running and shooting. Worthy mentions include the poker sessions, which play a decent hand of texas hold’em, and the race sections, which involve racing vehicles around predefined courses to get the fastest time. The graphics are good, and character animation especially makes me wonder just how much further they can push the aging PS3 hardware before it runs out of juice.

There are several downsides, although they may or may not affect your enjoyment of the game. The graphics are good, but the map itself is quite dull to explore. On the other hand, you never really need to. You can purchase maps in the store that tell you where every single secret collectible in the game is located, and you can fast travel between any outpost that you have captured. This along with plenty of vehicles scattered around make it very easy to get anywhere on the island that you want to.

But this does mean that the collection of the various relics and letters that make up the secrets very mechanical – select relic as waypoint on your map, fast travel to the closest outpost, jump in the nearest jeep, drive to the relic, pick it up (sometimes they are slightly harder to reach, but nothing that difficult), rinse and repeat. There are over 100 relics, and 20 letters to find.

If I have one criticism, a lot of the game feels like this, including a lot of the missions. You feel like you are completing objectives in a game, rather than becoming immersed in the story line. To what level this affects your enjoyment will depend on your own priorities in playing a game.

It is also worth mentioning the co-op mode. This can be played split screen on a single ps3, or played online, but gives you a separate story line that you have to complete with your friends help. It makes a refreshing change to play multiplayer in co-operation with your fellow team mates against insurmountable computer enemies, and I had a lot of fun playing this one evening with a friend.

I don’t think I will go quite as far as to say Far Cry 3 is a classic, but if you are looking for a game that has solid, first person stealth shooter gameplay, with good graphics, and are possibly more of a trophy hunter than somebody who likes to be immersed in story, then this is a great game. And invite a friend over for co-op.