Friday, November 9, 2012

Battle Simulator v0.0.2

Ok so it seems that there are issues getting the tool to work in Internet Explorer as a overlay in the game window, so for now I am releasing an update, (New Bear and Lion units) version of the tool  that is part of this page only. Fell free to dissect the code if you want.

29 comments:

  1. Replies
    1. I haven't touched this in a while since I didn't get much interest from my alliance members and most of them were fairly good at doing the math them selves, but the tool was shown to be fairly accurate for normal battles. It's biggest three biggest weakness are that to get a good simulation you need to know what the enemy has, and that it don't works for one flank at a time. As for equations that powered the tool there really wasn't so much an equation but more of a lookup table that contained all of a units stats and properties, such as if it could attack/defend and if it was ranged or melee.

      The tool calculated the ratio of melee to ranged attackers and the attackers combined attack power. The tool then calculates the raw melee and ranged defense ratings. The raw defense ratings are then multiplied by the defender bonuses which would be changed by tools. Then the ranged and melee defense ratings are multiplied by the attack type ratios, and the resulting numbers are added together. The final defense rating is then calculated by multiplying by the courtyard/accuracy bonus. (which is a little wonky in that it goes from -30% to plus 30% instead of from 100% up like the other fields.)

      Now that you have attack and defense ratings you can get a rough idea of what % of troops will be lost. If memory serves it is a quadradic equation that tells the percentage of lost troops and when you have an 8x attack/defense rating you will not take any losses. It has been a while since I last touched this so they could have changed a few things.

      -JLBShecky

      Delete
  2. I have no idea what you mean by Courtyard/Accuracy Bonus:

    and you don't have Armed Citizens in the list

    Can you make it calculate individual troop type losses on each front of the castle to make up a better configuration?

    ReplyDelete
  3. what if the attacker uses tools?
    what if the defender uses a moat?
    what if (and they must have) armed citizens?
    what if there is equipment (this could be tricky as there are so many different types and the technicus makes that even harder)?

    ReplyDelete
    Replies
    1. u need to calculate them through defence of tools% attack of tools% and commander increasment and u should write the final result in the defence of wall gat n keep

      Delete
  4. I'm writing a calculator of my own, using your method and I got as far as getting matching attack and defense ratings. However, I don't know how you calculated the percentage of troops lost. Could you go over that? Thanks,

    ReplyDelete
    Replies
    1. Well It has been a long time since I last touched Empire, but when I wrote this tool fro my alliance, and I deiced to share my findings. Things may have changed a bit since then but the same basic principle that I used to get my simulator up and running should work for you. At the time that I wrote the tool the basic equation for calculating what percent of troops would be lost in any wave, was calculated by comparing the ratio of attack verses defense power.

      Once you have the ratio of attack power versers the defense power I ran that through a quardradic equation that I got using a line fitting test and limited the results to between 0 and 100%. With I did my testing the equation that I used was "losses = (0.5556 * x * x) - (17.222 * x) + 116.67". For attacker losses x = attackpower/defensepower, and for attackers it is defense it is the inverse (x = defensepower/attackpower).

      Delete
  5. thanks its working please can you tell me how ican calculate tools in this tool

    ReplyDelete
  6. Hi JLBShecky, would you care to give me the calculations behind your program, Im working on something similar and I like to see the ways the losses etc are calculated.
    Thanks,
    W.

    ReplyDelete
    Replies
    1. If you just take a moment and view the source (usually this can be done just by right clicking and bringing up the context menu, and then selecting "view source"), you can see everything that I did in the tool. for the most part I have described everything they I did in the tool in the comments via past replies.

      -JLBShecky

      Delete
    2. Hi there, and thanks for the great tool!

      Just wondering: how did you came to the formula which calculates unit losses? Do yout think is it random, which of the attacking units will die, if let's say 70% survived?

      Delete
    3. As I have said in past replies, losses are directly tied to the ratio of offensive power verses defensive power. Unless game mechanics have changed since I last played the general rule is if you have 8x-10x the attack power then you should lose nothing. The thing to remember though is that as the attacker you have to split yor attack into 4 waves, so not Al your troops can fight agaunst the defenders, so against really entrenched defenders, the best that you might be able to do is any wave is double the attack power, in which case you would lose something on the order of 50 to 90% of the troops in that wave,but destroy allthe defenders. There is a little more math to it, but that is the general idea. As for how I came up with the equation, well I started by using data that someone else on the forums had put together showing what units to send against npc camps/towers, and then compiled a number of battle reports to fill in the missing data. Defenders do ge a small random defense bonus, but if you do it right then you should tAke no or minimal losses.
      -JLBShecky

      Delete
  7. You have a wonderful, unique, and fairly accurate calculator here, JLBShecky. I can't find another one like yours on the internet. It's exactly what a lot of people are looking for, and the only disappointment is that it doesn't have all the units, like the Wolfhounds and the Barbarians, which you can get from everwinter glacier village level 3. I know you haven't played in a long time but many people like me still do (I'm an active level 45) and this is outdated. Please update it for the people who are playing the game but lazy to do math.

    ReplyDelete
    Replies
    1. Oh, and also in thorn king and blade coast, morale bonuses/penalties. I'm a programmer and I understand how annoying, slow, and painful the process of creating a program can be, but for the players, please.

      Delete
    2. Thanks for the comments, there are actually two big things that are plaguing the tool as it stands: firstly is is way out of date due to my not having played Empires in close to a year now; secondly when I was last playing I stopped shortly after the first lions verses bears war, and during the battle I saw a number of issues with the simulator in relations to the moral bonuses/penalties.

      I based the tool on my experiences with similar tools from Travian and the original Imperion Beta, granted the last time that I played either of them the had by that time already had their own in game battle simulators. The one non programming issue in the tool is the human factor, in that if a player reinforces a castle, outpost, etc. then if you don't account for that possibility then you will most definitely lose. All that being said updating this tool, assuming that that they didn't make any changes to the actual underlying mechanics of how battle calculation work would be rather simple.

      The tool was for the most part just something that I hacked together when I wanted to test out a few things to try and help some of the younger players in my alliance plan things out, and if you want you could freely take the source code and update it with the new units, it uses a json lookup table/array with the stats of the units, (just view the webpage source and search for
      "Skeleton bowman":{stats:[92,51,125,20,0,0],ranged:true,attack:false,defend:true}
      ).

      Just add new lines to that with the units stats, and assuming that nothing has changed the tool should work with the new units. As for the moral bonuses I ran into issues with that and was not able to get enough reports to validate any findings, being on the losing side of the lions and bears didn't give me much change to work out just how things went as the heavier spenders were hitting us to hard and fast to be able to mount sustained defenses, much less successful aggressions.

      Delete
    3. Alright, thanks! I'll try to create a more updated version and post it myself if you don't mind? I'll give you credit for the original source code. I'm not too good with JavaScript but I'm familiar with it so I'll give it a shot.

      Delete
    4. Lol I just looked at the code and it said
      "Lion bowman":{stats:[98,54,129,26,25,4], ranged:false,attack:true,defend:true},

      Ranged false? XD

      Delete
    5. Well I guess that would go as a firm oops, and might has accounted for part of the reason that I was getting slightly off results during the original event.

      Delete
    6. This comment has been removed by the author.

      Delete
    7. It is giving me a "Uncaught TypeError: Cannot call method 'appendChild' of null" on the line where it says "table.appendChild('row');"
      I copied and pasted directly from view source on this page. What is wrong? When I tried in Notepad++ it said Syntax Error, now directly on chrome it says "Uncaught TypeError: Cannot call method 'appendChild' of null".

      Maybe we should set up somewhere else where we can talk about this.

      Delete
    8. Darren-

      We could probably move this to GTalk/Hangouts if you wanted to do such.

      That being said you wouldn't happen to have the following html code on your test page:

      <table id="tutorialTable"></table>

      Line 1214 of the blogger source (line 203 of the origional script itself) searches the page for an html element with an id of "tutorialTable", and then uses the adds the results to it. If there is not a table with said id, then "document.getElementById('tutorialTable')" will return null and the table variable will be set to null.

      Coming from how a typed language how javascript handles it variables/objects can be a little off the wall, but it has it's uses.

      -JLBShecky

      Delete
    9. OK, Now I'm getting a different uncaught error after I added the table with id "tutorialTable". Let's move this to hangouts before your post is flooded with back and forth discussion. I'm darrenyipthecatgod@gmail.com

      Delete
  8. This comment has been removed by the author.

    ReplyDelete
  9. this is a wonderful simulator and i developed one and went down the same line except when i built it i noticed that the melee and ranged defenders and warriors have both melee and ranged stats. therefore attacker power and defender bonus must have 2 different powers. with 2 different attacking stats it is incredibly difficult to calculate the death ratio.

    ReplyDelete
  10. JLP,

    try to bring up commdor sthrngth like typing ..

    kindly

    ReplyDelete