**Now running final 10 games**
Introduction
=
The game takes is strongly inspired by [Manu's Game of Town](http://codegolf.stackexchange.com/questions/44491/the-game-of-towns/44531). It takes place in a world of swords and magic. The king who ruled the whole continent just died, and the lords of the many city-states are now fighting over territory. You are one of these lords and your goal is to conquer and rule every single town.

Principle
=
People are divided into **8 classes** :

    Warlocks : Fighter (magic)
    Crusaders : Fighter (melee)
    Amazons : Fighter (range)
    Corsairs : Utility (steal, guard, transport)
    Bishops : Utility (convert, exorcize)
    Necromancers : Utility (resurrect)
    Architects : Utility (build)
    Peons : Resource (income, recruits)

When the game begins, you rule over one town. In each town, there are **100 people**. You have to split them up between those 8 categories.

Then the actual game begins, which is turn-based. A turn consists of **12 phases**, 7 of which are interactive (asking bots for a command). Next phase begins when previous phase has been executed by every town (Phase 1 : Town 1, Town 2, Town 3... ; Phase 2 : Town 1, Town 2, Town 3...) : 

    1. Raise Taxes 								- AUTOMATED 
    2. Steal Money								- INTERACTIVE
    3. Recruit Troops							- INTERACTIVE
    4. Pay Wages								- AUTOMATED
    5. Try Revolt								- AUTOMATED
    6. Convert Soldiers							- INTERACTIVE
    7. Attack Town								- INTERACTIVE
    8. Raise Corpses							- INTERACTIVE
    9. Move Army or Tribute						- INTERACTIVE
    10. Defend against Threats					- AUTOMATED
    11. Construct Buildings						- INTERACTIVE
    12. Make Children							- AUTOMATED

The controller provides you with input via command arguments, your program has to output via stdout. 

Syntax
=
**Output (preparation)**  
Before the game starts, the controller invokes you submission without arguments. This means you have to distribute your 100 people into into the 8 categories. 

You need to output :
`Warlocks Crusaders Amazons Corsairs Bishops Necromancers Architects Peons`

For example : `15 10 12 10 7 5 1 40`.

Each town also starts with 500 gold and 5 corpses.

**Input**  
Each time your program is called, it will receive arguments in this format : `Round;Phase;YourPlayerId;YourTownId;PlayerId_TownId_Gold_Corpses_Warlocks_Crusaders_Amazons_Corsairs_Bishops_Necromances_Architects_Peons_Temples_Barracks_Estates_Palaces;PlayerId_TownId_Gold_Corpses_Warlocks_Crusaders_Amazons_Corsairs_Bishops_Necromances_Architects_Peons_Temples_Barracks_Estates_Palaces;...`

**Example input**
`1;2;1;1;0_0_600_5_15_10_12_10_7_5_1_40_0_0_0_0;1_1_700_5_15_10_12_10_7_5_1_40_0_1_0_2;...`

Here, you see it is the 1st round, 2nd phase, you are player 1 in town 1. You have 700 gold, 5 corpses, 15 warlocks, 10 crusaders, 12 amazons, 10 corsairs, 7 bishops, 5 necromancers, 1 architect, 40 peons, 0 temples, 1 barracks, 0 estates and 2 palaces.

**Output**

See gameplay.

Gameplay
=

**All phases**

*Command* `W` = WAIT

*Invalid command* = WAIT

**Phase 1 : Raise Taxes**

Income is generated according to your population and your completed buildings :

    +5 gold * Peons
    +2 gold * (Warlocks + Bishops + Necromancers) * TEMPLES
    +2 gold * (Crusaders + Amazons) * BARRACKS
    +2 gold * (Corsairs + Peons) * ESTATES
    +10 gold * PALACES

**Phase 2 : Steal Money**

During this phase, you can steal money from one town by sending Corsairs. Each Corsair can steal up to **10 gold** (i.e. 12 Corsairs can steal up to 120 gold). If the target town doesn't have enough gold, your corsairs will steal everything, up to the maximum debt amount : **200 gold**. If you try to send more Corsairs than you own, the program will use all your available Corsairs.

*Command syntax* : `S DestinationId Corsairs`

**Phase 3 : Recruit Troops**

Here you can train your peons by spending some gold. You can recruit as much units as you want, as long as you have enough peons and gold available. If you try to recruit more than you actually can, the game will recruit randomly till everything has been spent. The program respects your maximum quotas (if you try to recruits 10 crusaders and 5 amazons with only 8 peons, it will for example recruit 6 crusaders and 2 amazons, and not 8 amazons or 8 warlocks).

    Warlock : 		10 gold
	Crusader :		10 gold
	Amazon :		10 gold
	Corsair :		12 gold 
	Bishop : 		20 gold
	Necromancer :	20 gold
	Architect :		15 gold
	

*Command syntax* : `R Warlocks Crusaders Amazons Corsairs Bishops Necromancers Architects`

**Phase 4 : Pay Wages**

Salaries are debited according to your population : 

    -1 gold * (Warlock + Crusaders + Amazons)
    -2 gold * (Corsairs + Bishops + Necromancers + Architects)

**Phase 5 : Try Revolt**

If your balance is negative, you loose the control of your town to the **Outlaws**. After a revolt, the gold of the town is resetted to start value : **500 gold**. The population is maintained at its current levels.

**Phase 6 : Convert Soldiers**

Each of your Bishops can convert 1 enemy soldier (Warlock, Crusader or Amazon) from a choosen Town for a fee of 50 gold per unit. The converted units join the forces stationned in your town. As with the recruitment, if you don't have enough gold or bishops available, the program will convert randomly while respecting the quotas.

*Command syntax* : `C DestinationId Warlocks Crusaders Amazons`

**Phase 7 : Attack Town**

You can send an army of Warlocks, Crusaders and Amazons to conquer a Town. If you try to send more than you have, the program will send everyone.

The soldiers have a **1.5 fighting bonus** following this pattern : `Mage > Range > Melee > Mage` (ie. A Warlock fighting an Amazon gains 1.5 power). Only the units in excess get this bonus (ie. A Warlock fighting a Warlock and an Amazon doesn't get this bonus). The bonus is attributed to both offense and defense.

Losses are distributed randomly between the units of the victor according to looser total power (ie. Offense power: 12 vs. Defense power: 14, Defense wins and looses 12 units). The looser looses all his units. Every dead unit is added to the corpses count of the town attacked.
If the offense wins, the town is captured and is now owned by the attacker. He also keeps the gold, corpses and peons that were in this town. Corsairs, Bishops, Necromancers and Architects flee in front of potential oppression.

The defense gets nothing.

*Command syntax* : `A DestinationId Warlocks Crusaders Amazons`

**Phase 8 : Raise Corpses**

Each of your necromancers can resurrect up to 5 peons by consuming corpses and spending gold. Each resurrected Peons cost 1 corpse and 20 gold. If you try to resurrect more than you can, the program will spend everything you have.

*Command syntax* : `R Corpses`

**Phase 9 : Move Army or Tribute**

You can send units to another town. If you try to send more than you have, the program will send everyone.

*Command syntax* : `M DestinationId Warlocks Crusaders Amazons Corsairs Bishops Necromancers Architects`

Or, you can send gold by chartering Corsairs's ships. Each corsair can transport up to **200 gold**. If you try to send more than you have, the program will send what you have.

*Command syntax* : `T DestinationId Gold`

**Phase 10 : Defend against Threats**

Several menaces threats to harm your town :

>- Zombies : The dead are not always as dead as they look. 10% (floored) of the corpses in your town will awake and eat brains. Each zombie will eat 1 Peon and then wander into the nothingness (Corpses of both Zombies and eaten Peons are consumed).
>- Demons : Your peons need to hear sermons or they will start to invoke Dark Spirits. Each of your Bishop cover the needs of up to 50 Peons. 10% (floored) of your Heretics (Peons in excess) will spawn Demons. Demons kill 1 Peon each and return to hell (Corpses of Peons are added to town count).
>- Bandits : Outlaws are dwelling in the neighbourhood. The total Outlaws population is divided equitably between towns and sent to steal wealth. Your only defense is your Corsairs patrols. Each corsair can stop up to 5 outlaws. Each outlaw not stopped steals 10 gold from your town (maximum town debt is 200 gold)

At least 1 town of Outlaws (100 population) is generated at the start of the game, then 1 more for each 5 players (ie. 1-4 Players : 1 Outlaws, 5-9 Players : 2 Outlaws...).
Outlaws can be recognized with `id = -1`

**Phase 11 : Construct Building**

When reaching this phase, the construction of the buildings in your town progress according to the number of Architects. Each Architect increases the completion of a single Building by 8%. When a Building reaches 100%, it is completed and start to generate revenues in the next "Taxes" Phase. The construction queue is auto-managed (first come, first served).

You can then also start the construction of other Buildings (BuildingId = Letter in parenthesis) :

    TEMPLE (T) : 		200 Gold
    BARRACKS (B) : 		200 Gold
    ESTATE (E) : 		200 Gold
    PALACE (P) : 		500 Gold

You can start the construction of as many Building as you want, and if you don't have enough gold, Building will be ignored. The construction of your new Buildings will only start next round.

*Command syntax* : `B BuildingId BuildingId BuildingId ...`

**Phase 12 : Make Children**

Every five round (round 5, 10, 15...), new Peons will be born and ready to fight. Each pair of Peons will make 1 Peon (ie. 23 Peons generate 11 new Peons).


Rules
=

 - Bots should not be written to beat or support specific other bots.
 - Writing to files is allowed. Please write to "yoursubmissionname.txt", the folder will be emptied before a game starts. Other external resources are disallowed.
 - Your submission has 1 second to respond (per town).
 - Provide commands to compile and run your submissions.

Winning
=
Winner is the one with the most towns after 100 rounds. If a player captures all towns, the game stops and he wins. If multiple players have the same amount of towns, the total population will count, then the amount of gold.

Controller
=
[You can find the controller on github.](https://github.com/Thrax37/koth-master/) It also contains 2 samplebots, written in Java. Open it in Eclipse, place the compiled bots in the root folder and add a class to the control program (just like the samplebots).

Fights
=

The fighting formula is something like this :

For each soldier class (Warlock, Crusader, Amazon) :

 - Calculate balance between offense and defense (ie. Who has more of each class and how many more?)
 - For the excess soldiers (ie. value of positive balance), see how many "weak targets" (see Phase 7 diagram) there is.
 - Multiply the eligible soldiers' (ie. "weak targets" compared to "excess soldiers") fighting strength by the bonus and add the rest with a fighting strength of 1. 

You can try a simulator here : http://ideone.com/ArJosE (just change the values of the soldiers, you'll get bonuses and total strengths)

Here are a few test cases :

    Attack      Defense     A. Bonus    D. Bonus   A. Str      D. Str    Winner
    20/10/0     12/12/12    8/0/0       0/2/10     34.0        42.0      Defense
    40/0/5      12/12/12    12/0/0      0/12/0     51.0        42.0      Attack
    0/60/8      10/30/2     0/10/6      8/0/0      76.0        46.0      Attack
    20/20/40    90/5/5      0/15/5      40/0/0     90.0        120.0     Defense

Results
=

Running...