## Economic models #

I'm trying to build a very simple economic model for the blobs. There are two types of items: food and money. A blob can do four things: rest, plant crops, harvest crops, or eat. What makes this complicated is that the blob has to make a tradeoff between present and future and between comfort and wealth.

How can I make it *interesting*? I don't want one option to be always better than the other.

One way to make blob behavior interesting is a non-linear utility function. Intuitively, the unpleasantness (negative utility) of each hour of work increases the more work you've done. Hour ten is tougher than hour three. Also, the pleasantness of goods (positive utility) decreases for each additional unit. This is called diminishing marginal utility in economics. With this principle we can have blobs that do not always choose the same thing, because choosing the same thing over and over leads to reduced returns each time.

The blob decision algorithm is: compute the total utility function of each of the alternative actions and then choose the highest one.

What I still haven't worked out is how to value the *future*. Planting crops has a present negative utility and a future positive utility. But how do I value the future utility? Having two farms that can be harvested in six months isn't equal to having one farm that can be harvested in three months and another that can be harvested in nine months. How do I take into account the amount of time involved? How do I take into account the possibly varying price of food? Also, how do I take into account the ability to choose something different (by having free time) in the future?

## Autonomous blobs #

I'm currently working on the blobs (villagers). I'd like them to be self-sufficient: they should be able to feed and shelter themselves by building farms and houses automatically to meet their needs. I've started by implementing simple blobs (currently represented by inverted pyramids, which are easy/fast to render) that can move around. Currently, blob positions are (x,y) instead of (m,n) -- world space, not grid space. We'll see how well this works.

To place a blob in 3-space, I need to compute z. To do this, I need to find out which triangle the blob is in; the vertices of the triangle are centers of hexagons, for which z values are known. I then convert the blob's location to barycentric coordinates within the triangle. The barycentric coordinates (b1,b2,b3) where b1+b2+b3=1 give me weights, and the blob's z value is b1*z1 + b2*z2 + b3*z3.

The actual implementation of the z-finding function reinterprets the hexagon grid as a rhombus grid. The nice things about rhombuses is that they are just a shear transformation away from a rectangular grid. That makes it very easy to figure out which triangle you're in.

Another thing I needed was to compute the gradient at any point. The gradient tells you which direction is the steepest. If you can picture a triangle in your head, take the normal to the triangle and project it down onto the z=0 plane. That tells you what direction is the steepest downhill. I use this to implement gravity: the force applied to the blobs is proportional to the gradient vector.

You can generalize the gradient to work on any function of (x,y). If you take the gradient of moisture(x,y), then you have the direction in which the moisture decreases most rapidly. Blobs that carry water to dry areas could use that gradient as a guide. If you take the gradient of food_price(x,y), then you have the direction in which the food prices decrease most rapidly. Blobs trying to buy food should move in that direction. Blobs trying to sell food should move in the opposite direction.

## SimBlob 2 #

Status of SimBlob 2: I have the map working (hexagonal grid, mountains, valleys, water), 2.5d navigation (you move around in 2d and can rotate and zoom, but can't change altitude), and some environmental simulation (springs, water flow, erosion, soil moisture, ground vegetation (grass)). The code is OpenGL+GLUT and should compile for Linux/Mac/Windows, although I've been developing in Linux and haven't tested the other two platforms.

[Update: I'm no longer working on SimBlob 2.]