Medieval, Total War

“Medieval, Total War” is the latest drain on my time. The PC game is fantastic. A quick rundown: take control of a medieval faction and try to conquer the whole of Europe. Gameplay is like a cross between Risk and Sim City for the strategic Europe-wide map part, and then you get to control your army on the battlefield. Note that as a general you don’t get to control the fight, only order the units. And they may not do what you expect them to…

The depth of the game is huge. As the Italians I was a Catholic faction, until I made the mistake of invading Hungary (more Catholics) and, after ignoring the Pope’s warnings, was excommunicated. England then cancelled their alliance because it conflicted with their alliance with Hungary, and Germany declared a crusade. So, I invaded Rome and put a puppet Pope in place and the excommunication was cancelled. A few years later the old Pope led a bit of a rebellion and I had a fight on my hand. At the same time the French decided to join and I’m in the midst of a full-on war with them, but at least I managed to marry a princess to the King of England and have a good alliance with them at least. (The English can always be counted on to do a bit of French-bashing ;-)). And that’s just a summary of a few evenings of play.
Now that “Rome, Total War” has come out you can pick up “Medieval, Total War” for about half the price of a new game and with the “Viking” extension pack. I haven’t even had time to open the box to see what that is yet.

The battlefield is excellent fun, too. I bought the game as I enjoyed the battles in “Shogun, Total War”. Controlling armies is quite tricky to start with, thought there are some basic tutorials. Getting to grips with the subtleties of troops takes a bit longer: peasants will turn tail and run at the first sign of anything, spearmen are good against cavalry, cavalry are best used to charge and then pull out etc. Taking a view of the landscape and placing your troops in the best positions also takes some thinking.

All in all: I’m finding this game absolutely fantastic.

Total War community
Activision’s Medieval, Total War website
By Medieval, Total War

Fantasy football update

A pretty good week for the team. We’ve gotten rid of Beattie and bought Roonie instead (definitely a bargain), and dumped Queudrue as he didn’t seem to be getting us many points and now Rio Ferdinand is in at the back. This gave us a few points in the Arsenal/Man Utd match last weekend, although with Lehman in goal that left us a few points lower than I would have liked.

Still, after dropping down to 4th we’re now joint 3rd and all catching up on the 1st place man who doesn’t seem to have been watching his team as closely as he should. Now my only worry is a) too many Arsenal players and b) too many Man Utd players. Arsenal are certainly not playing the “1-0” game of old and although they’re not losing (except the once…) they keep letting in too many goals.

So, the next quandry is: a new goalkeeper? Tottenham were looking like a side that people are having trouble scoring against, until beating Bolton 4-3 on Wednesday. Other potentials are Everton’s or Liverpool’s, though I don’t fancy too many Liverpool players whilst Gerard is still out.

The Gothic Temple, Landmark Trust, Stowe

Having just come back from a trip to Landmark Trust’s ‘Gothic Temple’ in Stowe I can absolutely recommend it. Staying in a temple in the middle of dozens of acres of National Trust grounds is fantastic. The temple has a triangular footprint wrapped around the central circular (domed) space with turrets at each corner of the triange. One turret is the stair tower, the other two are bathroom and kitchen (ground floor) and double bedrooms (first floor).

The nearest pub (The Queens Head) is a bit of a trek. The walkable route involves the back gate to the grounds being open; this is supposedly Wednesday to Sunday but we found it closed on Sunday. There is a small wall to climb down and a field to trek across which we didn’t find too much trouble. The food in the pub is definitely worth the journey, though, although unfortunately they get fully booked up on a Sunday.

The grounds of Stowe themseves can also occupy quite a few hours. There are a number of follies and temples in the gardens, all positioned for views and generally not as interesting once you actually get near to them.
Other sites nearby:

The Rothschilds place (can’t remember the name of it), which was extremely decadent and interesting mainly for Baron von Rothschilds general lack of taste.
Silverstone: just about within earshot, but didn’t go any closer.

