Medieval Total War, another progress review

The Pope raised his ugly head again but luckily I was able to sort him out with sheer volume of troops. I have the advantage of a very large fleet occupying most of the meditteranean so I can ship troops into coastal regions very quickly.

War with the English has started with my invasion of their three French provinces at once. They didn’t stand a chance, and King Harold had nowhere to retreat to. Still, he can’t have been very popular as his ransom was refused and I ended up beheading him. Now that I’ve got the whole of France the borders are much easier to police. Also, the invasion of a few more provinces brought me a few handy florins so I can get to work improving some more regions.

I’m holding off a war in Spain at the moment. There are a lot of troops there and a few ships out to see which would hamper my troop movements. I’ve pushed a couple of Catholic bishops in there to see if I can start converting some people so that the invasion is better received, when it happens.

Medieval Total War

Monty Hall problem and simulation

There’s been a bit of a debate on the forum at Freelancers.net about the Monty Hall problem. The crux of the problem is:

  • There are three doors. Behind one is a car, behind the other two a goat.
  • The contestant picks a door.
  • One of the other doors is opened to reveal a goat.
  • The contestant is then asked if they want to stick with the door they chose originally or change to the other unopened door.

Is it better to always stick or always change?

Remarkably, you have a 2/3 chance of winning if you decide to change every time.

To help sort things out, I wrote a little simulation program:
Monty Hall simulation.

And here is The Wikipedia entry on the Monty Hall problem.

Progress review of Medieval, Total War

It’s been an action-packed couple of days. The Sicilians rose from the
ashes and I had to retreat to the castle and muster some more forces.
The whole thing ended in a massive battle between my spearmen and
archers and their heavily armoured knights. I had to keep my distance
and pepper them with arrows to get the numbers down. I’ve also
discovered that my King is a coward and runs away at the first sight of
trouble.

I’ve finally gotten rid of the French, though, and the alliance with the
English is holding. Although they have a chunk of France that I really
have my eye on so I can’t see that lasting too long… The problem is
that attacking the English might provoke the Danes, but they don’t look
very strong. I think a few more turns of consolidating troops and making
sure there aren’t going to be any more provincial rebellions (I’m still
watching out for the Papacy again) and then I’ll have another war on my
hands.

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.
Hmmmm….

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"] . ";
        SET FOREIGN_KEY_CHECKS=1;";
   //Drop the table. We have to disable foreign key
   //checks, which means running the whole thing
   //from the command line
   $sql = "SET FOREIGN_KEY_CHECKS=0;
      drop table " . $tableName . ";".
      $createSQL;
   DataHandler::multipleDbQueries($sql);
}

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 .
         "temp_query.sql","a+");
      fwrite($file,$sql);
      fclose($file);
      exec("mysql -u " . DB_USERNAME .
         " --password=='" . DB_PASSWORD .
         "' " . DB_NAME . " < " .
         TEMP_CSV_LOCATION .
         "temp_query.sql");
   }
}

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

$sql = "SET FOREIGN_KEY_CHECKS=0;
   drop table oldTable;
   SET FOREIGN_KEY_CHECKS=1;"

MySQLInterface::multipleDbQueries($sql)

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.