Civ1 exploit: design flaw in randomness

Do you think that developers could resort to this simple solution while making Civilization 2?
 
Do you think that developers could resort to this simple solution while making Civilization 2?

Well, the exploited trick here is really a design flaw: developers could very well have temporarily stored the random seeds, then re-seed the generator for displaying the city, and then rollback the seeds to their value before the city was shown.

My point is that it is not really a "simple" solution - seed-based randomness is really widespread and classic. But it is very much possible that the same flaw exists in other versions of Civ (WinCiv, CivNet, ...) or even Civ2.
 
I should change my login to "darkpandora" ;)

LOL. Well, thanks for the response darkpanda. Yeah, I understood that if one were trying to figure this out by hand, one might be limited to "Okay, this city name works well when attacking a phalanx with a chariot... and I hope I found a seed that works for all the veteran and defense bonus combinations!"

I will say though that this is interesting information and affects my gameplay -- but not in the way you think! I have previously had my own skepticism about the CIV randomness generator to the point that I decided for a "pure" game by my own standards, I would play the game from start to end without even closing/reloading CIV, because I didn't know how deep the state goes on the random generator. I now know it's totally useless because that state is wiped just about every turn, so there's no point thinking that a game from beginning to end is any different from a game that is closed and resumed.

Anyway, thanks again as always (it will be interesting to see how huts work, too)

Jarvis
 

CIV RANDOM HACK - Huts table



Of course, in the wake of the random hack attack table I posted earlier, it did not take long to find out how to leverage the randomness for Hut rewards... I've had the table below on my disk for 2 weeks, and although I was waiting for a nice way to present it, now I think it's just been too long. So I'm just posting it as is, with necessary explanations.

How to read the table below?

The Huts table below is based on the Attack table and method presented in this post: CIV RANDOM HACK - Attack table

In the tabe below, the 4 numbers separated by slahes (/) represent the minimal number of "screen refreshes" (i.e. single random calls) after which the next call to random(4) will return, respectively, 0, 1, 2 or 3. Those random(4) results form the basis of the Tribal huts visit outcomes routine presented in this thread: Civ1 explained: tribal huts visit outcomes

For example, take a city of size 4 with 2 buildings:
  • the hut table below contains 0/3/1/10
  • the attack table contains P0 and +0
  • this means that, if your 4-pop 2-building city is named "P0", then after displaying its city view:
    • you will get an immediate win if attacking (+0 from attack table)
    • the immediate next random(4) will return "0" (first value "0" from hut table), which may result in a new city (Advanced tribe), a new unit (Skilled mercenaries) or 50$ when visiting hut
    • after 3 random calls, typically 3 screen refreshes (press 'C' key in map screen), the next random(4) will return "1" (second value "3" from hut table), which may result in a Civ Advance (Scrolls of ancient wisdom) or 50$
    • after 1 random call, the next random(4) will return "2" (third value "1" from hut table), which will result in 50$
    • after 10 random calls, the next random(4) will return "3" (fourth and last value "10" from hut table), which may result in a new unit (Skilled mercenaries) or a horde of barbarians

Hut table


