using System.Collections.Generic;
public static void Main()
var a1 = Army.fromString(army1);
var a2 = Army.fromString(army2);
var sim = new BattleSimulator(a1, a2);
private readonly Army army1;
private readonly Army army2;
public BattleSimulator(Army army1, Army army2){
var copy1 = army1.makeCopy();
var copy2 = army2.makeCopy();
while(copy1.fight(copy2)){
if(copy1.isDefeated && copy2.isDefeated){
if(copy1.isDefeated && !copy2.isDefeated){
public void battle(int itterations){
for(int i=0; i<itterations; i++){
if(outcome == Outcome.tie){
if(outcome == Outcome.win){
if(outcome == Outcome.loss)
var winPercent = win*100f/(itterations*1.0f);
var tiePercent = tie*100f/(itterations*1.0f);
var lossPercent = loss*100f/(itterations*1.0f);
Console.WriteLine($"Army1, {itterations} battles:");
Console.WriteLine($"Win: {win} ({winPercent}%)");
Console.WriteLine($"Tie: {tie} ({tiePercent}%)");
Console.WriteLine($"Loss: {loss} ({lossPercent}%)");
public Dude(int strength, int health){
this.strength = strength;
public string toString(){
return $"{strength}/{health}";
private List<Dude> dudes = new List<Dude>();
private Random randomSource = new Random();
public bool isDefeated => dudes.Count == 0;
public static Army fromString(string army){
var toReturn = new Army();
var items = army.Split(',');
foreach(var dude in items){
var dudeNoWhiteSpace = dude.Trim();
var raw = dude.Split('/');
toReturn.dudes.Add(new Dude(Int32.Parse(raw[0]), Int32.Parse(raw[1])));
var toReturn = new Army();
foreach(var dude in dudes){
toReturn.dudes.Add(dude);
public string toString(){
var sb = new List<string>();
foreach(var dude in dudes){
return String.Join(" , ", sb);
public bool fight(Army other){
var myIndex = randomSource.Next(dudes.Count);
var otherIndex = randomSource.Next(other.dudes.Count);
var myDamage = other.dudes[otherIndex].strength;
var otherDamage = dudes[myIndex].strength;
dudes[myIndex].health -= myDamage;
other.dudes[otherIndex].health -= otherDamage;
if(dudes[myIndex].health <= 1){
if(other.dudes[otherIndex].health <= 0){
other.dudes.RemoveAt(otherIndex);
if(isDefeated || other.isDefeated){