You must be logged in to post messages.
Please login or register

Caesar III: Game Help
Moderated by Granite Q, Gweilo

Hop to:    
loginhomeregisterhelprules
Bottom
Topic Subject: Randomness of Random Walkers (continued)
posted 06-24-08 22:17 ET (US)   
See previous thread

After two nights of wading through binary and thoroughly confusing my easts and wests I've now got a proper handle on the 'random' portion of a roaming walk. It's surprisingly simple, though devilishly difficult to figure - until you know how.

Every tile on the map is 'seeded' with an apparently random number which seems to be generated when the map is created and preserved when it is saved. These numbers are used for a variety of purposes, though I don't pretend to know all of them. In my last post on this subject I reported some of the effects of 'zeroing' the entire grid so as to negate the influence of those numbers on various game mechanisms.

I took this a step further. I ended up filling the 'random grid' of a custom 160x160 map with blocks of constant data, 32 tiles by 32. The first block was filled with zeros, the second with 1's, then 2's, 3's and so on. Apart from the rather pleasing cabbage-patch effect on the terrain I was thus able to run side-by-side tests and (eventually) unravel the mystery.

The four semi-cardinal directions in the game (NE, SE, SW, NW) are represented by the numbers 0 to 7, so that 0 or 1 is NE, 2 or 3 is SE, 4 or 5 is SW and 6 or 7 is NW. Since there are two numbers for each direction, I suppose it's possible that one of them might actually represent an in-between (cardinal) direction like North or West, but since the random part of a walk is confined to semi-cardinals (with rare exceptions) we can ignore that possibility.

Since we are using only the eight numbers 0 to 7, in computer terminology we are only interested in the last three bits of a number. We get this by taking the remainder after dividing by eight, so that 27 resolves to the number 3, the number 63 resolves to 7 and 80 resolves to 0 (Those three bits are the same as the ones used to determine where houses will merge). It so happens the same number determines the 'initial seeker' direction - the quadramble first executed by the labor seeker of a newly placed building depends on the result of divide-by-eight on the seed associated with the building's northern tile and in accordance with the number-to-direction relationships I itemised earlier.

StephAmon's "Ambulomancy" paper, a remarkable piece of deductive observation, gives us the means to predict a walker's path up to the end of its first 'outward-bound' phase. He coined a number of terms for different walker types. We need not concern ourselves with the 'distance-shorted' walker since it has no 'random' phase. The same goes for 'teleporting' walkers who do not return to their buildings after the outbound phase (schoolchildren and 'long distance' engineers, tax collectors and entertainers).