For booking the Gothic Temple contact The Landmark Trust.

TRUNCATE TABLE on MySQL InnoDB databases

Having come up against the extremely poor performance of using TRUNCATE instead of DELETE on MySQL InnoDB tables (see previous post MySQL Truncate slow performance problems) I thought I better come up with a solution that didn’t mean leaving a table to clear for an hour.

The solution is to use a combination of SHOW CREATE and DROP. DROPping a table is very quick indeed, so as long as you have the CREATE code to hand then it’s a simple matter to empty a table. The main thing to watch out for with InnoDB tables is foreign key constraints which are easily disabled.

Some sample code to use this from within PHP is shown below

function truncateTable($tableName)
   //Grab the code to create the table
   $sql = "show create table " . $tableName;
   $dataSet = DataHandler::loggedDbQuery($sql);
   $result = $dataSet->fetchRow();
   $createSQL = $result["Create Table"] . ";
   //Drop the table. We have to disable foreign key
   //checks, which means running the whole thing
   //from the command line
      drop table " . $tableName . ";".

This is used in conjunction with a static method I’ve created to run a standard (single) SQL query from within PHP called DataHandler::loggedDbQuery (which works with PearDB, which is where the fetchRow() method comes from) and a multi-line query function I have developed and wrote about in Multiple SQL queries using MySQL and PHP and referred to as DataHandler::multipleDbQueries($sql).

Multiple SQL queries using MySQL and PHP

Something that I’ve had problems with using MySQL/PHP is the limitation of only being able to run one line of SQL at a time. Using something such as Microsoft SQL Server it’s possible to write multiple lines of SQL and run it all in a single database call. Until stored procedures (in MySQL 5) are available (i.e. when it seems that the database engine is ready for a live environment) I’ve put together the following static method ‘hack’ using PHP’s exec() function (assuming you’re using PHP 5’s object syntax – otherwise just paste the code into a regular function):