Buildings ->0123456789101112131415
Size 11/8/0/50/2/7/10/2/5/10/2/1/71/3/2/00/2/1/74/0/3/10/2/4/10/4/7/10/6/2/10/2/6/10/2/3/10/6/1/31/0/4/20/7/1/20/3/8/1
Size 20/5/4/10/6/8/10/2/17/10/4/1/63/1/8/00/2/1/100/7/6/30/7/5/10/4/3/10/2/1/70/4/6/10/2/1/50/3/1/20/2/1/91/5/0/35/4/2/0
Size 30/2/3/10/10/1/20/7/6/10/5/1/90/3/1/40/2/9/10/9/1/20/16/2/10/2/1/30/5/7/10/6/4/10/7/1/20/3/1/20/2/4/10/2/1/80/4/2/1
Size 43/0/4/270/6/1/20/3/1/100/2/1/150/1/2/60/10/6/10/3/5/10/8/1/30/8/1/22/1/6/00/3/1/60/4/1/30/1/4/60/10/3/20/8/2/10/3/1/2
Size 50/9/4/10/2/1/40/2/1/75/2/0/10/7/2/10/8/1/50/3/5/10/10/4/12/6/0/52/0/3/40/2/7/10/4/2/10/8/20/10/3/1/70/2/1/40/2/1/5
Size 60/2/1/150/3/1/40/6/8/10/4/1/70/7/2/10/5/8/10/2/3/10/3/6/10/5/4/10/7/1/21/2/0/30/5/1/20/2/1/60/5/1/33/0/1/80/4/1/15
Size 70/3/11/10/2/1/30/7/2/10/6/4/10/2/7/10/7/1/40/2/5/10/3/1/110/2/3/13/2/4/03/0/1/40/3/4/15/3/0/73/17/2/00/5/1/20/3/1/11
Size 80/8/3/10/4/1/70/9/6/10/2/1/60/3/2/10/2/5/11/3/0/20/4/2/10/4/1/22/5/3/02/1/0/60/2/1/30/4/2/10/2/1/30/4/1/20/4/5/1
Size 90/2/6/10/7/1/60/2/1/40/2/6/12/4/0/124/0/2/10/3/8/10/5/1/70/3/1/100/11/1/30/2/6/10/3/1/23/0/1/50/5/2/10/4/3/10/4/5/1
Size 100/2/1/120/4/1/90/2/6/10/3/8/12/0/4/12/0/1/60/5/1/70/5/7/10/1/5/20/1/5/40/4/5/10/3/1/40/8/6/30/3/1/90/2/1/190/2/1/6
Size 110/3/7/10/3/8/10/2/1/52/3/4/00/8/1/70/4/3/10/7/2/55/0/18/11/8/0/20/4/10/12/0/1/46/1/0/70/3/1/20/8/3/10/9/3/10/4/1/6
Size 120/11/1/40/7/1/51/2/15/00/6/3/98/0/2/10/5/1/30/13/1/24/2/0/170/6/3/10/15/1/30/2/3/10/7/1/21/4/9/00/3/4/10/7/8/11/0/5/2
Size 130/4/1/23/0/5/10/3/2/10/9/6/10/2/1/40/14/1/60/2/6/10/8/4/10/2/1/80/9/1/40/13/4/11/3/0/50/18/3/10/11/7/10/4/1/30/2/1/4
Size 140/6/5/14/5/0/12/3/0/100/5/6/10/2/4/51/0/6/140/15/1/30/10/4/30/4/5/10/9/1/40/5/1/30/2/11/10/2/1/40/4/1/30/6/1/70/2/7/1
Size 150/8/1/50/2/1/70/4/1/73/0/4/50/6/1/30/7/2/10/2/4/10/3/1/20/6/2/10/2/1/90/4/1/60/3/2/10/14/1/100/2/3/13/6/1/00/5/4/1
Size 160/4/1/30/10/3/10/2/1/50/8/6/10/2/3/10/11/1/30/2/1/31/6/3/00/8/2/16/0/3/23/0/1/40/2/1/90/7/1/20/3/5/10/4/1/30/4/2/1
Size 170/3/1/100/2/1/50/4/2/10/8/1/33/26/0/50/7/2/10/2/8/10/2/11/10/8/2/10/3/1/20/3/5/10/10/2/10/4/1/30/3/1/20/3/6/10/3/1/4
Size 186/0/13/30/4/7/10/14/3/10/4/14/11/0/3/40/6/1/30/3/11/10/3/5/10/10/2/10/7/1/60/4/3/10/2/1/35/0/4/63/0/2/40/2/11/10/12/1/2
Size 191/11/2/00/3/11/10/6/4/10/3/2/10/2/1/31/7/3/00/5/1/30/2/5/10/2/1/120/4/5/12/0/4/60/3/6/10/5/12/10/5/1/25/2/0/13/7/2/0
Size 200/2/1/30/2/5/13/1/0/80/2/1/41/4/0/20/2/1/120/5/1/36/1/7/00/9/7/10/5/1/180/3/6/10/2/3/18/1/0/20/13/1/30/3/1/22/1/0/8
Size 210/7/8/10/5/7/10/5/1/30/14/1/100/2/1/100/4/1/30/6/1/22/0/8/50/2/1/60/4/1/30/5/1/30/2/4/10/2/3/10/7/2/10/2/5/10/2/11/1
Size 220/6/9/10/11/2/10/2/1/30/5/3/10/3/2/10/7/1/60/4/1/30/2/4/10/6/2/11/5/0/42/8/0/50/2/3/10/2/5/11/0/4/50/4/6/10/3/10/1
Size 230/14/3/10/8/2/10/7/1/20/3/2/11/3/0/60/3/1/141/0/4/70/10/4/14/3/0/14/1/17/00/1/12/30/14/1/30/7/2/10/4/1/20/3/1/80/3/9/1
Size 240/3/1/60/7/1/22/5/0/10/3/1/90/4/1/60/7/1/60/4/1/30/2/1/40/8/1/50/5/1/64/0/1/20/2/5/10/3/2/10/4/1/20/10/4/10/9/1/2
Size 250/11/5/10/2/1/100/12/2/10/14/2/10/4/6/10/4/1/50/10/3/10/9/1/120/6/5/10/2/1/40/4/6/10/3/2/40/4/1/53/0/1/40/5/1/20/6/1/7
Size 260/3/1/50/2/11/10/11/4/10/2/1/50/3/1/70/3/1/150/4/3/10/4/2/50/3/1/90/6/1/30/6/2/10/4/1/80/9/1/20/11/3/10/7/2/10/2/1/6
Size 270/2/4/13/0/2/10/2/1/51/5/7/00/7/2/10/4/3/10/4/2/10/4/1/30/3/1/150/5/3/13/0/10/10/6/1/30/2/3/10/3/1/120/2/8/10/6/1/3
Size 280/2/1/50/3/5/10/12/4/11/4/3/06/1/0/25/0/3/41/0/7/30/3/1/40/5/1/130/2/1/40/3/4/10/3/1/120/1/3/61/3/0/90/3/6/10/4/1/5
Size 290/2/1/120/1/9/41/0/7/20/13/9/10/4/1/80/3/11/10/7/2/10/4/3/10/6/3/10/4/1/20/5/3/10/3/1/120/3/6/10/2/12/10/6/5/10/3/1/2
Size 307/2/4/00/3/6/10/3/1/60/2/3/10/2/6/10/6/1/130/2/3/10/6/1/150/4/12/10/2/1/50/3/1/120/3/6/10/11/3/10/2/4/70/6/4/10/9/5/1
Size 310/4/5/10/2/3/10/7/5/10/4/1/80/2/6/10/2/1/40/2/7/10/5/4/11/0/3/40/5/3/10/5/2/80/1/3/80/3/4/10/6/2/10/3/6/10/3/1/9
Size 320/4/1/80/2/6/10/2/1/60/3/1/150/5/1/20/4/2/50/7/4/20/5/1/20/5/4/10/2/1/90/3/6/10/13/1/30/10/1/60/2/4/10/2/8/10/5/1/3
Size 330/3/1/20/2/1/60/2/3/10/10/4/10/6/1/131/9/3/00/5/1/30/3/5/10/20/1/60/2/1/90/4/6/10/3/4/10/2/5/10/9/3/20/6/1/23/6/10/0
Size 340/3/2/13/0/6/10/3/1/150/4/2/50/5/1/20/4/1/20/5/1/20/2/1/90/20/1/60/2/3/10/13/1/30/5/1/20/10/1/61/8/0/40/2/5/10/3/1/9
Size 350/3/1/150/4/9/10/2/7/10/9/1/20/4/1/20/2/1/50/2/13/10/20/1/60/4/6/10/7/1/60/13/1/50/2/7/10/2/5/10/2/1/70/2/8/12/1/8/0
Size 360/2/7/10/4/1/20/6/2/10/2/1/40/3/1/40/20/1/60/3/1/120/5/2/10/11/1/60/9/1/20/4/6/10/4/3/53/4/2/05/0/6/12/1/0/30/5/1/2
Size 370/2/5/60/6/2/10/4/1/20/2/3/10/3/1/40/5/1/23/1/0/130/11/1/60/2/13/10/2/1/40/3/6/10/7/1/65/0/1/90/5/1/30/4/9/10/5/1/3
Size 380/5/1/30/4/1/30/2/3/10/4/1/70/3/1/40/3/5/10/2/1/90/11/1/50/2/1/40/6/5/10/5/4/10/3/8/12/8/0/30/6/1/50/3/1/90/2/5/1
Size 390/5/1/110/3/1/40/2/3/10/7/4/20/4/1/70/2/9/10/11/1/50/11/1/60/2/13/10/5/1/130/7/1/60/13/1/31/0/3/20/3/11/10/3/4/12/9/1/0
Size 400/3/1/40/5/2/10/4/1/74/0/6/10/11/1/60/2/4/10/4/2/10/11/1/54/1/3/00/2/13/12/1/0/40/3/4/10/8/3/10/3/1/70/9/4/10/6/1/2
 