The 'grounded' walker travels in destination mode (using gardens if a shorter route is thereby provided) to a target tile (the algorithm for determining the target is beyond the scope of this post, but interested readers can refer to StephAmon's paper). A mode conversion takes place on the target tile, which becomes Tile #1 of the random walk which will continue (road-bound) for the normal default walk length (26 tiles for most walkers) from that point. He then returns home by the shortest route (using gardens if appropriate). A grounded walker need not be road-connected to his target if there is a garden path.

The 'blockage-shorted' walker travels in destination mode towards a target until it meets a gatehouse which prevents it from continuing. It then converts to random mode for the remainder of its normal walk length, following which it returns home (except that engineers, tax collectors and entertainers don't visibly return home). Tile #1 if the random phase of this walk type is the last walkable tile before the blockage. Note that destination mode walkers approaching a gatehouse 'sideways', i.e. on a road which passes along its front rather than meeting it square on, will attempt to enter it diagonally, so the last walkable tile is the one immediately before it:
GGRRRRRRR
GGR
*
R
R
The asterisk marks the conversion point for walkers coming up along the vertical road.

The 'default' walker has no target and travels (almost) entirely in random mode. Tile #1 of his walk is the tile where he spawns (which, thanks to Brugle a long time ago, is also predictable).

All that was a rather long-winded way of determining where Tile #1 of the random phase is. This is important, because you cannot hope to predict a turn without knowing that. Neither, unfortunately, can you hope to predict it without knowing what value has been used to 'seed' the tile on which the intersection lies. That probably means finding the map coordinates (0,0 is the northern corner - x increments SE and y increments SW), working out the offset into the random grid and inspecting the value stored there.

Prediction is then just a simple matter of adding together the tile number (counting along the walker's path so far beginning at tile #1) and the 'random' seed. Divide by eight, take the remainder, and you have the direction he will take. And that's all there is to it

If the computed direction is unavailable the first available clockwise direction is taken, remembering that the direction he has come from, which may be the direction computed, is not available due to the 'no reversing' rule. That will not affect the outcome of the computation at the next intersection.

Example: Walker meets 4-way intersection on tile #7 of his walk. random 'seed' is 172. Total = 179. Remainder of divide-by=eight is 3. Walker will go SE (unless he is approaching from that direction, whereupon he will go SW).


Caveats:

(1) There seem to be exceptions to everything in this game, and I haven't exhaustively tested every walker. I wouldn't be surprised if one of those highly individual walker types breaks some rule somewhere.

(2) Targetted walkers that undergo mode conversion in an intersection appear to follow the rules. Default walkers that spawn in an intersection are a little less reliable. Sometimes they do, sometimes they don't.

You can see how I arrived at my conclusions in my last post - given that the 'seed' was always zero, tile #1 carried an inherent NE disposition while walkers on tiles 2 and 3 wanted to go SE, and the direction cycles clockwise every second tile.

Since gleaning this knowledge I've been playing with traps that will ensnare some walkers and not others (good for keeping labor seekers in contact with housing). And it's not strictly necessary to get out the hex-editor either. The number associated with an intersection (or at least the important part of it - the last three bits) can usually be deduced by watching what existing walkers are doing prior to placing an important building. If one walker goes SE on Tile #6 the seed must be a 4 or a 5 (unless he is going that way because he can't go they way he really wants). Another walker going NW on tile #3 more or less confirms it's a 4.

One final area I'll be exploring - these 'seeds' are associated with certain terrain graphics. The graphic system is quite sophisticated and it's quite difficult to pick out one type once they are all mixed up and merged together, but if a sharp-eyed player can spot a tile in the landscape where he knows a house will/will not merge or he can deduce the direction seed from that tile's appearance, he would have an advantage.

I do hope I've not overlooked anything - I've made enough gaffs for one week

[This message has been edited by Trium3 (edited 06-24-2008 @ 11:18 PM).]

Replies:
posted 06-26-08 20:09 ET (US)     1 / 9  
Bump.

Also,
'teleporting' walkers who do not return to their buildings after the outbound phase
Players sometimes have used the term "teleport" for walkers who disappear instead of returning to their buildings--I've probably done it myself. However, in modern usage, walkers "teleport" when they begin their walks somewhere other than beside their buildings. (In Pharaoh, this can include bazaar traders and some entertainers.)
posted 07-01-09 14:18 ET (US)     2 / 9  
Targetted walkers that undergo mode conversion in an intersection appear to follow the rules.
I realized something, which might have been obvious to others. A walker who converts to random mode immediately after cutting a corner into a target tile where there is an intersection will follow the rules (in the opening post of this thread). However, if there isn't an intersection at the target tile (as would often be the case on a rectangular loop road), a walker who converts to random mode immediately after cutting a corner will have a preferred direction of NE.

For example, I built a tower on a loop road. The citizen on his NE walk cuts the E corner to get to the target tile which is just NW of the E corner. He turns SE (since he is going N and therefore does not reverse direction) at the target tile, and heads back to the tower rather than continuing around the loop. (This would occur with an identical arrangement in any location.)

However, if I add an intersection on the target tile by putting a road tile W of the E corner, N of the E corner, or both, then the citizen turns NW at the target tile and continues around the loop. (The NW direction was specified by the "random seed" for the intersection. With an identical arrangement in another location, the citizen's behavior would probably be different.)

Sometimes, adding an intersection to a loop can make a walker go around the loop, not because the new road changes the targeting, but simply because the intersection exists!

[This message has been edited by Brugle (edited 07-01-2009 @ 03:35 PM).]

posted 07-02-09 00:16 ET (US)     3 / 9  
That's interesting. It may well have been obvious, but it hadn't occurred to me that I might be able to 'fix' one of those 'corner-reversers' in this manner.

Now I just need to ponder on all the other walks it would probably break
posted 03-21-12 06:07 ET (US)     4 / 9  
3 years later...

I recently (less than a year ago) started getting into C3 (had it since its release, never played it much) and must say its nice to see a forum still active for it.

Anyway with regards to random walker behaviour I did some rudimentary tests of my own (don't like reading too much detail on what other people have already figured out as it removes the reward of discovery) and I'm not sure if this is common knowledge or not but as I didn't see mention of it in the quick scans of the few related threads I've read I thought I'd make a post on a cute trick I've found.

Namely: If a random walker being generated has an initial destination square consisting of a single road tile that is reachable only by a garden route then upon reaching it they will immediatly become a destination walker returning home. (which is useful in reducing the amount of time before the overall walker cycle repeats itself so that useful routes occur more frequently).

Also there appears to be some differance in the path taken by a walker generated with an unconnected intial square versus one in which no intial sqaure exists.

[This message has been edited by Outpost 582 (edited 03-21-2012 @ 06:09 AM).]

posted 03-22-12 13:20 ET (US)     5 / 9  
Hi Outpost 582, welcome to Caesar III Heaven.
I'm not sure if this is common knowledge ... If a random walker being generated has an initial destination square consisting of a single road tile that is reachable only by a garden route then upon reaching it they will immediatly become a destination walker returning home
It's deducible from information that could be obtained by recursively following links, but most players don't bother with that much detail. I don't recall it being mentioned before.

I used that technique for some walkers in my Palace Peaks whose walks were fairly long.
there appears to be some differance in the path taken by a walker generated with an unconnected intial square versus one in which no intial sqaure exists
Could you be more specific?
posted 03-23-12 01:11 ET (US)     6 / 9  
Could you be more specific?
Certainly: I set up an Engineer's Post in a isolated part of the map surrounded by a 3x3 road loop. From this a section of road runs NE. Without any other nearby roads the SE,SW and NW patrols would just circle around the post but if I added a road tile eight squares away in the appropriate direction, then that patrol would head up the NE road. Since none of the tiles in the 3x3 loop are valid choices for the walkers initial destination (I checked), I concluded that the act of adding an unconnected road can affect patrol routes.

Frustratingly though this is not always the case and in other more likely setups there was no differance between the two cases.

Something else I've found is that if the shortest path connecting the entry and exit points of a map are too long (didn't count the distance), then trade caravans will refuse to enter the map (of course removing the entry tile improves their route anway so that is an unlikely scenario).
posted 03-23-12 21:22 ET (US)     7 / 9  
Outpost 582,

I don't know much about the middle (wandering around) phase of a "random" walk, but it seems to me that you're saying that Tile #1 (as Trium used the term) is treated differently for a 'default' walker depending on whether an (unconnected) walk target exists or not. Beware: engineers have some quirks not shared by most "random" walkers.
if the shortest path connecting the entry and exit points of a map are too long (didn't count the distance), then trade caravans will refuse to enter the map
I'd expect strange things to happen if the cross-country path from the entry point to the exit point is too long (I'd guess more than about 500 tiles), so I'll assume that that isn't the case. If there's a road from the entry point to the exit point that's too long, then I'd guess that caravans would not enter just to pass through but would enter to go to a storage yard that isn't too far away.

[This message has been edited by Brugle (edited 03-23-2012 @ 09:24 PM).]

posted 03-24-12 02:27 ET (US)     8 / 9  
it seems to me that you're saying that Tile #1 (as Trium used the term) is treated differently for a 'default' walker depending on whether an (unconnected) walk target exists or not.
There is an example where that is demonstrably the case (I'm too lazy to go see whether I mentioned it in any of my other ramblings).

Where a walker spawns in a dead end he will often be seen to begin a 'default' walk by doing an about-turn after a single tile of travel, only to bounce off the dead end and continue in the original direction (sometimes called a 'false start'). Placing a disconnected road tile near the appropriate routing centre for the quadrant associated with the walk causes the walker to abandon the habit.

Outpost 582's observation would appear to be linked in some way, though it is difficult to explain what might be going on in terms of the game's walker algorithms.

Oh, by the way - hi Outpost 582 and welcome

[This message has been edited by Trium (edited 03-24-2012 @ 08:44 AM).]

posted 03-24-12 03:41 ET (US)     9 / 9  
Brugle,

I suppose an alternate #1 tile could be the case though I don't know how I'd establish which it is, though I did notice that the walker would reverse at a corner when this was not previously the case. (Also there was no nearby housing so only a labour seeking worker was generated. I used an Engineers Post since it doesn't collapse).

For the caravan: It seems that they are forced to use the road if one exists and check its length to determine the distance to their target (instead of as the crow flies) and that their walk distance is reset after each warehouse they visit. If the distance from the warehouse to the next warehouse or exit is too large they simply teleport off the map (So presumably having all exporting warehouses near the entrance of the map and adding a maze at the exit would help maximize trade on larger maps).

Edit: missed Trium's post (Hi and thanks for the welcome)

What would constitute a dead end though, since my setup features a road loop?

[This message has been edited by Outpost 582 (edited 03-24-2012 @ 03:49 AM).]

Caesar IV Heaven » Forums » Caesar III: Game Help » Randomness of Random Walkers (continued)
Top
You must be logged in to post messages.
Please login or register
Hop to:    
Caesar IV Heaven | HeavenGames