Wednesday, 17 November 2010

A Just Price for housing


Standing Stone: reasons for adopting a 'just price' for housing

We live in a late capitalist society in which democratic politicians have deliberately stoked a speculative bubble in housing prices, because most voters are property owners and spiralling house prices mean that those who are already on the housing ladder feel richer. The consequence of this is that, over the country as a whole, house prices are already beyond the reach of many folk on ordinary wages. Along the Solway coast, the pretty villages have a price premium because they are attractive and pleasant places to live, but local wages are depressed. This means that folk working in the local economy cannot buy houses locally – unless they have inherited wealth.

So begins a process of clearance which is just as socially corrosive as the clearances of the eighteenth century, when the landowners enclosed land which had traditionally been common. The reaction, then, here in Galloway, was of a violent revolt by the country folk, throwing down the walls of the new enclosures and burning barns. Now, here in Auchencairn, I think the Caldows and Helen Sankey are the only people born in the village who still live on the main street (Geordie Milligan lives on Spout Row). Every other house is owned by incomers, and the native population has been effectively cleared across the burn into the bantustan of social housing. We have a very nearly complete ethnic segregation, with those who live in the old village now overwhelmingly rich and English, and the Crescent overwhelmingly poor and Scots.

It wasn't always like this. The three houses across the street for me, when last sold in the 1950s, were bought for less than two hundred and fifty pounds for all three. When I bought my first flat in the village, I paid four thousand pounds. Now, the only property for sale in the village under a hundred thousand pounds is Monty's flat – which is tiny.

Unless ordinary people without inherited wealth are able to afford to own houses in this area on wages earned in this area, the social dislocation and, effectively, ethnic cleansing is only going to get worse. Ultimately, that must lead to unrest.

Applying this to Standing Stone

None of this is the fault of anyone in the Standing Stone project. It is a consequence of political and economic forces which are far bigger than us.

However, if we do get planning permission to build new dwellings on the Standing Stone site, the market value of those dwellings when they are complete will be very much greater than what they cost to build. If we don't cap the resale price, then we are effectively giving one another a speculators' charter, and we risk the site rapidly developing into yet another rich incomers' enclave. We risk this both because the speculative opportunity will suck in spivs, and because your actual people – the sort of folk we would choose to live among, that we think in developing the idea that we are choosing to live among – simply won't be able to afford to buy into it.

People have objected – very reasonably – that they need to be able to get their investment out again. And it is true that if the housing market continues to spiral madly out of control, then if we put a cap on resale prices of dwellings at Standing Stone then people may not be able to leave, because the capped price will not realise enough money to buy a replacement property on the open market. These are real and reasonable issues.

The just price

Clearly if we are to derive a formula for a 'just price' for a dwelling, that formula needs to represent the investment which has been put in – including investment as 'sweat equity', our own labour which we've expended in creating the dwelling.

Furthermore, we need to notionally detach the value of the land from the value of the dwelling. The 'croft' part of the holding – without planning permission – has a value as agricultural land. So the capped value of a holding, if we choose to adopt a 'just price' cap, is the market value of the agricultural land plus the capped value of the dwelling, and (irrespective of what DGSHT's policy says) clearly the 'just price' cannot be less than the total amount reasonably invested. If Ruth has invested a sum in the farmhouse, then she must be able to realise at least that sum if at some time in the future she needs to sell. To expect her to accept less is just unreasonable.

But at the other end of the scale I'm expecting to spend less than £40,000 cash (and a lot of work) on structure. My dwelling, at the end of that, will have one bedroom, rather than the three or four that the farmhouse has, but as a modern designer structure with a nice view it's open market value isn't going to be a lot less. If I'm spending £55,000 on ten acres of land, then the pro-rata cost of the half-acre of that which forms the curtilage of the dwelling is about £2,500. For simplicity say I spend £7,500 on design fees and contractors, and value six months of my full-time equivalent labour at £10,000, then the investment cost of my dwelling is

Land:
£2,500
Fees and contractors
£7,500
Sweat equity
£10,000
Structure
£40,000
Total
£60,000

Should I be allowed to sell this dwelling which has cost me £60,000 for £120,000? Why? What justifies me making such a speculative profit?

The affordable price

The average annual wage in Dumfries and Galloway is around £20,000. This means that the cost price of my one bedroom dwelling is three times the income of a single wage earner – a multiplier which is certainly acceptable to mortgage lenders. Actually, DGSCHT consider a multiplier of 3.5 times average annual wage to be reasonable. And on a two bedroom dwelling, that's 3.5 times not the income of one wage earner, but the income of 1.5 wage earners – a household with one person working full time and one person working part time. So the affordable price of my one-bedroom dwelling would be £75,000, and the affordable price of a two or three bedroom dwelling would be £105,000.

Now, OK, in aiming for a £40,000 structure cost I'm aiming to build a structure which is affordable to me, so it has to be 'affordable' – I'm too old to take on new debt. But a cost of £1,200 per square metre seems a commonly quoted value these days, so (allowing the same figures for land value of the curtilage and for fees as in my example) you have £95,000 to spend on structure of two to three bedrooms (including sweat equity), which builds you 80 square metres of reasonable quality structure, which is equivalent to six rooms each 12 foot by 12 foot.

Thus it seems to me that it is possible to build new dwellings on the site such that the cost is lower than the 'affordable price'. Furthermore, knowing what I do of the group, all of us are going to have to build dwellings which cost less than the 'affordable price', simply because none of us are rich.

The just price revisited

This doesn't solve the Ruth conundrum, of course, because she's having to buy at full market rate and cannot be expected to take a hit to sell at an 'affordable price'.

So we need a formula which I think is something like this:
value of the land part of the holding
plus reasonable investment cost of dwelling
plus 2% per annum compound interest on the reasonable investment cost of the dwelling
where:
value of the land is the agricultural value of the land as assessed by a qualified surveyor appointed by the Company
reasonable investment cost is for new builds and for the byre units an agreed multiple on the internal area of the dwelling in square metres, I'd suggest £1,200; for the existing dwelling, the price actually paid (including essential renovations).

This gives us a 'just price' which for all new units is likely to be lower than or equal to the 'affordable price' as seen by DGSCHT.

Non-idealistic argument for a just price formula

The arguments I advanced at the head of this document for a just price for housing are idealistic; they represent a rejection of the market in favour of enhancing social cohesion and abstract 'fairness'. I believe that most of us do have a degree of idealism, but I acknowledge that the exact degree varies.
However, bear in mind that getting planning permission for ten new dwellings on this site is a very big ask. It is precisely the 'sporadic development in the countryside' that the council has policy to prevent. We're going to have to do a lot of special pleading and special argument. If we fail to get planning permission, we're most of us going to have had a significant share of all our capital tied up for at least two years in land, with nowhere to live. And although it's probable that if it all goes pear shaped we can resell the land for the money invested, that isn't guaranteed.

So we need all the help we can get. We can get a certain amount of political if we're able to play the 'green' card, the 'low impact' card (but I'm not certain I can achieve low impact in my budget, and I suspect other people may be the same; concrete is cheap stuff). One card that we know we can play, though, is 'affordable housing'. And, we already know that if we play the affordable housing card, we will get not insignificant help from DGSCHT.

In summary, if we cap resale at an 'affordable' value, we will be able to recover the investment made in dwellings (provided we're don't built using solid gold taps and marble staircases), and we will get significant support which will significantly lower the risk involved in the project. That seems to me a substantial win for very little actual cost.

Wednesday, 31 March 2010

Auf Essen in Deutschland


I've spent the week in Germany, where I've been performing a safety audit on a device made by a German subsidiary of a Swiss company on behalf of an English subsidiary of a French company. I write this sitting in France, fifty metres from Switzerland, while waiting for a plane to fly me to the Netherlands and thence home to Scotland. It's all remarkably painless.

But let's talk about Germany. Lots of the things you thought you knew (or I thought I knew) about Germany turn out to be true - or at least, turn out to be true of small towns on the fringes of the Schwartzwald. My view might be slightly influenced by the company I was auditing, by the fact that that Swiss-owned engineering company was absolutely obsessive about quality in everything they did (including hospitality). It was engineering of the kind I associate with Germany: always up to a quality, never down to a price. Over-engineered rather than under-engineered; good and thoughtful design, but emphasising sturdiness and durability over style.

The taxis were spotlessly clean, their drivers unfailingly courteous. The factory was clean and efficient and all the staff positive, relaxed, confident and happy to explain their work. The hotel was extremely well fitted and comfortable (and clean), the rooms generous and luxurious, the staff helpful, friendly and welcoming. They were mostly middle aged, not young; I think almost entirely local; and the ratio of staff to guests higher than you'd find in anything but the most upmarket British hotel. Yet the cost of a room was exactly the same as in a grubby corporate flea-pit in East Kilbride - where you would not have got the delicious and varied breakfast.

Which brings me to food. The company we were auditing treated us as guests; not only did they provide us with restaurant-quality lunch each day in their staff canteen, they took us out to dine every night, at a total of three different restaurants; twice the one belonging to our hotel, once a modern restaurant in the local administrative centre, and once... I'll come to that.