Last edited:

Unsinkable triremes



Just a quick post about random hacking triremes to be unsinkable: as stated elsewhere, there is 50% chance for a trireme to sink when it is away from coast.

The actual code makes a call to random(2), and if the result is different from 0, checks whether it is next to coast: if not, it sinks.
Conversely, if the random result is 0, then the check above is skipped, and thus the trireme does not sink.

So you just have to follow instructions for the CIV RANDOM HACK - Attack table, and the next random(2) call will return 0, thus your trireme will not sink.
 
i'm playing Early Conquest game on a pangea continent but, being a noob, i can't get the huts to produce as i'd like them to...

so maybe i'll describe what i'm doing so that someone could point out my error. :)

since i'm still in build up mode most / all of my cities are at 1 / 2 population and are producing more settlers to make more cities. it would be great to reliably start new cities far away without having to produce and move them there one square at a time!

goal: produce "Advanced Tribes" on suitable-land-type huts.

so i rename the 1/ 2 attacking city pross / orkenypuszta (from attack table, +0)
then i click in the city to view it
then i "attack" the hut with my chariot.

as i understand it i should get a predictable result every time, and hopefully an Advanced Tribe if the hut is on suitable land type...

but i don NOT. i get mixed results... barbarians / tech / 50 coins.


so what am i doing wrong? :confused::confused:
 
