View Full Version : town capture simulator


Offa
Nov 11, 2004, 05:24 PM
For a long time now I have wanted to know the attacking force needed to capture a town. For example how likely are 6 horsemen to take a town defended by 3 spears on a hill. Individual combat calculators help you to get an idea about this but don't really give the answer. Sirp has written a programme which calculates this, but on my computer his utility crashes if asked to evaluate attacks involving many units.

This is a little Java program that simulates trying to take a town. It seems fiendishly tricky to me to calculate the true chance of taking a town but it is reasonably easy to simulate lots of attempts and work out the chances that way.

The program lets you specify the attackers and the defenders, and then simulates lots of attempts to take the town. It allows for retreats according to the formula by BomberEscort, and for those irritating defender promotions. I haven't attempted to allow for bombardment, armies or for units that can attack more than once in a turn. The current defender is selected according to the product of power and remaining hit points as I am not sure how the game does this.

Latest version:

28 dec 04 version (http://www.civfanatics.net/uploads8/combat1.zip)

Cyber Dreyk
Nov 11, 2004, 08:45 PM
It's a very interesting, thank you! :D
But how I can start your utility without installed java on my PC? :(

ainwood
Nov 11, 2004, 10:24 PM
Sounds promising - but is a .jar file a java archive? Do we need to uncompress it first? :confused:

Offa
Nov 12, 2004, 01:29 AM
It is a zipped jar file. The server won't let me upload a jar file, so I had to zip it first. I don't think you need to do anyting special to run a jar file, just double click: at least that works on my machine.

Here is a screenshot. It is a tad garish, but I could tone it down:

http://www.civfanatics.net/uploads8/combat.jpg

Gramphos
Nov 12, 2004, 03:02 AM
You will have to install JRE (some version) to be able to run java files.

jar files are run with java -jar filename.jar normally an association is setup on install

Offa
Nov 12, 2004, 05:25 PM
I guess I have installed lots of java stuff on my computer so that explains why I can run executable jars with a double click. I only now see that it opens with javaw, whatever that is. I had assumed executable jars would open on most computers: so much for portability. Anyway it runs just great on my machine :p .

Frankly I only tinker with programs as a bit of fun, it's just a game for me, like playing civ really. Therefore I am a bit ignorant :blush: . If I knew how to I would convert the program to an applet. I suspect that this is easy but I don't know how to do it :crazyeye: .

Having said all that, I think this will run from windows Internet Explorer, or is that just my machine as well?

socralynnek
Nov 15, 2004, 04:44 AM
Hey, interesting tool and good work.

2 proposals:
1.One button where only the results are cleared (so I can just add an attacker without having to enter them all again)
2. Adding a third and fourth row, one for attacking bombardment units, one for defending ones.

Offa
Nov 15, 2004, 11:46 AM
Hey, interesting tool and good work.

2 proposals:
1.One button where only the results are cleared (so I can just add an attacker without having to enter them all again)
2. Adding a third and fourth row, one for attacking bombardment units, one for defending ones.

Thanks:
Your first idea is easily done. I agree that re-entering all the units is a drag. It would be pretty easy to have buttons to remove the last unit entered too but might make the interface a bit cluttered. I am also going to increase the allowed limits on the number of simulations as it was running very fast on my machine, 100000 simulations takes a few seconds.

Re the second proposal, adding buttons for bombardment is of course pretty easy, but accurately simulating it not quite so easy. At the moment I don't know how bombardment works. It would complicate the simulation a fair bit but I might try it at some point.

Similarly attackers which can attack several times a turn (eg armies, tanks) would be interesting to simulate, if potentially a little complicated: eg how do you work out whether or not to use the second attack and at what point of the battle do you use it.

More stats about the results would also be possible, if wanted.

Offa
Nov 15, 2004, 12:02 PM
Here it is with a clear results button:

http://www.civfanatics.net/uploads8/combat.gif


revised combat simulator (http://www.civfanatics.net/uploads8/combat.zip)

Offa
Dec 06, 2004, 04:20 PM
Ok I know that no one is reading but I find my calculator very useful so I have buffed it up more. I haven't added bombardment as I can't think of a sensible way in which to implement it that would really simulate what a player does, ie in a real game a player would potentially bombard for several turns to kill more population etc. I haven't added blitz either as it plays little or no role in games I play.

here is an example simulating an attack with vet horsemen on a hill town defended by 2 fortified spears.

http://www.civfanatics.net/uploads8/calculator.GIF

new calculator (http://www.civfanatics.net/uploads8/combat_simulator1.zip)

I think all that needs to be done is unzip the programme which is an executable jar. If there is no java on the computer I think it can be run from IE, but if there is a double click will work. Anyone who wants can have the source.

Ambiorix
Dec 19, 2004, 02:37 PM
Installing Java (http://www.java.com/en/download/installed.jsp) worked best for me.
Offa, this tool looks really useful, and I'll sure use it in the next COTM, but I'd be very very grateful if you could tone down the colors a bit. :twitch: ;)

Offa
Dec 20, 2004, 03:24 AM
Yes it is pretty garish isn't it. I put colours in so I could see what was going on easily, and really should have some subtle shades instaed of these rather violent default colours.

I will tone it down or just make it all grey.

MSTK
Dec 20, 2004, 12:10 PM
This is a great an useful tool :)

However, I always have a 50-100 stack of artillery on hand...
How about adding the option, "Fully Bombarded"? So, it sets all of teh defender's HP to 1.

Offa
Dec 20, 2004, 01:09 PM
I did think about putting in bombardment but it would be hard to model what you would do in practice. For example if your first go at bombardment reduced city size to 7, you probably wouldn't attack but would try to bombard again next turn to reduce city size to 6. In addition, I hardly ever use bombardment myself. I guess armies would be nice too but are actually slightly tricky to implement for much the same reason: eg when down to 2hp should it attack? I guess I could make them attack if they figured their chance of winning was say >80%, but it is quite cumbersome to do.

You can just put the defenders down as having 1HP. You can prevent them from promoting by making them elite, otherwise promotions will potentially make life much harder for your attackers. Another effect of bombardment is reduction in population, which can of course also be calculated.

Dom Pedro II
Dec 20, 2004, 02:53 PM
50 to 100 artillery???!! I usually have 50 to 100 units! :lol:

Anyway, this is really cool since military commanders have access to this kind of information in real life. So it's not like cheating... I don't think so anyway.

MSTK
Dec 20, 2004, 03:30 PM
50 to 100 artillery???!! I usually have 50 to 100 units! :lol:

Anyway, this is really cool since military commanders have access to this kind of information in real life. So it's not like cheating... I don't think so anyway.

No, it is never considered cheating to know your odds :)

Offa
Dec 21, 2004, 02:09 PM
OK, here it is in pastels. Actually I think it looks anaemic and my wife says it looks military.

I added a fully bombarded button as well: this sets all the defenders to 1HP elite units (I made them elite to stop them promoting).

I fixed an error :blush: as well, which was nice of no-one to mention. Retreat chances now work properly.

http://www.civfanatics.net/uploads8/combat_pastel.GIF

pastel combat sim (http://www.civfanatics.net/uploads8/combat_simulator2.zip)

Mistfit
Dec 21, 2004, 02:13 PM
IMHO the colors are much nicer now. Neat utility BTW.

which was nice of no-one to mention
My problem was the fact that I'm not intelligent enough to notice the problem:D

Ambiorix
Dec 21, 2004, 02:38 PM
Thanks Offa !
This is the best anaemic military tool I've ever seen ! :D

Spart
Dec 23, 2004, 05:41 PM
Great little tool, hopefully you will fill it full of options!

MSTK
Dec 23, 2004, 06:54 PM
Wait a sec...does this consider the option of promotions? Because a unit you've attacked until 1 HP with one unit may emerge with 2 HP later...

Offa
Dec 24, 2004, 01:36 AM
Wait a sec...does this consider the option of promotions? Because a unit you've attacked until 1 HP with one unit may emerge with 2 HP later...

Yes it does. That is one of the reasons you are asked the experience level of defenders (conscript to elite) and the only reason why you are asked whether the defender is from a militaristic civ: both of these factors affect promotion chances.

I don't consider attacker promotions as at the moment I don't simulate blitz attacks and therefore these promotions, although nice, have no impact on taking the town.

Offa
Dec 28, 2004, 02:35 AM
I just noticed that if an attacker starts with 1 HP ( as opposed to falls to 1 HP during the attack) the programme gives him a chance to retreat. I have fixed this now.

new version (http://www.civfanatics.net/uploads8/combat1.zip)

This doesn't make any difference (hopefully) unless you wish to simulate attacks with 1 hp fast attackers, in practice not a common event.

Tať Shala
Jan 02, 2005, 08:41 AM
Very cool. :goodjob:

Will you add a blitz option?

Offa
Jan 06, 2005, 01:19 PM
I may have a go adding blitz, but it isn't entirely straightforward. I'm currently not quite sure how blitz works. I think armies have considerably modified attack strength as well and that would also need to be allowed for. In addition it is a little problematic to work out when or if to attack for a second time with an injured blitz unit.

Offa
Jan 07, 2005, 04:31 PM
I have taken a bit more time out from actually playing civ to tweak this a little more, adding blitz attack.

blitz version (http://www.civfanatics.net/uploads8/blitz_combat.zip)

The way attacks work in this simulation is that attackers are put on an arrayList in the order in which they are added, and then this list is iterated through, attacking the the strongest remaining defender ( calculated as HP x Power) until all the defenders are dead. I have changed this now so that attackers with blitz can keep attacking until they have used up their blitz lives. It was pretty simple to implement this, although getting the graphs and stats to still add up was more of a headache (I hope it works). The tweaks stuffed up the graphs a lot at first but seem OK now. Please tell me if it doesn't work.

Anyway the thing is blitz attackers will carry on attacking as long as they can. Therefore if an attacker who started with 15 HP goes all the way down to 1HP in the first attack, it will still try to attack again. I don't really like this, as I suspect that nobody really plays like that. It would be simple to institute a rule for blitz attackers only to attack if they have xHP left, and I think this would be better. If anyone has any suggestions I will consider them.

For myself, I hardly ever have any blitz units, so the exercise is a tad academic. Still fun though.

ionimplant
Apr 14, 2005, 07:27 AM
great work, Offa! if you want more people to use it, just put it in your signature as a link.

ControlFreak
Apr 14, 2005, 09:13 PM
Anyway the thing is blitz attackers will carry on attacking as long as they can. Therefore if an attacker who started with 15 HP goes all the way down to 1HP in the first attack, it will still try to attack again. I don't really like this, as I suspect that nobody really plays like that. It would be simple to institute a rule for blitz attackers only to attack if they have xHP left, and I think this would be better. If anyone has any suggestions I will consider them.
If I understand you question correctly, you are trying to program your simulator to determine when to attack with the remaining units. Depending on how you've set this up (I'm not a Java programmer), you could break up blitz units in several different "simulated" units based on the number of attacks allowed. Give them all the total HP for the blitz unit. After the first blitz unit attack, readjust the remaining units to the left over hitpoints and stick them back in the stack of eligible attackers. Repeat until all blitz attacks are used up. Most real players would not attack with a 1HP army if there are other, healthy units, but they might attack with it as the last attacker if they were desperate to take the city. The resulting percentage of taking the city would given them an indication of how desparate they are willing to be to attack with their 1HP army at the end of the turn.

If I'm way off base, sorry. And sorry for digging up the thread, but I just found it thanks to recent references from GOTM.

Offa
Apr 15, 2005, 02:36 PM
If I understand you question correctly, you are trying to program your simulator to determine when to attack with the remaining units. Depending on how you've set this up (I'm not a Java programmer), you could break up blitz units in several different "simulated" units based on the number of attacks allowed. Give them all the total HP for the blitz unit. After the first blitz unit attack, readjust the remaining units to the left over hitpoints and stick them back in the stack of eligible attackers. Repeat until all blitz attacks are used up. Most real players would not attack with a 1HP army if there are other, healthy units, but they might attack with it as the last attacker if they were desperate to take the city. The resulting percentage of taking the city would given them an indication of how desparate they are willing to be to attack with their 1HP army at the end of the turn.

If I'm way off base, sorry. And sorry for digging up the thread, but I just found it thanks to recent references from GOTM.

Thanks for your interest ControlFreak. Blitz attackers are presently represented by a Unit object. This could be broken up but I am reluctant to do so as it could be messy. I think I could change things to order attackers to attack in order of strength, which would kindof have the result you are after. Even this isn't entirely simple as at present the algorithm just has to iterate once through the list of attackersto realize the attack is over, and this would be a bit more complicated. At present defenders are reordered to keep the strongest remaining on top (as in the game) but attackers are used in the order they are added (which allows you to see which is the best order of attack). I might have a play with this again though, as frankly it is almost as much fun as playing civ for real.


If anyone fancies it, here is the code as a text file.

Tubby Rower
Aug 24, 2005, 01:01 PM
Really nice Offa!! I appreciate your work on this.

You knew there was a question coming.....Is there a way to add a remove unit button? For instance, if I add 6 defenders and should have only added 5. I'd like to remove it without doing it all over again. But it would probably take you longer to code it than it would for the time that it would take me to click clear, and add them back again. So nevermind.... :D

Offa
Aug 30, 2005, 05:38 PM
Is there a way to add a remove unit button? For instance, if I add 6 defenders and should have only added 5. I'd like to remove it without doing it all over again. But it would probably take you longer to code it than it would for the time that it would take me to click clear, and add them back again. So nevermind.... :D

Ask, and you shall receive :) .

blitz combat with remove buttons (http://www.civfanatics.net/uploads10/new_combat.zip)

Tubby Rower
Aug 31, 2005, 06:00 AM
Thanks a heap Offa!!

morchuflex
Sep 03, 2005, 06:00 AM
Hello.

This program seems great but I can't get it to work on my PC (WinXP sp1). I have installed the latest JRE but when I double-click the .jar file, I only get a blank page and my computer starts to crawl... Any help?
The funny thing is, I once used an older version of the simulator on a Win98 computer, and it worked perfectly. I miss it!

Offa
Sep 03, 2005, 08:13 AM
morchuflex, I wish I could help. It does work on my machine with XP(2002 home, service Pack 2). Presumably it has something to do with your Java installation, a dark art to me.

I can only hope that someone more expert in Java can help you.

General_W
May 27, 2008, 03:18 PM
ok - so I'm bumping a really old thread here, but I was just introduced to this wonderful tool by Chamnix, and I wanted to say "thank you!"

Worked great on my PC, and is really helpful. Thanks for you hard work on this Offa!
:salute:

ddanon90
Dec 16, 2008, 05:53 PM
nice tool homie, can you run it at the same time as civ 3?

Offa
Apr 25, 2009, 04:06 PM
I rejigged this nearly 3 years ago, but never got around to uploading the new version.
It is really just the same as the old version but it has a save option. If you use this you can save results, which should open nicely in Word or Excel etc.

The file has been renamed with a .txt extension so that I could upload it (I don't seem to have any zipping programmes left on my PC). Therefore it needs to be renamed with a .jar extension to work (right click it to save target as "combat.jar", type of file: all files).