So what is German food like? Sausages and sourkraut? Chips and cream-cakes? Errr... no. We did eat a little sourkraut - several varieties of it, all good. We ate noodles, of kinds I'd never heard of before, let alone seen - nothing like Italian noodles. We ate dumplings. We once ate chips - once. We ate a simply extraordinary quantity of meat. We ate home made icecream. I didn't eat sausage at all (although a number of varieties were available at breakfast). Slightly to my disappointment I didn't eat a proper Schwartzwald Kirsche Torte - I could have, but I simply didn't have room (my abstemiousness at breakfast was for the same reason). I have eaten more this week than I eat in an average fortnight.

So, what is the food like? In one word, delicious. Extraordinarily good. Exceptional. Second, in my experience, only to Malaysia. Everything was of superb quality, freshly prepared, not over fancy. The effete over-complicated confections of British television cooking were nowhere to be seen; nor was fast food, or junk food. In the urban centres we did see a few Indian, Chinese and Vietnamese restaurants, and we did see sausageinnabun shops. But the places we went to served food which was proudly local, unashamedly German, unquestionably fresh-cooked and utterly excellent.

Until the very last night - last night - which was completely different. We drove up into the forest, up steeply climbing twisting roads which would be a joy to cycle in summer, to an ancient farm-house turned gasthof. The whole place was wooden, over four hundred years old. We went into a simple, homely dining room which would hold twenty people at the most, but which was empty but for a man sitting alone and the four of us. A pretty young waitress who spoke no English brought us simple paper menus, and came back after a few minutes to take our order. I chose a venison ragout with noodles, which sounded good.

So much, so normal. And then it all changed.

Mien host came in, a tall and powerful old man called Saxo, wearing casual countryman's clothes. He spoke a little English but was much more comfortable in German. He sat down with us for a few minutes, talking, and then said he'd shot a wild pig, and would we like some? After not a lot of discussion, we agreed we would. Was it spit-roasted, someone asked? No, it had been baked in the oven, after the bread he'd be serving with it. Saxo also said he had some mead, would we like to taste?

He disappeared into the back, and shortly reappeared bearing an enormous ox horn in a wrought iron stand. I joked that it must be an aurochs horn, but in truth I don't know where he got one so big; it wasn't old, and was by far bigger the horn of any domestic breed I know of except perhaps a Texas long-horn. He offered this to us and I realised it was full of mead. How much mead fills a horn like that? I haven't a clue, but it must have been at least two litres. I was certain that between four of us - and one a driver - we'd never empty it. So we chatted round the table with Saxo, and drank his (wonderful) mead, passing this epic horn from hand to hand, until the chef appeared.

The chef was a man as big as Saxo, and with the sort of belly on him a good chef should have. He greeted us, spoke to Saxo, and they both disappeared into the back. After a few moments they reappeared, bearing a trencher. A trencher? it was at least four feet by two, of sturdy oak. It filled the table, clearly leaving no room for such effete nonsense as individual plates. On it. besides two baked quarters of a substantial pig and a large loaf of rough bread cut into thick slices, were two large crocks of gravy, baked apples, baked potatoes, sweet corn, and a mountain of roughly chopped mushrooms (which, it transpired, were the only ingredient which had been bought in). Oh - and four very sharp knives. No forks.

Four people - four people could not possibly eat all this.

Four people very nearly did. There were some potatoes left at the end, and an apple, and perhaps a kilo of pork on the shoulder. We gorged ourselves. We all gorged ourselves, despite having already overeaten for three days, because it was so extraordinarily delicious, so utterly delectable.

And when, finally, we thought we had eaten all we possibly could and the trencher had been removed, the pretty waitress (who, it transpired, was not German but from Drakula's home village in Transylvania) persuaded us all to have some home-made ice-cream with advocaat; and Saxo reappeared and persuaded us to have a schnapps. The waitress and the other guest (an engineer from Bratislava in Slovakia) joined us, and together we conversed in a happy mixture of German, English, French, a bit of Italian, a bit of Dutch, and some Slovak, while the mead horn continued to circulate.

We could have had that meal - in that place, in that environment - any time in the past four hundred years; there was an electric light but it was no brighter or more intrusive than a candle lamp. Apart from the potatoes and sweet corn, we could have had it any time in the past millenium.

At the end of it all we went back to the hotel very late. I was drunker than I've been in twenty years - and probably happier. The mead horn? It was empty.

Wednesday, 30 December 2009

Settling a game world

This essay is part of a series with 'Worlds andFlats' and 'The spread of knowledge in a large gameworld'; if you haven't read those you may want to read them before reading this. This essay describes how a large world can come into being and can evolve. I've written again on this subject since - see 'Populating a game world')

Microworld

Some twenty years ago I wrote a rather sophisticated cellular automaton which I called 'Microworld' which modelled the spread of human population over a landscape. It did this by first fractally folding a grid to assign elevations to cells. Then, cells below a critical elevation – the tree line – were assigned as forest. For each cycle – 'year' – a cell remained forest, its soil fertility would increase. Random events – 'lightning strikes' could change a cell from forest to clearing. Then the following transitions might take place, each with a probability, where each cell is considered to have eight neighbours:
  • A forest cell with a lightning strike as a neighbour may catch fire and burn
  • A forest cell with a fire as a neighbour may catch fire and burn
  • A burning cell become a clearing cell
  • A clearing cell with forest or scrub as a neighbour may become scrub
  • A scrub cell may become forest
This more or less completes the 'natural' cycle... then we get to settlement. Pastoral and agrarian 1 cells gradually degrade soil fertility (erosion, etc). Agrarian 2 cells do not degrade fertility.
  • A clearing cell (including cells above the treeline) may become a pastoral cell (pastoral 1, no settlement)
  • A pastoral 1 cell whose soil fertility falls below a threshhold becomes waste
  • A pastoral 1 cell with no pastoral neighbours may become waste
  • A waste cell below the treeline may become scrub
  • A waste cell may become clearing
  • A pastoral 1 cell with two or more pastoral neighbours may become a pastoral 2 cell (settlement)
  • A forest cell with two or more pastoral neighbours may become clearing
  • A pastoral 2 cell with two or more pastoral 2 neighbours may become agrarian 1
  • An agrarian 1 cell which falls below a critical fertility becomes pastoral 1
  • An agrarian 1 cell with three or more agrarian 1 neighbours becomes agrarian 2 (smith, mill)
  • A cell with three or more agrarian 2 neighbours becomes market
  • A market cell with no agrarian 2, market or urban neighbours becomes waste
  • A cell with two or more market neighbours becomes urban
That's simple, but it provides a remarkable good model of population spread. however, it is essentially a grid and so doesn't make for natural-seeming landscapes when considered as a three dimensional rendered world. How can we do better?

Microworld Two

The objective of this essay is to outline an angorithm for creating inhabited landscapes in which games can be set, which are satisfyingly believable when rendered in three dimensions. The objective of creating landscapes 'procedurally' – that is, with algorithms – is that they can be very much larger than designed landscapes for the same richness of local detail. This does not mean that every aspect of the final landscape must be 'procedural'. It would be possible to use the techniques outlined here to create landscapes which were different every time the game was played, but it would be equally possible to create a landscape which was frozen at a particular point and then hand edited to add features useful to the game's plot. And while I'm principally thinking in this about role playing games, this sort of landscape would be applicable to many other sorts of games – strategy games, god games, first person shooters...

The physical geography

Consider our landscape as, once again, a fractally folded sheet on which any given point has characteristics based on its elevation and orientation. There are two critical levels – water level and treeline. The water level is, overall, sea level, but in the case of a localised depression it is equal to the lowest land height between the depression and the sea (lakes form in depressions). Computing the fractal sheet forms stage one in computing the landscape. Next, we need functions which, for any given point on the landscape, compute two different dimensions of soil fertility: water and warmth. We'll assume a coriolis prevailing wind blowing from the west, bringing in damp air from an ocean in that direction. Western slopes are wetter than eastern slopes. In principle, also, there's likely to be a rain shadow to the east of high ground leading to considerable aridity, but that may be too expensive to compute. Rain runs swiftly off steeper slopes, more slowly on flatter ground, so flatter ground is wetter than steeper ground. Water flows down hill, so lower ground is on the whole wetter than higher ground. This isn't a precise model of soil hydrology, but I think it's good enough. From each lake a watercourse follows the lowest possible path to the sea. Watercourses modify the land overwhich they flow, carving out a route at least sufficient to carry the amount of water collected in the watershed above each point. Where watercourses flow down steeper gradients, they carve out gullies, possibly with waterfalls. Where they cross shallower gradients or level ground, they become broader. Computing the watercourses becomes the second stage of computing the lanscape.

Vegetation