class MySQLInterface
   public static function multipleDbQueries($sql)
      $file = fopen(TEMP_CSV_LOCATION .
      exec("mysql -u " . DB_USERNAME .
         " --password=='" . DB_PASSWORD .
         "' " . DB_NAME . " < " .

What this allows you to do is to pass in a SQL string and have it executed as if it was being run from the command line. This is especially useful if you need to disable foreign keys for some reason. e.g

   drop table oldTable;


Downsides of this are

  • Requires command line access to mysql
  • Liable to SQL injection

Since i’m working within an internal system I have control over both of these and the code seems to work particularly well.

Optimising MySQL a query with packed keys

I’ve been learning more about MySQL lately and particularly optimising
SQL queries on large tables. Large, in this case, being at the moment
hundreds of thousands of rows but soon to be millions. One of the
problems I’ve had is that MySQL sometimes decides not to use an index
even when a handy one seems to have been created for it. The root of
this appears to be to that with B-tree indexes if there are a large number of records with similar looking values then the MySQL engine may decide that it’s just as much effort using the index as to search the whole table.

The answer appears to be adding PACK_KEYS = 1 to the end of a create
table, or running the SQL command ALTER TABLE MyTable PACK_KEYS = 1 once
the table has been created. In effect, this takes account of the
similarity of adjacent keys. In our case we have a large column of field
type bigint(21) where the starting digits of the index are timestamp
generated. So, at present, we end up with a few tens of thousand rows
all starting with 108xx. Enabling packed keys means not only that the
index is smaller as MySQL only needs to store the differences between
keys (plus an extra byte to keep track of where the similarity starts)
but also that the index is actually of some use i.e. doesn’t become a
large, flat structure.

One down side of using packed keys is that inserts are slower, but given
that the system we are building is inserting each row once and then (in
theory) never touching it again that’s a small price to pay. The other major drawback, however, is that packed keys only works on MyISAM tables at present and not InnoDB. This actually isn’t much use to me as the large inserts we occassionally have to do would end up with MyISAM locking the table for perhaps an hour or more.

Pack keys
reference in the MySQL manual

Restaurant review: Gili Gulu sushi restaurant, London

It’s hard not to know about Yo Sushi, the ‘famous’ conveyor belt sushi
restaurant, but what’s not so well known is that the idea is almost a
direct import from Japan where such restaurants are more common. Gili
Gulu is another along the same vein in central London just off the main
stretch between Leicester Square and Covent Garden.

One of the big things that you’ll notice about Gili Gulu compared to Yo
Sushi is the price: the set meals are more than enough for an early
evening snack and come in at £7.50 for either a large noodle dish and
three sushi’s or miso soup and 6 sushi dishes. Very good value and even
with a drink on top you can have a reasonable meal for around £10. The
buffet is more of a blow-out experience but for around £11.50 it’s all
you can eat, including any of the noodle dishes off the menu.

The interior is well presented but informal. The tables are ideal for
groups of four, yet the bulk of the seating is based around the conveyor
belt which snakes around the space. This is ideal for a couple or if
you’re on your own. Once you’re sat down and have decided which of the
menu choices to go for you simply watch the food go past and pick up
anything that you like the look of. In comparison to Yo Sushi there is
not the same range of dishes, and Gili Gulu is lacking some of the more
time-intensive sushi rolls, but at a much reduced price I certainly
aren’t complaining. There’s a choice of rice and raw fish sushi rolls,
with a light spread of wasabe, as well as a few cooked dishes for the
less brave. On the conveyor belt you’ll also find dumplings, plates of
noodles, peas in their pods, and a few ‘tourist pleaser’ dishes such as
chicken on skewers, spring rolls and prawn crackers.

The main failing of Gili Gulu, though, is that at busier times they
often don’t have enough staff. Although the food from the conveyor belt
is self service the idea of free tea refills loses its appeal if you
can’t attract the attention of someone with a tea pot. Not being a sushi
expert I can’t comment on the authenticity of the food but having
sampled the Yo Shushi experience (and it is still more of an experience)
I can’t say I have noticed any shortcomings.

Gili Gulu is a great place for a quick, informal meal before an evening
out or at the end of an afternoon in town. It’s certainly not an
upmarket restaurant but if you’re in the area and fancy some fast but
stylish food then I think it’s hard to beat.

Address: Gili Gulu, 50-52 Monmouth Street, London, WC2

Nearest tube: Leicester Square or Covent Garden.

Review of Gili Gulu on London eats

PHP 5 class constants and subclasses

Another one of those ‘I wish PHP 5 did this…’ moments has occurred to
me with class constants. The addition of constants is good but the
problem is when it comes to subclassing. The code on the PHP 5 site:

class Foo {
   const constant = "constant";

echo "Foo::constant = " . Foo::constant . "\n";

is fine. Of course, what you really want to have is a method to give
you the constant in case you want to change the workings later:

class Foo {
   const constant = "constant";

   public function getConstant(){
      return self::constant;
$foo = new Foo();
echo "$foo->constant = " . $foo::getConstant() . "\n";

and this works too. The problem is that if you decide a subclass
needs a different constant value, so we add

class Bar extends Foo {
   const constant = "bar constant";

If we then call

$bar = new Bar();

then the value returned is “get_constant” i.e. the value of the
constant in the parent class. This is because Bar has no handler for
getConstant() so it uses its parent. That’s fine, but now we’re in the
parent context then Foo::constant is returned through the reference to
self::. The way to get round this (that I have found) is to put a copy
of the getConstant() method in each of the subclasses. This kind of
defeats the purpose of inheritance in this case.

class Bar extends Foo {
   const constant = "bar constant";

   public function getConstant(){
      return self::constant;

Now we call

$bar = new Bar();

and the correct value is returned. Of course, the other way round is
not to use constants at all but to put the value in a private variable,
but then what use are constants?