If you get mixed results, then you're not doing it right...

But anyhow let's start at the beginning: what's your version of Civ? (not that it should have any impact, though, just to be sure)

Next, here is how you should proceed, step by step:

Objective: force result of Huts to "Advanced Tribe"
  1. Look at the Huts random hack table in this post: http://forums.civfanatics.com/showpost.php?post=12825192#post12825192
  2. Each cell contains 4 numbers, which are the number of random calls to execute so that the next random call (random(4)) returns 0, 1, 2 or 3
  3. Look at this post then, that describes which random value you need depending on which hut outcome you want: http://forums.civfanatics.com/showthread.php?t=510312
  4. You see that for Advanced Tribe, you need the random(4) to return 0
  5. From the Huts random hack table, you will then be looking at the first of the 4 values from each table cell
  6. Assuming you only have cities with 0 buildings and size 1 or 2, the table tells you you need 1 additional random call after showing city view (size 1) or 0 random call after city view (size 2)

That's for the theory, now here's how to proceed:
  1. Get one of your units (e.g. chariot) right next to a hut you want to visit
  2. Take a note of which direction your unit will need to move to enter the hut (will be useful to perform a "blind move", i.e. moving the unit without seeing it on screen)
  3. Go to your size-1 or size-2 city, properly renamed as explained in the Random attack table; that is pross for size-1 cities, or orkenypuszta for size-2 cities
  4. Open the city screen then display the City View
  5. WARNING: from now on be careful where you click! because each click on the map screen will make the map refresh and trigger 1 additional random call...
  6. Exit the city screen
  7. If you city was size 2, DO NOT CLICK ANYWHERE, but make your unit (e.g. chariot) visit the hut by pressing the arrow in the correct direction (noted at step 2 above)
  8. If your city was size 1, we need 1 more random call before visiting the hut, so typically, press "C" ONLY ONCE to center the view on the chariot (this will refresh the map and thus call random() once), and then visit the hut

If you still cannot achieve your objective with the detailed steps above, then you'll need to provide more details about what you're doing - or why not a video?
 
  • Like
Reactions: GPR
is there a hack to lower the threshold at which the hut will produce an Advanced Tribe?

currently it will only produce an Advanced Tribe if the "map value" is 13 or greater, whatever that is. is there a table for "map value?"