Now sprinkle seeds randomly across the landscape at a density of roughly one every ten square metres. Seeds which fall in water, ignore (? or make into water plants?). The position of the plant is taken from the random sprinkling. The species and size of the plant that grows from the plant are a function of the water and warmth functions described above, with latitude and longitude as seeds for pseudo-random functions delivering aspects like branching and so on – enough to make individual plants distinct and not carbon copies even of other plants of the same species, but nevertheless recreatable from just the latitude and longitude. So for each plant only two integers need to be stored, yet every time a player passes he will see an identically recreated world. Of course there is a trade-off between storage space and rendering time, and it may be more efficient to build and cache a detailed model of each plant. Like a lot of other things it depends on the game being designed and the processing power of the platform on which that game is delivered. As to how the functions which select the vegetation type work, obviously trees grow better in wetter places, grassland plants in dryer places; within the wetter places, coniferous trees are more prevalent where it is cooler, broadleaves where it is warmer. In the very wettest places, willows, alders and marshland plants. These plants – the seeded plants – are the feature plants of the landscape. When rendering the landscape the renderer would first apply a suitable local surface texture, for example, in grassland areas, grass.

Settling the world

So now we need to make this an inhabited landscape. My proposal for this is to introduce proto-actors, which may be the same software agents as the non-player characters the user will interact with (see my essay on the spread of knowledge). At this stage in their lifecycle, the proto-actors are fairly simple state transition machines. Generally, their algorithm is as follows: Starting from one or two seed points, proto-agents will initially move across the landscape travelling at most 20Km in a day, preferring to stop at inns or else at existing settlements; and will maintain a history of the places they have been, never revisiting a place until they have settled. Whenever moving, whether before they have settled or after, proto-actors will plan their route across the landscape, avoiding trees, buildings, and steep gradients, and will prefer to cross rivers at a bridge (if available) or else a ferry (if available), or failing that at the narrowest convenient point. When proto-actors settle, they will claim an area of territory appropriate to their trade – more below; the system must build up a database of land holdings. In particular a land holding will never cross a watercourse, an existing road or overlap another land holding (although roads may develop across existing holdings). This is key because I don't want holdings normally to have regular shapes. A settled proto-agent will build a building to live in, and possibly an additional one for his trade. When building buildings, proto-actors will prefer to build at the edge of their land holding, as close as possible to existing buildings and ideally at the side of an existing road. The richer an existing building is, the more attractive it will be to new buildings. Buildings will be built with their long edge aligned with the edge of the owner's hoding.
  • A proto-actor is initially, as described above, an itinerant. Itinerants are introduced into the world at a small number of geographical locations, and gradually, not all at once. Itinerants travel as described above. As they move they will leave breadcrumb trails with a roughly ten metre resolution. If they cross an existing track which goes in roughly the right direction they will prefer to follow it. Once a track has been followed by a certain number of proto-actors, it becomes a road.
  • An itinerant who finds an area of unsettled grassland of ten hectares with low soil fertility and not more than one hundred trees settles and becomes a pastoralist. He builds a cottage.
  • An itinerant who finds an area of unsettled grassland of ten hectares with medium or high soil fertility becomes an agrarian. He builds a homestead. Depending on the fertility of his land he can support between zero and ten labourers, 10% of a smith, 10% of a miller and 10% of a bonnet laird.
  • An itinerant who finds an area of unsettled land of 100 square metres within five hundred metres of a homestead with unfulfilled labourer demand becomes a labourer. He builds a cottage.
  • An itinerant who finds an area of unsettled land of 100 square metres within five kilometres of ten farmers with unfilled smithing slots becomes a smith. He builds a cottage and a forge.
  • An itinerant who finds an area of unsettled land either at the side of a water course or at the top of a hill, and within 5 kilometers of ten farmers with unfilled milling slots becomes a miller. He builds a mill – water or wind, appropriate to location.
  • Any settler who plays host to more than a certain number of travellers becomes an innkeeper. He claims 400 square metres of unclaimed land as close as possible to his existing settlement and buids an inn and stableyard.
  • An itinerant who finds 400 square metres of unclaimed land within a certain distance of an inn and a smith will become a merchant, provided that there are three smiths within a 5Km radius who have unfilled market slots. The merchant builds a marketplace and a counting house.
  • An itinerant who finds 200 square metres of unclaimed land within a specified distance of a market with an unfilled chapel slot becomes a priest and builds a chapel and manse, and possibly a school.
  • An itinerant who finds 100 square metres of unclaimed land adjacent to where a road crosses a river becomes a ferryman.
  • A ferryman who carries more than a certain number of passengers in a given period becomes a tollkeeper and builds a bridge.
This set of rules – and possibly others like them (woodcutters, fishermen, hunters...) provide the first wave of settlement. Once the landscape is sufficiently settled by this first wave, there needs to be a period of establishing trading routes. First, every settler will visit his nearest market, leaving a permanent track if there is not already a road. Where several of these tracks overlay one another, once again a road is created. Each merchant then visits each of the ten markets nearest his own, following existing tracks and roads where available. Wherever the merchants do not find roads, new roads are created. This completes the roads network. Each market is now assigned a value which is a function of
  • the number of people for whom it is the nearest market
  • the sum of the wealth (soil fertility) of the homesteads for which it is the nearest market
  • the wealth of other markets within a day's travel
Depending on its wealth a market may support up to twenty stallholders, including bakers, butchers, tanners, weavers, cobblers, chandlers and so on. So a second wave of itinerants sets off. These follow the original rules for itinerants, but if they find an unsettled 100 square metres within five hundred metres of a market, will set up as a stallholder, building a town house and appropriate trade building on their own settlement, and a stall in the market. An itinerant finding a hundred square metres within five hundred metres of a market which has all its stallholder slots filled may become a slum landlord, and build a tenement for day-labourers. Finally, aristocracy. In the second wave an itinerant who finds either a hilltop, an island in a lake or river, or a significant river crossing, with one hectare of unclaimed land and within 5Km of ten farms with unfilled bonnet laird slots becomes a bonnet laird (or 'squire', if you prefer) and builds a fortified house. At the end of the second wave of settlement the ten percent of bonnet lairds with the richest fiefs (using much the same metric as for the wealth of markets) become barons and build castles.

Rendering the buildings

This seems to me to provide an algorithmic means of settling a landscape which will generate organic and satisfying patterns of settlement. But it all fails if the buildings are chosen from a limited palette of models. As with the trees I think we need algorithmic mechanisms of building similar-but-different buildings which can be repeatably rendered from relatively small data sets. As an example of what I mean, in damper landscapes where wood is likely to be available, there might be a higher probability of stave buildings, or weatherboarding, with mainly shingle roofs. In slightly less damp areas where timber is still available, cruck frames and half timbered buildings will prevail, with mostly thatched roofs. In the dryest areas, cob and brick buildings will be common, often with tile roofs. On steeper hillsides, stone buildings will be common, perhaps with slate roofs. Within each of these types there are essential cells from which a building is created. These cells can be longer or shorter, taller or lower, wider or narrower. A building may comprise a single cell, or more. If more than three cells they may be arranged in a row or round a courtyard. And they may have one story or two. Which they have can be based – like the details of the plants – on functions which take latitude and longitude as arguments and which, internally use pseudo-randoms seeded from those latitude and longitude values.

How vast a world?

OK, so, with this general approach, how big can we go? The answer seems to me to be 'big enough'. A 32 bit integer gives somewhat over four billion values, so can resolve down to one millimetre precision in a world 4000 kilometres by 4000 kilometres. But we don't actually need millimetre resolution; centimetre would be quite small enough. And that gives us potential for a world 40000Km square, or 1.6 billion square kilometres, which is three times the surface area of planet Earth.

In practice we can't go that big for all sorts of space and time reasons. Recording land heights is inevitably an issue. I don't know of a pseudo random function which will generate satisfying land heights. Anything based on Julia sets, for example, ends up with landforms symmetrical around a central point. Furthermore, the shapes of fractals which can be constructed from simple functions tend to have a noticable and unnatural degree of self-similarity across scales. I'd dearly like to be wrong on this, but I think we need to store at minimum elevation values at ten metre intervals. If we can accept 100mm resolution for elevations, storing 16 bit values gives a range of 6,500 metres - 21,000 feet - from the deepest seabed to the peaks of the highest mountains.

This means that landform information alone requires 20Kbytes per square kilometre - unindexed, but seeing it's a rigid ten metre grid that isn't a problem. Which, in turn, means that you can store landform information for a planet the size of Earth in one terrabyte. But we don't need a planet the size of earth. Scotland is 80,000 square kilometers of land area; allowing for a bit of sea around to the horizon around it, say 100,000 square kilometers. That seems to me more than big enough to be a game space. It amounts to 160Mb of landform data, which is completely manageable.

If we stored plant data for every distinctive plant in Scotland - even at one per ten square metres - that does become an impractically large data set, because quite apart from anything else, the plant locations do have to be indexed. But actually, given that the actual plants that grow are a function of the location at which they grow, no player is going to notice if the pattern of the locations of plants is the same for each square kilometre. So we can manage plant data for a land area the size of Scotland in 400,000 bytes - we could do it in less (if the locations were generated using a pseudo-random function, much less).

