2 Attachment(s)
Advanced Army Build Window (With Pictures and Working Code Example)
Hello, long time player, first time poster.
I am a fellow game developer and I have been playing CoC for quite some time, and I have been thinking of a suggestion to help easily manage the building of an entire army.
A lot of users, whether they are prepping for war or are about to head out and raid villages, generally have a specific composition of troops they like to utilize. Whether you are using GoWiPe or barch, trying to evenly manage your barracks to optimize build time can be quite frustrating, especially with the more complex troop compositions.
The idea I am proposing is a 2 part feature request. The first being a new build interface, the 2nd being the algorithm to evenly distribute that build into the player's barracks. I will go over these in detail!
Although I am a game programmer, I am not that great with graphic design so bear with me :)
New Advanced Build Interface
Let me start off by saying that this is NOT a replacement for the current barrack build interfaces that exist to queue troops into individual barracks, but rather a new alternative interface to manage all barracks (Dark and Normal)
A new button on the current UI could be created that would open up this new interface. Here is a crude example of what the interface could look like (again I am no graphic designer)
Attachment 115081
Now this can be designed to be a scroll-able window or in any other format, this was just the easiest to show an example of this feature. You can see the title at the top says "0/300". Obviously this works similar to the current barrack build interfaces, except the latter number is the combined total of all available barracks. So if one barrack is under construction, this number would reflect that change. In this example, 4 maxed out barracks each with a queue limit of 75 == 300 total available queue slots.
Attachment 115082
In this image you can see a basic GoWiPe setup being queued up and ready for building. The numbers in the title bar reflect the current build capacity and queued troop count. Using the + or - buttons on each troop, a player can adjust the numbers desired
NOTE: Building would not start until the Build button is hit, so adjusting the numbers on this interface would not change the state of the current barracks.
Hitting the Button, and the Algorithm
This is where the tricky and technical part comes in. The idea I have for what actually happens when the build button is hit flows as follows:
- Clear the current barracks of anything currently in their queue
- Refund resources
- Maybe prompt user about the current queue being cleared
- Create a list of data structures representing the desired army composition based on user input
- Sort that list from higher troop training times troops to lower troop training times
- Obtain a list of active barracks
- Execute queuing algorithm to fill the barracks with the troop composition, optimized for even time distribution among all barracks
Here is a functional c++ program showing the algorithm. Obviously assumptions are made about the makeup of your data, so it would definitely have to be adapted. But here is the simplified version of the code:
NOTE: This only shows normal elixir troops and normal barracks, not dark - Dark barracks will work the exact same way, but it would be it's own algorithm, lists and barracks since they are completely separate. So there was no point to show both since it's the same thing.
http://ideone.com/mYvRk5
For those unfamiliar with code or ideone, to test this out do the following:
- Click the "Fork" button on the top left to modify the code in your own copy of the program
- Scroll down until you see the function "ExampleSetup" (Line 155)
- You can modify lines by commenting them out by starting the line with // or modifying the values
- The number '75' on line 158 represents the capacity of that barrack
- The number '20' on line 163 represents the desired number of that particular troop
- You will also see on line 163 TYPE_ARCHER - meaning this is the archer type. You can mix and match these any way you'd like, and the algorithm should still work.
- The list of types start on line 9
- the "push_back" part means we are adding a new entry to the list.
Once you've made the modifications desired, hit the "Run" button in green. This will compile and run the algorithm. You will see text output of the results below. You can re-edit the code to try something new, then hit the "ideone It!" button to re-run it without creating a new version.
The algorithm starts on line 210, here is what it's doing
- Lines 210 thru 213 are sorting the Army Composition List in order from longest training time per troop, to lowest training time per troop.
- This has nothing to do with the quantity desired, this sorts the list to make sure Golems (45m training time per) are ahead of Dragons (30m training time per), and Dragons are ahead of Archers(25s time)
- Pre-sorting this list sets up for an optimal queue distribution which happens later in the algorithm
- Line 216 starts the loop of the Army Composition List
- We always look at the first entry of that list (which was sorted to be the longest training troop)
- We continue this loop until all troops desired by the player are queued in barracks
- Lines 219 thru 235 finds a Barrack with the lowest queued training time that also has the capacity for the troop we are currently looking at.
- Lines 238 thru 242 is a safety check. This condition should never be true. If it is, then something went horribly wrong (queued troops over capacity, etc)
- Lines 245 thru 246 queue one of those troops into the barrack
- Lines 249 thru 252 will remove the troop from the primary list once all quantity has been distributed
And that's the algorithm! I tried many, many different test cases and it worked each time, evenly distributing the army to give the most optimal time among all the barracks.
I welcome any feedback or suggestions to make this better. Or if you found a bug then let me know!