in practice i can only get an Advanced Tribe on shielded-plains (not empty plains) and straight rivers (not river curves... or maybe it's all about the hidden shield which is either there or not...) update: nope, shielded curved river hut will only give me the 50 coins, even with city view. :(

still waiting on my TerraForm Key... not that i would use it overmuch for normal play but there are a few scenarios i'd like to play out... even scenarios it for some reason doesn't supply like a map filled with the "game" special resource. :)

unrelated question: i noticed that i get more food from a city if i irrigate (and possibly railroad) the square before i build it. what is needed for this and what isn't?
 
is there a hack to lower the threshold at which the hut will produce an Advanced Tribe?

currently it will only produce an Advanced Tribe if the "map value" is 13 or greater, whatever that is. is there a table for "map value?"

in practice i can only get an Advanced Tribe on shielded-plains (not empty plains) and straight rivers (not river curves... or maybe it's all about the hidden shield which is either there or not...) update: nope, shielded curved river hut will only give me the 50 coins, even with city view. :(

No table, this is hard-coded in CIV.EXE, but probably easy to patch. I'll have a look later, maybe.

still waiting on my TerraForm Key... not that i would use it overmuch for normal play but there are a few scenarios i'd like to play out... even scenarios it for some reason doesn't supply like a map filled with the "game" special resource. :)

In the meantime, you can take a look at JCivED.

But be advised: "special resources" are controlled with a hard-coded formula in CIV.EXE, you cannot edit them in savegames...
See these threads for more details:


unrelated question: i noticed that i get more food from a city if i irrigate (and possibly railroad) the square before i build it. what is needed for this and what isn't?

If building a city on plains/grassland/river, the square will automatically be irrigated and roaded at the same time.
But CIV 1 has a known bug that Cities cannot be railroaded after their creation - unless the railroad was already there built before the city is built, which is the situation you describe.
Fortunately, a patch exists to "fix" this bug! See here: City square behaviour - patch suggestion
The patch is also available in JCivED.
 
I came back to civ (it will always have a special place in my heart) while waiting for BE to get patched, and this thread has made my day/week/month. As a programmer/software tester, I can easily see how this could make it into the game and remain undetected for so long. But taking the design flaw and turning it into an exploit that you always win your battles still makes me laugh every time I think about it. I applaud your work reverse engineering civ and all the things you've uncovered from it.
 
Really? I've noticed new cities start out with railroads instead of roads after railroad has been researched.
 
But you can't railroad the tiles of any cities founded before the discovery of Railroad. Usually I've founded at least one city prior to discovering Railroad.
 
...
... it seems close to always possible to discover a city (or any other outcome). However, odds seem "locked" when using the save swap trick.

Well, some hut squares are on hills,
i am sure there never was a city given from a hut
in the non-hacked game.
 