Building data is different. We need to store the latitude, longitude and type of every building explicitly, and again they need to be indexed in order that we can recover the buildings in a given area efficiently. We need about 16 bytes per building (four bytes latitude, four longitude, two type; then for each tile a null-terminated vector of pointers to building records). If we assume that our feudal land of 80,000 square kilometers has a population of a million, and that there are on average five occupants of every building, that's two hundred thousand buildings, implying 3.2Mb of data.

Of course, that's just the backing store size. As tiles are loaded into active memory - see the essay 'Tiles and Flats' this raw backing data has to be inflated procedurally into actual models that can be rendered; models which may have thousands of vertices and hundreds of kilobytes of textures. The functions which do that inflating have some finite size, and, significantly, they'll need to work on prototype models which will in turn take storage space. Finally there are hand-edited models potentially used at particular plot locations; those need to be stored more or less in full. But all this has not become an unmanageable amount of data. It seems to me plausible that you could store a fully populated 100,000 square kilometer game world on one uncompressed 700Mb CD. On a 4Gb DVD, you could do it very easily.

Thursday, 12 November 2009

When in Germany

I've spent the week in Germany, where I've been performing a safety audit on a device made by a German subsidiary of a Swiss company on behalf of an English subsidiary of a French company. I write this sitting in France, fifty metres from Switzerland, while waiting for a plane to fly me to the Netherlands and thence home to Scotland. It's all remarkably painless.

But let's talk about Germany. Lots of the things you thought you knew (or I thought I knew) about Germany turn out to be true - or at least, turn out to be true of small towns on the fringes of the Schwartzwald. My view might be slightly influenced by the company I was auditing, by the fact that that Swiss-owned engineering company was absolutely obsessive about quality in everything they did (including hospitality). It was engineering of the kind I associate with Germany: always up to a quality, never down to a price. Over-engineered rather than under-engineered; good and thoughtful design, but emphasising sturdiness and durability over style.

The taxis were spotlessly clean, their drivers unfailingly courteous. The factory was clean and efficient and all the staff positive, relaxed, confident and happy to explain their work. The hotel was extremely well fitted and comfortable (and clean), the rooms generous and luxurious, the staff helpful, friendly and welcoming. They were mostly middle aged, not young; I think almost entirely local; and the ratio of staff to guests higher than you'd find in anything but the most upmarket British hotel. Yet the cost of a room was exactly the same as in a grubby corporate flea-pit in East Kilbride - where you would not have got the delicious and varied breakfast.

Which brings me to food. The company we were auditing treated us as guests; not only did they provide us with restaurant-quality lunch each day in their staff canteen, they took us out to dine every night, at a total of three different restaurants; twice the one belonging to our hotel, once a modern restaurant in the local administrative centre, and once... I'll come to that.

So what is German food like? Sausages and sourkraut? Chips and cream-cakes? Errr... no. We did eat a little sourkraut - several varieties of it, all good. We ate noodles, of kinds I'd never heard of before, let alone seen - nothing like Italian noodles. We ate dumplings. We once ate chips - once. We ate a simply extraordinary quantity of meat. We ate home made icecream. I didn't eat sausage at all (although a number of varieties were available at breakfast). Slightly to my disappointment I didn't eat a proper Schwartzwald Kirsche Torte - I could have, but I simply didn't have room (my abstemiousness at breakfast was for the same reason). I have eaten more this week than I eat in an average fortnight.

So, what is the food like? In one word, delicious. Extraordinarily good. Exceptional. Second, in my experience, only to Malaysia. Everything was of superb quality, freshly prepared, not over fancy. The effete over-complicated confections of British television cooking were nowhere to be seen; nor was fast food, or junk food. In the urban centres we did see a few Indian, Chinese and Vietnamese restaurants, and we did see sausageinnabun shops. But the places we went to served food which was proudly local, unashamedly German, unquestionably fresh-cooked and utterly excellent.

Until the very last night - last night - which was completely different. We drove up into the forest, up steeply climbing twisting roads which would be a joy to cycle in summer, to an ancient farm-house turned gasthof. The whole place was wooden, over four hundred years old. We went into a simple, homely dining room which would hold twenty people at the most, but which was empty but for a man sitting alone and the four of us. A pretty young waitress who spoke no English brought us simple paper menus, and came back after a few minutes to take our order. I chose a venison ragout with noodles, which sounded good.

So much, so normal. And then it all changed.

Mien host came in, a tall and powerful old man called Sago, wearing casual countryman's clothes. He spoke a little English but was much more comfortable in German. He sat down with us for a few minutes, talking, and then said he'd shot a wild pig, and would we like some? After not a lot of discussion, we agreed we would. Was it spit-roasted, someone asked? No, it had been baked in the oven, after the bread he'd be serving with it. Sago also said he had some mead, would we like to taste?

He disappeared into the back, and shortly reappeared bearing an enormous ox horn in a wrought iron stand. I joked that it must be an aurochs horn, but in truth I don't know where he got one so big; it wasn't old, and was by far bigger the horn of any domestic breed I know of except perhaps a Texas long-horn. He offered this to us and I realised it was full of mead. How much mead fills a horn like that? I haven't a clue, but it must have been at least two litres. I was certain that between four of us - and one a driver - we'd never empty it. So we chatted round the table with Sago, and drank his (wonderful) mead, passing this epic horn from hand to hand, until the chef appeared.

The chef was a man as big as Sago, and with the sort of belly on him a good chef should have. He greeted us, spoke to Sago, and they both disappeared into the back. After a few moments they reappeared, bearing a trencher. A trencher? it was at least four feet by two, of sturdy oak. It filled the table, clearly leaving no room for such effete nonsense as individual plates. On it. besides two baked quarters of a substantial pig and a large loaf of rough bread cut into thick slices, were two large crocks of gravy, baked apples, baked potatoes, sweet corn, and a mountain of roughly chopped mushrooms (which, it transpired, were the only ingredient which had been bought in). Oh - and four very sharp knives. No forks.

Four people - four people could not possibly eat all this.

Four people very nearly did. There were some potatoes left at the end, and an apple, and perhaps a kilo of pork on the shoulder. We gorged ourselves. We all gorged ourselves, despite having already overeaten for three days, because it was so extraordinarily delicious, so utterly delectable.

