# Introduction

This model simulates a medieval battle between two armies (blue vs red).
The main goal is to find which formations and compositions of units work against which.
Uploading files to this wiki was unsuccessful, so I've provided external links as well (with the hope that file upload might be fixed in the future).

# Problem definition

Two armies fight each other on a battlefield. An army is composed of several units in a certain formation.
When simulation is started the armies move against each other, killing the units of the opposing army.
When one army has no units left alive it is considered defeated and simulation is over.
There is a limit to how many units an army can have, each unit type has a cost.
Sum of costs cannot be greater than cost limit (600). Furthermore, an army cannot have more than 32 units of the same type.

# Method

I am using NetLogo to simulate movement and combat of the units.
I have selected certain scenarios which bring out differences in military strategies.
Each scenario is run 20 times. More runs would ensure higher certainty of results.
Since there is a bit of randomness in play (seeking enemies, random hits), if an army wins by just a small portion of it surviving (e.g. one soldier) I will consider it a tie.

Scenario A
Same composition of units and formations.

Scenario B
Same composition of units, different formations.

Scenario C
Knights centric Blue vs Spearmen centric Red

Scenario D
Swordsmen centric Blue vs Spearmen centric Red

Scenario E
Generic Blue vs Swordsmen and Knights Red

# Model

Following is the description of the model and how the units fight.
Soldiers start moving forward (towards the center) in formation.
When one soldier meets an enemy soldier, they exchange hits of certain damage (DMG).
Hits lower health points (HP). When health reaches zero a soldier dies.
If a soldier survives an engagement he seeks nearest enemies.
If a soldier doesn’t meet an enemy till he reaches the center of battlefield he starts to seek nearest enemies.
Soldiers of the same army do not fight each other but are obstacles to one another.
When such collision occurs, the blocked soldier tries to find a different route, if there is none, he waits.

Units
The difference between armies is given by their color. The damage a unit gives to enemy is a random number between half of its DMG and full DMG.

Spearmen
HP: 5 , DMG: 3, Cost: 10
Swordsmen
HP: 10 , DMG: 2, Cost: 20
Knights
HP: 20 , DMG: 5, Cost: 50

Formations
Line - half of the unit type is north and the other south making a line facing towards the center, each unit type creates a different line
Square - same as line, but there are 2 lines per unit type (6 lines per army)
Wedge - an arrowhead looking formation pointing towards the center, each unit type creates its own wedge

# Results

Table of results with every battles outcome:
[1]

Screenshots of every battle before it starts (ZIP):
File:Xlazl00 Screenshots.zip [2]

Scenario A
Same composition of units and formations.
A1: line vs line => TIE

A2: square vs square => TIE

A3: wedge vs wedge => TIE

Scenario B
Same composition of units, different formations.
B1: line vs square => BLUE

B2: line vs wedge => RED

B3: square vs wedge => RED

Scenario C
Knights centric Blue vs Spearmen centric Red
C1: line vs line => RED

C2: square vs square => RED

C3: wedge vs wedge => RED

C4: line vs square => RED

C5: line vs wedge => RED

C6: square vs wedge => RED

C7: square vs line => RED

C8: wedge vs square => RED

C9: wedge vs line => RED

Scenario D
Swordsmen centric Blue vs Spearmen centric Red
D1: line vs line => RED

D2: square vs square => RED

D3: wedge vs wedge => RED

D4: line vs square => BLUE

D5: line vs wedge => RED

D6: square vs wedge => RED

D7: square vs line => RED

D8: wedge vs square => TIE

D9: wedge vs line => RED

Scenario E
Generic Blue vs Swordsmen and Knights Red
E1: line vs line => BLUE

E2: square vs square => BLUE

E3: wedge vs wedge => BLUE

E4: line vs square => BLUE

E5: line vs wedge => BLUE

E6: square vs wedge => RED

E7: square vs line => RED

E8: wedge vs square => BLUE

E9: wedge vs line => BLUE

# Conclusion

Through the many battles it became clear that numbers and the ability to flank the enemy are the major deciding factors.
When even a stronger enemy is flanked, their chances of winning are quite slim.

Changing the cost/budget/health/damage of the units might change the results, but with how I set the model, having a wider (taller) formation and greater numbers is a sure way to victory.
However one cannot omit the factor of chance. Since the damage given is a random number (between half of damage and full damage), there might be few occasions when luck decides the battle.