Haha.. Awsome info darkpanda.. (Though I'm a latecomer to thread)

Stupid of implementors to screw seed on showing city, but then again, it's not a multi-player game, so it's no big deal really.

Seeing that a roll of 1 always create a tech, I have been looking at how to get specific techs by getting the second roll to roll appropriately on d72. As most of the interesting techs early on have low numbers, it's way too often you get the lowest one.

Basically, you commonly have a size 1 city with no buildings ('cept maybe palace), so given a name for that city, how many refreshes do one have to do to get 1 for tech and then a good d72 roll. Tedious to figure out having to figure out by manually testing though.

Is that java code that reproduce the algorithm something you could share?

Anyhow, I found another strangety. For a city of size 1 with no buildings (possibly 'cept palace), named pross, I seem to get in one of two seeds depending on some other unknown attribute. Either I'm getting a tech after 8 refreshes, or I get one after 7 or 9 refreshes. I'll have a look at the city view and see if I can see anything different in graphics when it happens to explain it.
 
Haha.. Awsome info darkpanda.. (Though I'm a latecomer to thread)

Stupid of implementors to screw seed on showing city, but then again, it's not a multi-player game, so it's no big deal really.

Seeing that a roll of 1 always create a tech, I have been looking at how to get specific techs by getting the second roll to roll appropriately on d72. As most of the interesting techs early on have low numbers, it's way too often you get the lowest one.

Basically, you commonly have a size 1 city with no buildings ('cept maybe palace), so given a name for that city, how many refreshes do one have to do to get 1 for tech and then a good d72 roll. Tedious to figure out having to figure out by manually testing though.

Is that java code that reproduce the algorithm something you could share?

Anyhow, I found another strangety. For a city of size 1 with no buildings (possibly 'cept palace), named pross, I seem to get in one of two seeds depending on some other unknown attribute. Either I'm getting a tech after 8 refreshes, or I get one after 7 or 9 refreshes. I'll have a look at the city view and see if I can see anything different in graphics when it happens to explain it.

There is Java code simulating the random routine of Civ. It is part of JCivED since the latter uses it to generate random maps: https://sourceforge.net/p/jcived/code/HEAD/tree/tags/jcived-0.0.17a/src/dd/civ/logic/CivRandom.java

I did write some separate code to generate the random attack tables, but they are not published with JCivED as far as I remember, I need to check.

Now, re-reading your post, I am not sure I understand what you mean by "refresh" ? On which context are you attempting to obtain a tech ?
 
Following your hut table, one see how to roll a d1 for the hut in order to always gain a tech when one enter a hut. However, after doing that 0-3 random roll for the hut, a 0-72 roll is then made to see what tech you found according to the linked post above with tribal hut outcomes. I'm trying to figure out how to get that 0-72 roll to roll my way.

A detailed example to avoid any confusion: Having a unit ready to enter a hut, entering a size 1 no buildings city named pross, your table says that if you go into city view, press esc twice to get out in map, then hit c or click map 8 times, and then move into hut, you will roll a 1 in the 0-3 random roll and get a tech. From what I observe you will then roll a d72 of somewhere in the range 46-53 (At the time I received tech #53, but I would have done so on any roll in the 46-53 range so I dunno the exact number rolled).

If instead of hitting c or clicking map 8 times (which I called refresh), you do it 10 times, you will also get a tech, but now the random roll is somewhere in the 8-10 range (A specific one, I just don't know exact yet).

Of course, clicking 'c' 412 times to get the 0-72 roll to go your way is impractical, so it would be nice to figure out what one should name the city in order to create a get tech outcome on hut, that rolls a specific number for what tech after. Not really needed to know it for all city sizes and number of buildings. It's easy to have a size 1 city without buildings, so if that works, that is enough for me.

I figured that if you had some simulation code you used to generate the table of city names, and see how many times you had to roll to get a 1 result when entering a hut, that maybe it could be extended to check what d72 roll will be made for tech afterwards.
 
As to the two separate results I get for the same city sizes/buildings, it seems like they are likely just skewed one roll.

My current theory is that sometimes rand() is called when moving cavalry into hexes that are expensive to move into, and that explains why I have to refresh screen one time less sometimes. I'll try to verify when I take further huts if it's only happens then moving into expensive tiles.

Optimizing a bit for what tech I get from huts, in my emperor game here, I invented RailRoads in 3020 BC, and at that time I'm a Democracy that recently built J.S. Bach cathedral. Probably my best start so far at least.. Though mangling with the random number generator would be called cheating by most, it's interesting to see what's possible if one were incredibly lucky :)
 
This also works to control where a civ starts when you destroy another. The invasion screen when you invade their last city, resets random seed to show the city screen with given name, so it will be the same each time you try it. But when you get into the city screen you can alter the name and enter city view. When you leave the city screen and get a report the civ is destroyed, the new civ will be placed based on the seed you just created.

Have tried out quite a few different names to see if I could control it, but the same locations seem to repeat. Either, only a dozen or so tiles are likely targets, or it's an effect like techs, that you are likely to pick an invalid tile, and there is some procedure to move to closest legal one or something, where lots of tiles map to a small set of closest legal tiles. Extra tedious to check though, as you don't see on the map where they reappear.
 
This also works to control where a civ starts when you destroy another. The invasion screen when you invade their last city, resets random seed to show the city screen with given name, so it will be the same each time you try it. But when you get into the city screen you can alter the name and enter city view. When you leave the city screen and get a report the civ is destroyed, the new civ will be placed based on the seed you just created.

Hmmm, there are more powerful forces at work than rand() calls in this process. It is possible to take complete control of respawns with reliability, without re-seeding the rand function. Suitability and date matter more. But you are correct, i saw that rand() does play a role. What it looks like, from the luser POV, is that if you allow a variance then a variance can occur. But it is a pittance of effort to eliminate variants.
 
Top Bottom