And when, finally, we thought we had eaten all we possibly could and the trencher had been removed, the pretty waitress (who, it transpired, was not German but from Drakula's home village in Transylvania) persuaded us all to have some home-made ice-cream with advocaat; and Sago reappeared and persuaded us to have a schnapps. The waitress and the other guest (an engineer from Bratislava in Slovakia) joined us, and together we conversed in a happy mixture of German, English, French, a bit of Italian, a bit of Dutch, and some Slovak, while the mead horn continued to circulate.

We could have had that meal - in that place, in that environment - any time in the past four hundred years; there was an electric light but it was no brighter or more intrusive than a candle lamp. Apart from the potatoes and sweet corn, we could have had it any time in the past millenium.

At the end of it all we went back to the hotel very late. I was drunker than I've been in twenty years - and probably happier. The mead horn? It was empty.

Monday, 2 November 2009

The polemic, as detective story

If I'd met Steig Larsson, I'm pretty sure I'd have liked him. I like his values. And I absolutely agree with the thesis which I think caused him to write this book, which is that one of the most effective ways in which you can change the values of a society are through popular culture. Not through high culture, but through films people choose to watch, television programmes they stay home to follow, books they actually read.

This is a book to be read. It is, first of all, a ripping yarn. Its two protagonists are both well realised and interesting - Blomkvist, Larsson's own alter ego, is a warm, gentle, intelligent person of strong convictions and integrity. Salander - the girl with the dragon tattoo - is darker; profoundly damaged, severely autistic, desperately vulnerable, with ethics and values which don't mesh well with the society around her but which have an integrity of their own. Around them is a wider cast of characters, many of them interesting, most of them well drawn and realised.

It's a rattling good yarn. It's extremely well told - there are a series of clever misdirections early in the narrative which make you (made me) think you've seen a major clue to the mystery; in my case I was (mostly) wrong. The denoument, when it comes, is absolutely consequent on the evidence that has been presented - this is a whodunnit in that classic sense - but also profoundly surprising and shocking.

At the same time it is not great writing. The prose does not sing, it clunks. At first I thought this might be an artefact of poor translation, but Larsson himself acknowledges it, when he has Blomqvist comment on the slapdash prose of the book that, in the book, Blomqvist writes. The writing is functional; it is good enough. Fit for purpose. This is a journalist's narrative, an activist's, a polemicist's. It is not a poet's story.

Larsson's own thesis - the one he is seeking to persuade us of - is reflected in the title he chose, 'Män som hatar kvinnor' ("Men who hate women"). The book exists to persuade us that fascism and misogyny are intimately linked. It's a good argument, well made. But underneath that are other things: profound distrust of big money; anger at hypocrisy; an acute awareness of the dark things that hide behind respectable facades. The whole book is, in fact, a political tract - but you won't notice that at first read through. The story will grab you by the throat, and hurry you through the landscape Larsson paints so quickly that these details will pass unnoticed by the conscious mind, but will seep into your unconscious subliminally.

Let them seep. The world would be a better place if more people shared Larsson's values.

Thursday, 20 August 2009

Days when I'm proud to be Scots

So, we released Abdelbaset Ali al-Megrahi yesterday. For the purposes of this note, let's simply assume that Megrahi was guilty as charged. Let's ignore the fact that the evidence in the case was clearly murky, and appears to have been manipulated by intelligence agencies, and by bribing witnesses. Let's ignore that al Megrahi consistently denied guilt.

A man has killed - in an appalling masacre - two hundred and seventy innocent people. Now he is in prison, in a land far from his home and family, and he is dying. Does he deserve to be released? No. Should he be released on compassionate grounds? That depends on whether those holding him have compassion.

Compassion is not deserved. Compassion is an act of grace, of mercy. An eye for an eye - justice, revenge, the law of vengeance, the obsessive levelling of scores - not only leaves everyone blind. It leaves everyone impoverished. It leaves a world devoid of moral values to look up to.

But Scotland isn't like that. Scotland has mercy, and compassion. Our government has grace. And so, we let him go: to go home to die, amongst his kin. Were he ten times as guilty, this would still have been the right thing to do.

On days like this I am proud to be Scots.

Friday, 20 March 2009

Not quite a chip off the old block

In 1936, Pierre-Jules Boulanger asked his engineers to design him a 'toute petite voiture', and they responded in style. They were French, and it showed. They designed a car with flair, with elan, with chic, and with a certain joi de vivre. They designed so well that their little car was still in production fifty-four years later, and won the hearts of millions of people across Europe and Africa. The Deux Chevaux was not only an enormously practical, reliable, adaptable and economical vehicle, it was also the world's most underrated sportscar - more fun to drive than anything else I have driven with the sole exception of a Lotus Elise. I loved mine. It was my favourite car ever.

Which is why the petite voiture which sits outside my house now is another Citroen: a C3 Pluriel, a car whose design pays conscious homage to the Tin Snail. Less characterful, perhaps, blander, the curves rounded off into something closer to a child's toy aesthetic, but echoing the high-arched roofline and the bulbous curving bonnet. And echoing the original in other ways, too - in it's folding canvas roof, in its claimed versatility.

I've lived with mine for nine months now, for ten thousand miles. I like it very much. But it has to be said that as a replacement for the Deux Chevaux, it fails.

Why?

Let's start with the roof, since it's such a significant part of what makes both cars outstanding. In the 2CV, there are four positions for the roof. The first is, obviously, closed. Release two latches - which can be done from the driver's seat, but ideally not when the car is in motion - and the front half of the roof folds back. With it back the aerodynamics are reasonable - there's no significant buffeting. To get to the next position, one must stop, get out, unclip the roof from the front frame, and roll it up manually. It then clips in a neat bundle above the rear window, leaving the car essentially roofless. Again, the aerodynamics are OK - there aren't any real problems with harmonics. To get the roof right back, one needs tools: four bolts, and the whole roof and boot lid can be removed. It doesn't normally leak, there's virtually nothing to break, and one can still buy a complete roof assembly for £150. In the words of another French engineer of the interwar years, 'c'est brutal, mais ca marche'.

Contrast the Pluriel. Superficially it's better. The roof has six positions, and all the first five can be selected electrically with the car in motion. The last involves stopping the car, opening the boot, and swinging the neatly folded roof and rear window assembly down under the boot floor. This is easy enough - it's nicely counterweighted and needs no strength. Furthermore, with the roof folded away, the side arches can be removed resulting in a completely open car - something I very much appreciate and which wasn't possible with the 2CV. Removing the side arches is a matter of undoing four latches and lifting them away from the car. With the arches removed, the car is remarkably neat. No tools are needed.

But. But.

With the roof opened to the second position there's quite intense buffeting above about 50 mph, and in the fourth position there's a harmonic that's so intense above that speed that I worry about the structural integrity of the roof. With the roof in the fifth position - neatly folded on the rear window - there's buffeting, but it isn't extreme and the car can be comfortably driven in that state. And with the roof in its sixth position, below the boot floor, there's no more buffeting than you'd expect in any open car. But rather than six usable roof positions you really have only four, the same number as the Deux Chevaux.

Of course, you can still select between three of these when on the move. But the electric mechanisms which make that possible, and which control the latching and unlatching of the rear window, are clear weak points. If the electrics fail, you cannot close the roof, whatever the weather. There is no manual override. What in the 2CV was a simple sheet of waterproofed canvas has grown in the Pluriel into a minor miracle of engineering; and with that complexity has come cost. Where a new roof for a 2CV costs £150, a new roof for a Pluriel costs £2400.

And, it leaks. I'm not really complaining, I'd read the reviews and knew leaks were a feature of the design before I bought it. Mine leaks into the boot - things left there over a rainy night come out extremely damp. It's not a big problem, and I think the virtues of the design outweigh it; but I can't help thinking that the pivoting rear window contributes to this. Furthermore, the mechanism for swinging the rear window down takes up quite a lot of room in what is already a small car.

Which brings us to the next point. The Tin Snail was a genuine four seater car (it even had four doors). It could seat four adults without their being unduly cramped. Boulanger was a very tall man, and insisted on being able to sit comfortably in the car. The Pluriel claims to be a four seater, but in truth it's a four seater only if the driver is a midget, or if the rear seat passengers have had both legs amputated above the knee. With me in the driving, there is 40mm between the back of the driving seat and the front of the back seat; and I'm a lot shorter than Boulanger.

There's another issue with those rear seats. They have reinforced, non-adjustable head restraints, which form part of the car's roll over protection. Both the 2CV and the Pluriel present themselves as adaptable, utility cars. In the 2CV, the rear seat unclipped and could be removed easily leaving a large load floor. This would easily take a pair of race bikes with only the front wheels removed. The rear seats of the Pluriel don't remove; instead, they're meant to fold. But they're too big. When folded, the reinforced head restraint prevents the drivers seat being moved into a position that is comfortable for me to drive in. This means that only the passenger side rear seat can be folded flat if I'm to drive. It is still possible to fit one race bike in with both wheels off, but it's a squeeze.

Of course, like the 2CV before it, the Pluriel is designed with mountings for a roof rack - it's the only convertible currently for sale in Britain with mountings for a roof rack. So in theory one ought to be able to put the bikes on the roof... Except that my local Citroen dealer tells me the roofrack has been discontinued, and I haven't been able to locate one.

And then, of course, the Pluriel is much heavier, and consequently much less economical, than its ancestor. The 2CV weighed 560Kg, just over half a ton; with the benefits of modern advances in materials science, the Pluriel weighs 1158Kg. Of course, Citroen are not the only marque to fall into this trap; Issigonis' Mini weighed 617Kg against its modern successor's 1132Kg. A little of that extra weight is going into 'safety'; a little, more questionably, into 'comfort' and 'refinement'. But none of these cars major in refinement or comfort. The Citroens major in fun and adaptability, and the 2CV could legitimately add to that, 'economy'. The extra weight, sadly, means that the Pluriel cannot.

So what's my conclusion, after living with the Pluriel for nine months and ten thousand miles? Well, I like it very much; I find it hard to imagine another modern car that would suit me nearly as well. But if I could have brought a brand new 2CV instead, there would have been no competition. I do appreciate the removable side arches; they're (for me) a real improvement. The Pluriel is slightly more refined. The build quality does seem to be a bit better. But for the rest, it's much less engaging to drive, much less economical, and much, much less practical.

Monday, 16 February 2009

John Knox stirs in his grave

It would become illegal to view this picture in Scotland. 
OK, let's start at the beginning. My party - the Scottish National Party - has introduced legislation making it an actual crime for girls under sixteen to have sex, and is now proposing to make it a crime to have images of 'rape'. These two matters are not distinct, they're linked. And to talk about why they're linked I want to start by agreeing that, yes, there are public policy issues here.

Young people are vulnerable to older people. When very young, they're very vulnerable; we teach young people to view adults as authority figures. Most of the time this is a good thing. But it means that young people are vulnerable to sexual advances from older people, sexual advances which they might have rejected from someone who did not have perceived authority. And, young people inevitably have less experience of sexuality than their elders; they don't have an appropriate repertoire with which to respond, and this too makes them vulnerable. So young people do have to be protected, and it's right that, as a society, we have rules which prevent adults predating sexually on children.

Similarly, rape is a serious matter. Rape, even if not violent, can have a devastating psychological effect on the victim. Again, issues of authority and of power are involved in rape. It's obviously right that, as a society, we should have rules which protect people (mostly women) from being forced into unwanted sex by others (mostly men).

So I'm not arguing for rape or for paedophilia. I'm arguing for open debate, clear thinking, honest statement of problems and issues. I'm arguing for free speech, and for freedom of artistic expression. Because it is at least partly through artistic expression that society develops its norms, and passes them on to rising generations. When Charles Dickens was concerned about the condition of children in Victorian London, he wrote novels about it. When Robert Burns wanted to express his opposition to slavery, he wrote poems about it. The novels and poems reached a far wider audience and ultimately affected political change far more effectively than dry factual accounts.

I'm not arguing that paedophilia is acceptable, but why is there considered to be a crime committed when two fifteen-year olds make love? Are they each supposed to be predating on one another? Are they each supposed to be predating on themselves? And does anyone - does anyone - believe that to have the police intervene in a relationship between two fifteen year olds is not going to be far more harmful to them than under-age sex ever is?

Yes, the state must provide young people with appropriate education, appropriate access to contraception and health-care and counselling. Yes, the state must protect young people from predatory adults. But criminalising the first tender development of sexuality? That is - literally - obscene.

And so we move onto the second issue. The government - my government - my party - proposes to make it illegal to possess images of
'Rape and other non-consensual penetrative sexual activity, whether violent or otherwise...'
Part of the legal fiction which gives rise to this sort of legislation is that somehow consent is simple, and that it's possible to tell from an image whether consent was given or not. But in practice, consent is not that simple. A person may consent to an act with a given partner, and not consent to the same act with the same partner a few days or hours or minutes later. The act is not different. One could not necessarily tell, looking at a photograph afterwards, which act was mutually consented to and which was not.

The need for sexuality, and the nexus between sexuality and aggression, is very deep in the human psyche, very close to the centre of who, and what, we are as people. We all have it, and it troubles many of us in one way or another. As playful creatures, many of us choose to explore these issues through play. Play in which there may be many layers of the granting or withholding of consent; games in which people may choose to consent to engage in forceful sex against their active protest.

And many people - perhaps, we don't know, very many people - find some degree of pain or fear enhances sexual pleasure. Consensual sexual activity can be extremely vigorous, can be extremely uncomfortable, and can involve implements designed and intended to cause pain. How many decent middle class homes in Scotland have a pair of handcuffs or a whip or flogger hidden at the back of a bedroom drawer? We don't know. I don't know and you don't know - because we're a sexually repressed nation. But the people who sell these things do a good trade, here in Scotland; I'd hazard a guess it's more than any of us would think.

This isn't to defend rape. It isn't to excuse rape. But rape is something that happens inside the head of the victim - consent is either given or withheld. Consent is not something a picture can show. Coercion does not need to involve violence; no matter how tender an image of sexuality, we cannot know by looking at it that one or both of the participants was not blackmailed into taking part. No matter how apparently violent an image of sexuality, we cannot know by looking at it that it has not been positively chosen and is not being actively enjoyed by all concerned.

There is a yet more serious issue beyond this. The present legislation is aimed at images; but will have a chilling effect on all art forms. If we cannot explore issues of sexuality, coercion, violence in narrative, in stories, in film, in other art, how are we to give our rising generations language in which to explore and understand what is appropriate and what is inappropriate? Repression does not stop things happening. People will continue to have sex. Some of that sex will continue be rough. But if we have outlawed discussion about what is, and what isn't, acceptable to us as a society, how are victims to know when it is appropriate to protest?

Wednesday, 1 October 2008

Sex, adolescents and the law

Adolescents have sex.

This impacts on their lives negatively in a number of ways - certainly under-age pregnancy is now a very serious matter for public policy concern and the spread of sexually transmitted diseases among the young is also worrying. It's obviously undesirable to have adults predating sexually on children. It's also highly undesirably that young people of either gender should be pressurised into sex before
they're emotionally ready.

But that's precisely the point.

Emotional readiness does not occur miraculously on your sixteenth (or, in Scandinavia,14th, or in the USA, 18th) birthday. It happens when it happens. I personally didn't have 'underage sex', but then I was a late developer - many people with whom I've discussed the matter did, and most of them think (as adults) that it was a good thing, the right thing for them.

Legislation - the criminalising of normal, innocent and tender sexual behaviour - is grotesquely wrong; a quite immoral step to take. Where two fifteen-year-olds have consenting sex in the context of a relationship however ephemeral, the limit of public policy concern should be, had they had appropriate education to help them make the decision, and did they have appropriate access to contraception. And if they did not, the failure - the 'crime' if you like - is not theirs but ours - society's - for not providing these things.

Personally I'd go further and argue that adolescent sexuality between partners not more than two years apart in age should not be criminalised. We do - and should - expect older people to be more responsible. But a relationship between a seventeen year old and a fifteen year old does not seem to me perverse, unnatural or worthy of criminalisation.

There are, of course, serious issues here around alcohol, consent, and peer pressure. Access to alcohol does seem to me a matter for public policy intervention and I fully support the Government's plans to raise the age at which it is legal to purchase alcohol. But peer pressure is not going to be resolved through legislation. No matter how draconian and intrusive we make the state, adolescents are still going to whisper among themselves about who's 'doing it', boast, exaggerate, or feel left out. Education can address this. Legislation can't.

I don't want ours to come to be seen as the killjoy party, or the party of the old against the young, the spiritual and political successors to the unlovely John Knox. Alcohol we must indeed deal with. But when you pile one thing on top of another, young people in Scotland are bound to come to the view that the SNP is hostile to them, and that is going to cost us votes. But, aside from that, we should not do this not because it is in our partisan interest not to do this, but because it would be immoral of us to do this.

This is not a matter for criminal law.

Saturday, 23 August 2008

Medals, counting and chauvinism

The BBC has a predictable story this morning about whether Scotland will have its own team at the London Olympics. Which is a silly season story, a slow-news-day-story, a non story. First of all, it is quite possible that by 2012 Scotland will be irrevocably on the road to independence. We should have had a referendum before then, but even if the unionist parties block it we will have both Holyrood and Westminster elections before then, and it is entirely possible under present circumstances that the SNP will gain an absolute majority of Scottish seats in both.

In any of those cases, of course there will be a separate Scottish team at the London olympics. On the other hand, if Scotland fails to choose independence, of course there won't. It's as simple as that.

But there's a deeper, nastier chauvinism behind the story. The British media - the BBC inter alia, although they may not be the worst offenders - have been making a big deal about 'Team GB' coming fourth in the 'medal table' as if that somehow reflected credit on the second most obese nation in the world, the nation of lard arsed couch potatoes whose nearest approach to athleticism is the five-metre waddle from the double yellow line to the pizza counter.

Scotland shouldn't have its own team, runs the argument, because if it did 'Team GB' might not come fourth in the table.

But look at that medal table, and what do you see? You see big, populous countries at the top. If you adjust it by population, suddenly 'Team GB' is not fourth but twenty second. Russia was not third but thirty-sixth. The United States were not second but forty-fourth. China was not first but sixty-sixth.

If there is credit due to nations for their athletes' success, it goes to Dutch Antilles and Jamaica, with far and away the highest ratio of medals to population. The best performers among the European nations were Slovenia, Norway, Estonia and Latvia - all smaller than Scotland. And Australia - about whose relative 'failure' the BBC has been crowing - did substantially better than 'Team GB', at sixth. But do nations deserve credit, and if so why? These athletes are extraordinary individuals, and their successes are individual successes.

Let's stop to consider where the credit lies for Scotland's performance. I don't yet know - because it's not in all cases obvious which athletes are 'Scottish' - how well Scotland performed. But our outstanding athlete was Chris Hoy. Where did he develop his talent? Meadowbank Velodrome. What is Scotland doing to celebrate? Demolishing it. To say 'yes, but we're also building one in Glasgow' is no excuse. That a city the size of Edinburgh has nowhere for young cyclists to race in safety is quite simply a scandal.

So what's this about racing - and training - in safety? Jason McIntyre should have been another of Scotland's athletes competing for medals in Beijing, but he couldn't make it - because 'Team GB' couldn't give him a safe environment to train, because Britain's casualness about driving standards casually killed him. And while the team were out in Beijing, Davy McCall, who represented Northern Ireland at the 1998 Commonwealth Games in Kuala Lumpur, was killed in exactly the same way. This is how Team GB supports our elite athletes: we kill them.

Our athletes have done extraordinary things. They deserve enormous credit. But they've by and large done extraordinary things in spite of, rather than because of, the support (or lack of it) we've given them. Politicians - of any party, even mine - who try to take credit for the achievements of Chris Hoy need also to take responsibility for the death of Jason McIntyre. Where are our next generation of elite cyclists going to come from, if we demolish the velodromes and treat the slaughter of cyclists by motorists as a peccadillo?

Yes, but how did Scotland do?

So, after the rant about how bad chauvinism is and how credit for the achievment rests with the individual rather than the nation, how did Scotland do? Well, one person won all our gold medals. Step forward Sir Chris - without you Scotland would have had a very thin haul. Without Meadowbank Velodrome, indeed, we wouldn't have had two thirds of our medals, because one of 'our' three silvers came from Ross Edgar. If Chris Hoy, rather than Jason McIntyre, had gone under the wheels of a careless motorist this spring, we'd have had no golds at all.

For the rest, Katherine Grainger brought us a rowing silver - but as part of a crew of four the rest of whom were not Scots. David Florence won a silver canoeing. And that's it; that's all, folks. Six medals, four in the velodrome, two on the water. Three gold, three silver. And, arguably, two which an independent Scotland would not have got, since one of Hoy's and Grainger's came in team events with non-Scots making up the bulk of the team.

So how does that compare? 'Team GB' scored 1 medal for every 1.3 million people - as against China's 1 medal for every 13 million people or Jamaica's one medal for every 250 thousand. Team GB scored one gold for every 3.21 million, as against China's one gold for every 26 million or Jamaica's one gold for every 450 thousand.

If you consider 'pure' Scottish medals only, leaving out Hoy's team sprint and Grainger's sculls, Scots athletes bring home one medal for every 1.28 million Scots - marginally better than Team GB - and one gold for every 2.55 million Scots, considerably better than Team GB. If you count all the Scottish athletes' medals, Scotland has one medal for every 850,000 people, and one gold for every 1.7 million.


Looking at medals score and bragging rights and all the chauvinist claptrap alone, Scotland has no reason not to fly our own flag at the next olympics. We do have the talent.

Sunday, 17 August 2008

It's not cricket!

Look, lets stop fooling ourselves. The London and Edinburgh velodromes have both been sold off to developers - the London one, supposedly, to help pay for the Olympics. We have Chris Hoy because when he was developing in the sport there was a velodrome in Scotland for him to learn the ropes. Now there isn't - so where is the next Chris Hoy coming from?

There's someone else from Scotland who should have been winning medals for us at this Olympics. Jason McIntyre should have been doing for us in the man's time trial what Emma Pooley did so brilliantly in the women's. But Jason couldn't be there - because some careless motorist killed him while he was out training this spring (and was fined a derisory five hundred pounds in punishment).

Cycling doesn't have too much spent on it. Cycling doesn't have nearly enough spent on it. Every medium sized town has an Olympic size swimming pool. Every city has a running track. And we have one - count them, one - indoor velodrome in the whole country. In no other of our elite sports do we turn promising young athletes out onto the roads to battle it out with speeding motorists too busy with their mobile phones to pay attention to where they're going.

And yet half of all Britain's gold medals this year have come from cycling. Half. As many as all other sports put together. And there are more to come - Victoria Pendleton, Mark Cavendish and Shanaze Reade haven't even started yet.

So no - it isn't cricket. It isn't dull and tedious and arcane. It's epic and explosive and tactical and colourful and glorious. And we're good at it. So for heaven's sake get behind our cyclists and support them. Because if you think this is good, you ain't seen nothing yet.

Saturday, 26 April 2008

The spread of knowledge in a large game world

part of the role of Dandelion, in The Witcher games,
is to provide the player with news
These days we have television, and news. But in a late bronze age world there are no broadcast media. News spreads by word of mouth. If non-player characters are to respond effectively to events in the world, knowledge has to spread.

How to model this?

Some non-player characters - doesn't need to be many - are news-spreaders. News-spreaders need to travel. They have to travel even when there are no player characters in the vicinity. But, they don't have to travel very often - once or twice every game day. When a news-spreader is in the immediate vicinity of another character, the pair may (with some degree of randomness) exchange news. There needs to be a hierarchy in the exchange of news, so that 'I-saw' events need to be more likely to be passed on than 'I-heard' events; there needs to be a counter which counts the number of times a knowledge item has been passed on, and also an age counter so that knowledge items are less likely to be passed on as they get older.

One obvious class of news-spreader is a merchant. Merchant agents can either shuttle mechanically between a fixed group of markets or else possibly respond intelligently to supply and demand. Provided that there is a mesh of merchant routes covering the markets of the game world, and that a useful subset of non-merchant characters are required to visit a market every few game days, this should give a reasonably realistic framework for news spreading.

What else? What things qualify as news items? I think at least the following:
  • Deaths of sentient characters, especially if violent
  • Commodity prices
  • Changes of rulers in cities
  • Marriages of sentient characters
  • Plot events, flagged as events by the game designer
Obviously, news is more valuable if the people involved are important or notorious: the significance of a story is probably the product of the significance of the people concerned.

So a news item becomes a tuple

(days-old nth-hand significance action (actors))

for example

(54 2 10 'killed '(fred joe))

meaning 'I spoke to a man who'd spoken to a man who said he saw notorious fred kill well-liked joe on 54 days ago'. Obviously, the non-player character must be able to construct a natural language sentence from the tuple when speaking within the hearing of a player character, but there's no need for a non-player character to produce a natural language sentence for another non-player character to parse; instead they can just exchange tuples.

But if we're exchanging knowledge between agents, then agents must have a means of representing knowledge. This knowledge is an association between subjects and sets of statement, such that when the agent learns the statement

(54 2 10 'killed '(fred joe))

it adds this statement (with the 2 incremented to 3) to the set of statements it knows about fred and also to the set of statements it knows about joe. It's possible that the receiving agent could then challenge for further statements about fred and/or joe, the automated equivalent of a 'who's joe?' question.

There could be feedback in this. Fred's and joe's significance scores could be incremented for each character to whom the statement is passed on, increasing the likeliness that fred, at least, would feature in more news stories in future. There needs also to be some means of managing how the non-player character's attitude to the subjects of the statement are affected. For example, If fred kills joe, and the character (say bill) receiving the news feels positively towards joe, then bill's attitude to fred should become sharply more hostile. If bill feels neutral about joe, then bill's attitude to fred should still become a bit more hostile, since killing people is on the whole a bad thing. But it bill feels very hostile towards joe, then bill's attitude to fred should become more friendly.

Obviously the rate of decay, and the degree of randomness, of the news-passing algorithm would need to be tuned, but this schema seems to me to describe a system with the following features:
  • Non-player characters can respond to questions about significant things which happen in the world - without it all having to be scripted
  • If you travel fast enough, you can keep ahead of your notoriety
  • Characters on major trade routes will know more about what is happening in the world than characters in backwaters
This seems to me a reasonably good model of news spread.

Scaling of the algorithm

Let's work around the idea that a 'game day' equates to about two hours of wall clock time. Let's work around the idea that there are of the order of fifty markets in the game world, and that for each market there are two or three merchants whose 'home base' it is.

Obviously non-player characters who are within the vicinity of a player character have to be 'awake', in order that the player can see them interacting with their world and can interact with them. Those characters have to be in working memory and have to be in the action polling loop in any case. So there's no extra cost to their gossiping away between each other - around the player there's a moving bubble of gossip, allowing each character the player interacts with to have a high probability of having some recent news.

But the merchants who aren't in the vicinity of a player don't have to be in working memory all the time. Each merchant simply requires to be 'woken up' - loaded into memory - once per game day, move a day's journey in one hop, and then, if arriving at an inn or at a market, wake and exchange news with one resident character - an innkeeper or a gossip. So the cost of this algorithm in a fifty-market game is at worst the cost of loading and unloading two non-player characters from memory every minute, and copying two or three statements from the knowledge set of one to the knowledge set of the other. If you're dynamically modifying significance scores, of course, you'd need to also load the characters about whom news was being passed on; but this still doesn't seem unduly onerous.

Obviously, if memory is not too constrained it may be possible to maintain all the merchants, all the innkeepers and all the characters currently being talked about in memory all the time, further reducing the cost.

Friday, 4 April 2008

Worlds and Flats

Of Compartmented Worlds

Playing The Witcher has got me thinking again about an algorithm for rendering a world which I first thought of twenty-five years ago. Then, it was a hack for dealing with the fact that the computers of the day didn't have much memory or horsepower. Now, it's a hack for dealing with the fact that - when considered against the complexity of a world - the computers of today still don't have enough memory and horsepower. Mind you, today I'm contemplating photorealistic scenes, whereas then simple line and wash would have been good enough, but...

The algorithm for rendering I'll call 'flats'. But before we get to discussing flats, lets discuss worlds.
The world of The Witcher (and other games based on the Aurora engine) is composed of areas. One area is loaded into memory at a time; when the player reaches an area boundary, the area is unloaded in toto, and the next area loaded, also in toto. The result is a noticeable interruption in game play. There's also, normally, a noticeable visual disjunction at the boundary; the new area uses a different 'tileset', which is to say, set of bits of scenery. When you look across a boundary, the scenery often appears different from what you find when you cross the boundary and arrive at the other side.

Finally, you can only cross boundaries at specific gateway points. For example, Chapter Four of The Witcher takes place in a continuous rural space composed of three main areas: the lakeside, the village, and the fields. Between the lakeside and the other two regions there's a wooded escarpment, which provides some logical justification for the fact that there are actually only two places you can actually cross it - from the lake shore, either up the road to the village or else through a series of glades to the fields. But between the village and the fields there's no such logic. There are a pair of gateposts, and you must cross between those gateposts - but the landscape appears continuous, with no visible barrier. It's an artifact of the game engine.

So, how to deal with this?

My interest, let's be frank, is in story telling; and the nature of story telling is moderately constrained plots. In computer mediated story telling the reader/player can and should be able to explore the plot in his own way, make his own choices, take his own path through the environment, encounter the elements of the plot as he encounters them on that path, and it's the job of the story teller to make that engaging whatever path the reader takes. But if the reader chooses to ignore your hints and wander out of the area you've populated with plot altogether, there's two things you can do. One is put up physical barriers which stop him (although the silly field fences in Chapter One of The Witcher do /not/ count, as it's obvious that Geralt could simply hurdle them; they are just another artifact.

Of Finite and Infinite Worlds

But an infinite world is not required for the sort of stories I'm interested in; the sort of stories I'm interested in take place in, at best, regions of infinite worlds. Just because I don't choose to use all of it, of course, is not a reason that a world should not be infinite.

There are plenty of fractal mathematical equations which map an infinite three dimensional surface with landscape like features. If such an equation gives you land heights, then altitude, steepness and orientation will give you soil type and vegetation cover. There is no need to store a whole world in order to be able to reproduce it exactly when the player follows the same route through it for a second time; it is sufficient to start with the same seed. So a world need not take up vast amounts of disk space for pre-mapped scenery; scenery need only be mapped as it comes in sight. This is fundamentally the trick used by Elite to pack a large, reproducible universe into less than 32K of RAM, and it still works today.

Of River Systems

However, there are reasons to prefer that a world be pre-mapped, at least at coarse grain. One example of why is river systems. It's trivial that we render a river at the bottom of a valley, but it isn't trivial to compute how wide and deep that river should be. To calculate that we have to explore the extent of the watershed upstream of any given point, and sum the rainfall on it, which in turn is a factor of exposure to prevailing airflow and the proximity of ocean to windward. It's computable, but it's much more efficient to compute it once and cache the results, especially since for any given river system it's a recursive function.

Furthermore, rivers cause erosion, changing the landscape through which they pass, cutting gorges on steep slopes (especially if soft), building up flood-plains in flatter areas downstream. Some fractals are naturally extremely landscape-like, but it seems to me - better mathematicians might prove me wrong - to realistically render river systems requires some degree of post processing, and post processing which would be expensive to do repeatedly in realtime.

Of Human Settlement

Human settlement is a separate issue. Many years ago I wrote a program which modelled the spread of human settlement over a landscape.

Human settlement is not random. Human settlement follows rules and patterns. Pioneers settle in places which have a sufficient spread of resources to meet their year round needs; they settle near to easy routes from their parent settlement. Pastoralists need grazing land and water; they spread up river systems, but avoid marshy areas. They settle where there is open grazing, but often close to a forest edge for access to timber. Second wave settlers prefer to settle close to existing settlers, for mutual protection and help. Cereal growers join these settlements where the depth of soil is optimal for crops. As the settlement grows and pressure on land increases, the forest edge is cut back both for building material and to increase the available agricultural land. If a settlement fails, the forest may reclaim this land

Road networks develop. People travel between settlements by the easiest route - but the very fact a route is travelled makes it easier. A path gets cleared; later, people fill in boggy bits and bridge streams, to make their own passage easier or to encourage trade through their lands. Because as a road grows more important, so the settlements along it grow more important, and as the settlements along it grow more important so the roads between them grow more important. The road network, then, is a dynamic fractal which interacts with another dynamic fractal, the distribution of human settlement.
The program I wrote was a cellular automaton which modelled human settlement in only thirty states. It did a remarkably good job. Settlement would spread across a landscape; settlements in strategically beneficial areas would grow faster, develop temples and markets sooner, and thus become important foci of the roads system; other settlements would wax and wane, some falling into ruin; new waves of settlers might settle in slightly different areas.

More states would be better, give a richer, more subtle model, But this demonstrates that it's easy to design a program which will settle a landscape in a realistic way automatically. Once again, though I think it can be done more realistically if it is precomputed and cached rather than if it is generated from the landscape fractal.

In summary: yes, I think it's possible to have an infinite world which is satisfying and can be reproduced at will from a seed, but the stories I want to tell do not call for infinite worlds and if the world is finite I believe it can be made still more satisfyingly realistic by pre-computing and caching things like river systems, afforestation and settlement patterns. Either way, though, the world can be very large - much larger than the worlds of current near-photo-realistic games. The world of The Witcher, for example, is a few hundred hectares; I'm envisaging storing hundreds or thousands of square kilometres in similar data size and with a similar expenditure of artist's effort.

Rendering, and the Flats idea

Rendering a convincing distant view in computer-generated virtual environment is hard. There's an enormous amount of data in a distant view, and if the viewer is moving in real time it becomes computationally unaffordable, even on machines with a great deal of horsepower. Games typically work around this problem by either angling the camera downwards, or else rendering a high degree of atmospheric haze - it's always slightly foggy - so there is never a distant horizon.

Movies shot in studios often have wonderful, detailed backgrounds to their sets. Vistas of far mountains and great cities... of course, the far mountains and great cities don't exist in the set. They're painted on large canvases called 'flats'. The flats illusion depends on the camera not moving too much, because of parallax - nearer things should appear to move relative to further things, and on a flat they don't.

But. But.

For a player moving in a computer game the field of view is quite restricted - it's no more than thirty degrees, typically straight ahead as he moves. Parallax movements are less significant straight ahead. A single flat still isn't going to work, but in many animated films a system of multiple flats is used, with the nearer flat moved relative to the further flat to give an illusion of parallax. This can work very well.
Suppose one projects onto the world a hexagonal grid - it doesn't have to be hexagonal, but I think that is likely to work best - with a cell size of about 100 metres (the exact cell size depends a bit on the speed of movement of the player, for reasons which will become apparent). Cells are grouped into metacells of seven cells (if square, then metacells of nine cells). For each cell, there are six inner flats. Each inner flat consists of a rendering from the centre of the cell of everything more than one cell distant, but less than five cells distant, over a 60 degree arc of view.

For a given area of the world the distant view doesn't change very much. We don't, therefore, have to compute a set of outer flats for every cell, just for every metacell. The outer flats each consist of a rendering of the scenery more than one whole metacell away, from the centre of the metacell.
To render a scene, then, we first paint the outer flat for the metacell the player is in, in the direction the player is looking. Over that we paint the inner flat for the cell the player is in. Over that we render the actual objects in the adjacent cells which fall within the viewing area. Over that we render the objects in the current cell. Thus we only have to render in real time certainly no more objects than can already be rendered by systems which clip for distance either by angling the camera down or by using fog, and yet still manage a realistic distant view.

Rendering the Flats

OK, so when do the flats get rendered? After all, if you're going to pre-render six full colour full screen resolution flats for every hundred metre cell in the world, then either your data volume is going to get enormous or your world is going to get pretty constrained - which was just what we were trying to get away from. And if you're going to multiply that with flats rendered for every time of day and every weather condition - well, it's not feasible.

You cannot realistically pre-render the flats, in my opinion. Or if you can, you're going to have to give them so much real time post processing that you will lose the benefit. Pre-rendering the flats is not the idea. But if they are rendered in real time, where is the benefit...?

There's a middle way. Running straight forward at top speed a player crosses a hundred metre cell in about a minute, during which to give an illusion of continuous movement at least nine hundred full screen frames must have rendered. But the flats don't change in a minute. The flats don't change in five minutes. They don't need to. Even if rain clouds are sweeping across the landscape, it's OK for the distant view still to be sunny five minutes after the rain reaches you, or vice versa. If you can render a high proportion of the detail in a view only once every nine hundred frames, you've saved a lot of processing.

So there is a continuous background process running which renders flats. It does it all the time. It prioritises making sure that a flat exists for every direction the player may look in in the next minute - that is, every direction from the cells and metacells he's currently heading towards. Having done that, it renders flats for cells to either side which he might turn to. It maintains in memory a small stock of flats from recently visited cells, so that if the player turns back they don't have to be repainted in a hurry; and if a flat is more than about five minutes - 4,500 frames - old, it may repaint it to update time-of-day lighting or weather effects.

Obviously, quite a lot of the time the join between two adjacent flats will be in view. I don't see this as a problem. Just naturally, the rendering of the flats should essentially form segments of a hoop, so the join between two adjacent flats should not be perceptible.

Artifacts

Inevitably, there will be undesired artifacts of this system. Significantly, mobile objects - 'non-player characters', the avatars of other players, monsters and computer mediated creatures in the landscape - more than two cells away will not be visible. The flat is static, so it can't have moving characters on it. There may be some algorithmic way round this, since one hundred and fifty metres away is rather close for people to suddenly vanish; but it is not a problem I have a solution for.

Again, if the player is looking sideways as they cross a metacell boundary, there will be a jarring sudden shift in parallax. I acknowledge that and think it just can't be helped; that the benefits in terms of quality of view for given computer power, will render it acceptable.

Creative Commons Licence
The fool on the hill by Simon Brooke is licensed under a Creative Commons Attribution-ShareAlike 3.0 Unported License