Finished Code

This commit is contained in:
2020-04-22 09:29:29 -06:00
parent 97a8f80ca9
commit f04d7554c8
21 changed files with 527 additions and 15 deletions

View File

@@ -1,5 +1,7 @@
using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.IO; using System.IO;
using System.Threading;
using BattleFieldSimulator.FileSystem; using BattleFieldSimulator.FileSystem;
namespace BattleFieldSimulator.BattlefieldEnvironment namespace BattleFieldSimulator.BattlefieldEnvironment
@@ -11,12 +13,14 @@ namespace BattleFieldSimulator.BattlefieldEnvironment
public List<Troop> Adversaries { get; } public List<Troop> Adversaries { get; }
public StreamWriter OutFile { get; } public StreamWriter OutFile { get; }
public Environment(IMap map, List<Troop> allies, List<Troop> adversaries, string outFile) public Environment(IMap map, List<Troop> allies, List<Troop> adversaries)
{ {
Map = map; Map = map;
Allies = allies; Allies = allies;
Adversaries = adversaries; Adversaries = adversaries;
OutFile = new StreamWriter(Path.Combine(FileSystemConstants.ExecutionDirectory, outFile)); string format = "M_dd_yyyy_hh:mm:ss:tt";
var logName = $"log_{DateTime.Now.ToString(format)}.txt";
OutFile = new StreamWriter(Path.Combine(FileSystemConstants.LogDirectory, logName));
} }
} }

View File

@@ -6,9 +6,9 @@ namespace BattleFieldSimulator.BattlefieldEnvironment
{ {
public Environment CreateEnvironment(IMap map, List<Troop> allies, List<Troop> adversaries, string outFile) public Environment CreateEnvironment(IMap map, List<Troop> allies, List<Troop> adversaries)
{ {
return new Environment(map, allies, adversaries, outFile); return new Environment(map, allies, adversaries);
} }
} }
} }

View File

@@ -13,12 +13,12 @@ namespace BattleFieldSimulator.BattlefieldEnvironment
_troopLoader = troopLoader; _troopLoader = troopLoader;
} }
public Environment Setup(string mapName, string troopFile, string outFile) public Environment Setup(string mapName, string troopFile)
{ {
var map = _mapLoader.LoadMap(mapName); var map = _mapLoader.LoadMap(mapName);
var allies = _troopLoader.LoadAllies(troopFile); var allies = _troopLoader.LoadAllies(troopFile);
var adversaries = _troopLoader.LoadAdversaries(troopFile); var adversaries = _troopLoader.LoadAdversaries(troopFile);
var env = _environmentFactory.CreateEnvironment(map, allies, adversaries, outFile); var env = _environmentFactory.CreateEnvironment(map, allies, adversaries);
return env; return env;
} }
} }

View File

@@ -4,6 +4,6 @@ namespace BattleFieldSimulator.BattlefieldEnvironment
{ {
public interface IEnvironmentFactory public interface IEnvironmentFactory
{ {
Environment CreateEnvironment(IMap map, List<Troop> allies, List<Troop> adversaries, string outFile); Environment CreateEnvironment(IMap map, List<Troop> allies, List<Troop> adversaries);
} }
} }

View File

@@ -2,6 +2,6 @@ namespace BattleFieldSimulator.BattlefieldEnvironment
{ {
public interface IEnvironmentSetup public interface IEnvironmentSetup
{ {
Environment Setup(string mapName, string troopFile, string outFile); Environment Setup(string mapName, string troopFile);
} }
} }

View File

@@ -34,7 +34,7 @@ namespace BattleFieldSimulator.ConsoleClient
PrintHelpMenu(); PrintHelpMenu();
break; break;
case "-r": case "-r":
_simRunner.RunSimulation(inString[1], inString[2], inString[3]); _simRunner.RunSimulation(inString[1], inString[2]);
break; break;
default: default:
return; return;
@@ -48,6 +48,10 @@ namespace BattleFieldSimulator.ConsoleClient
$"A properly formatted man and troop json file are required. The files must be placed \n" + $"A properly formatted man and troop json file are required. The files must be placed \n" +
$"in their respective folder locations. There are examples of what the files should \n" + $"in their respective folder locations. There are examples of what the files should \n" +
$"look like in there. \n \n" + $"look like in there. \n \n" +
$"The maps and troop files load from folders maps/ troops/ respectively. These folders " +
$"should be placed in the execution directory. \n\n" +
$"Log files are written to the common documents folder of your operating system. For windows this is \n" +
$"\tC:\\Users\\Public\\Documents\\BattlefieldSimulator\\Logs \n\n" +
$"<-q> Will exit the program"); $"<-q> Will exit the program");
} }
@@ -58,7 +62,7 @@ namespace BattleFieldSimulator.ConsoleClient
Console.WriteLine("Welcome to the battlefield simulator! \n \n " + Console.WriteLine("Welcome to the battlefield simulator! \n \n " +
"Please make a selection: \n" + "Please make a selection: \n" +
"\t <-h> help menu \n" + "\t <-h> help menu \n" +
"\t <-r mapFileName.json TroopFileName.json outFile.txt> run program \n" + "\t <-r mapFileName.json TroopFileName.json> run program \n" +
"\t <-q> exit program \n"); "\t <-q> exit program \n");
} }
} }

View File

@@ -2,6 +2,6 @@ namespace BattleFieldSimulator.SimRunner
{ {
public interface ISimRunner public interface ISimRunner
{ {
void RunSimulation(string mapName, string troopFile, string outFile); void RunSimulation(string mapName, string troopFile);
} }
} }

View File

@@ -14,15 +14,15 @@ namespace BattleFieldSimulator.SimRunner
_simulation = simulation; _simulation = simulation;
} }
public void RunSimulation(string mapName, string troopFile, string outFile) public void RunSimulation(string mapName, string troopFile)
{ {
var environment = Setup(mapName, troopFile, outFile); var environment = Setup(mapName, troopFile);
_simulation.Run(environment); _simulation.Run(environment);
} }
private Environment Setup(string mapName, string troopFile, string outFile) private Environment Setup(string mapName, string troopFile)
{ {
return _environmentSetup.Setup(mapName, troopFile, outFile); return _environmentSetup.Setup(mapName, troopFile);
} }
} }
} }

View File

@@ -26,9 +26,15 @@ namespace BattleFieldSimulator.SimRunner
finished = CheckIfFinished(environment.Allies, environment.Adversaries); finished = CheckIfFinished(environment.Allies, environment.Adversaries);
} }
if(environment.Adversaries.Count != 0) if(environment.Adversaries.Count != 0)
{
Console.WriteLine($"The Enemy Won!!\n\n"); Console.WriteLine($"The Enemy Won!!\n\n");
environment.OutFile.WriteLine($"The Enemy Won!!\n\n");
}
if(environment.Allies.Count != 0) if(environment.Allies.Count != 0)
{
Console.WriteLine($"We Were Victorious!!\n\n"); Console.WriteLine($"We Were Victorious!!\n\n");
environment.OutFile.WriteLine($"We Were Victorious!!\n\n");
}
} }
private void PrintRoundInfo(IEnvironment environment) private void PrintRoundInfo(IEnvironment environment)

View File

@@ -0,0 +1,139 @@
Allies: 2
Adversaries: 2
Ally 0 Casualties: 0 Initial Troop Count: 30
Ally 1 Casualties: 0 Initial Troop Count: 10
Adversary 0 Casualties: 0 Initial Troop Count: 10
Adversary 1 Casualties: 0 Initial Troop Count: 15
A . A . . . . . . .
. E . . . . . . . .
. . . . . . . E . .
. . . . . . . . . .
. . . . . . . . . .
. . . . . . . . . .
. . . . . . . . . .
. . . . . . . . . .
. . . . . . . . . .
. . . . . . . . . .
--------------------
Allies: 2
Adversaries: 2
Ally 0 Casualties: 17 Initial Troop Count: 30
Ally 1 Casualties: 2 Initial Troop Count: 10
Adversary 0 Casualties: 6 Initial Troop Count: 10
Adversary 1 Casualties: 0 Initial Troop Count: 15
A . A . . . E . . .
. E . . . . . . . .
. . . . . . . . . .
. . . . . . . . . .
. . . . . . . . . .
. . . . . . . . . .
. . . . . . . . . .
. . . . . . . . . .
. . . . . . . . . .
. . . . . . . . . .
--------------------
Allies: 2
Adversaries: 2
Ally 0 Casualties: 26 Initial Troop Count: 30
Ally 1 Casualties: 3 Initial Troop Count: 10
Adversary 0 Casualties: 10 Initial Troop Count: 10
Adversary 1 Casualties: 0 Initial Troop Count: 15
A . A E . . . . . .
. E . . . . . . . .
. . . . . . . . . .
. . . . . . . . . .
. . . . . . . . . .
. . . . . . . . . .
. . . . . . . . . .
. . . . . . . . . .
. . . . . . . . . .
. . . . . . . . . .
--------------------
Allies: 2
Adversaries: 1
Ally 0 Casualties: 26 Initial Troop Count: 30
Ally 1 Casualties: 3 Initial Troop Count: 10
Adversary 0 Casualties: 4 Initial Troop Count: 15
A . A E . . . . . .
. . . . . . . . . .
. . . . . . . . . .
. . . . . . . . . .
. . . . . . . . . .
. . . . . . . . . .
. . . . . . . . . .
. . . . . . . . . .
. . . . . . . . . .
. . . . . . . . . .
--------------------
Allies: 2
Adversaries: 1
Ally 0 Casualties: 26 Initial Troop Count: 30
Ally 1 Casualties: 5 Initial Troop Count: 10
Adversary 0 Casualties: 8 Initial Troop Count: 15
A . A E . . . . . .
. . . . . . . . . .
. . . . . . . . . .
. . . . . . . . . .
. . . . . . . . . .
. . . . . . . . . .
. . . . . . . . . .
. . . . . . . . . .
. . . . . . . . . .
. . . . . . . . . .
--------------------
Allies: 2
Adversaries: 1
Ally 0 Casualties: 26 Initial Troop Count: 30
Ally 1 Casualties: 5 Initial Troop Count: 10
Adversary 0 Casualties: 11 Initial Troop Count: 15
A . A E . . . . . .
. . . . . . . . . .
. . . . . . . . . .
. . . . . . . . . .
. . . . . . . . . .
. . . . . . . . . .
. . . . . . . . . .
. . . . . . . . . .
. . . . . . . . . .
. . . . . . . . . .
--------------------
Allies: 2
Adversaries: 1
Ally 0 Casualties: 26 Initial Troop Count: 30
Ally 1 Casualties: 7 Initial Troop Count: 10
Adversary 0 Casualties: 12 Initial Troop Count: 15
A . A E . . . . . .
. . . . . . . . . .
. . . . . . . . . .
. . . . . . . . . .
. . . . . . . . . .
. . . . . . . . . .
. . . . . . . . . .
. . . . . . . . . .
. . . . . . . . . .
. . . . . . . . . .
--------------------
Allies: 2
Adversaries: 1
Ally 0 Casualties: 26 Initial Troop Count: 30
Ally 1 Casualties: 8 Initial Troop Count: 10
Adversary 0 Casualties: 13 Initial Troop Count: 15
A . A E . . . . . .
. . . . . . . . . .
. . . . . . . . . .
. . . . . . . . . .
. . . . . . . . . .
. . . . . . . . . .
. . . . . . . . . .
. . . . . . . . . .
. . . . . . . . . .
. . . . . . . . . .
--------------------

View File

@@ -0,0 +1,156 @@
Allies: 2
Adversaries: 2
Ally 0 Casualties: 0 Initial Troop Count: 30
Ally 1 Casualties: 0 Initial Troop Count: 10
Adversary 0 Casualties: 0 Initial Troop Count: 10
Adversary 1 Casualties: 0 Initial Troop Count: 15
A . A . . . . . . .
. E . . . . . . . .
. . . . . . . E . .
. . . . . . . . . .
. . . . . . . . . .
. . . . . . . . . .
. . . . . . . . . .
. . . . . . . . . .
. . . . . . . . . .
. . . . . . . . . .
--------------------
Allies: 2
Adversaries: 2
Ally 0 Casualties: 15 Initial Troop Count: 30
Ally 1 Casualties: 2 Initial Troop Count: 10
Adversary 0 Casualties: 6 Initial Troop Count: 10
Adversary 1 Casualties: 0 Initial Troop Count: 15
A . A . . . E . . .
. E . . . . . . . .
. . . . . . . . . .
. . . . . . . . . .
. . . . . . . . . .
. . . . . . . . . .
. . . . . . . . . .
. . . . . . . . . .
. . . . . . . . . .
. . . . . . . . . .
--------------------
Allies: 2
Adversaries: 2
Ally 0 Casualties: 23 Initial Troop Count: 30
Ally 1 Casualties: 4 Initial Troop Count: 10
Adversary 0 Casualties: 9 Initial Troop Count: 10
Adversary 1 Casualties: 0 Initial Troop Count: 15
A . A E . . . . . .
. E . . . . . . . .
. . . . . . . . . .
. . . . . . . . . .
. . . . . . . . . .
. . . . . . . . . .
. . . . . . . . . .
. . . . . . . . . .
. . . . . . . . . .
. . . . . . . . . .
--------------------
Allies: 2
Adversaries: 1
Ally 0 Casualties: 23 Initial Troop Count: 30
Ally 1 Casualties: 4 Initial Troop Count: 10
Adversary 0 Casualties: 3 Initial Troop Count: 15
A . A E . . . . . .
. . . . . . . . . .
. . . . . . . . . .
. . . . . . . . . .
. . . . . . . . . .
. . . . . . . . . .
. . . . . . . . . .
. . . . . . . . . .
. . . . . . . . . .
. . . . . . . . . .
--------------------
Allies: 2
Adversaries: 1
Ally 0 Casualties: 23 Initial Troop Count: 30
Ally 1 Casualties: 6 Initial Troop Count: 10
Adversary 0 Casualties: 5 Initial Troop Count: 15
A . A E . . . . . .
. . . . . . . . . .
. . . . . . . . . .
. . . . . . . . . .
. . . . . . . . . .
. . . . . . . . . .
. . . . . . . . . .
. . . . . . . . . .
. . . . . . . . . .
. . . . . . . . . .
--------------------
Allies: 2
Adversaries: 1
Ally 0 Casualties: 23 Initial Troop Count: 30
Ally 1 Casualties: 7 Initial Troop Count: 10
Adversary 0 Casualties: 8 Initial Troop Count: 15
A . A E . . . . . .
. . . . . . . . . .
. . . . . . . . . .
. . . . . . . . . .
. . . . . . . . . .
. . . . . . . . . .
. . . . . . . . . .
. . . . . . . . . .
. . . . . . . . . .
. . . . . . . . . .
--------------------
Allies: 2
Adversaries: 1
Ally 0 Casualties: 23 Initial Troop Count: 30
Ally 1 Casualties: 7 Initial Troop Count: 10
Adversary 0 Casualties: 10 Initial Troop Count: 15
A . A E . . . . . .
. . . . . . . . . .
. . . . . . . . . .
. . . . . . . . . .
. . . . . . . . . .
. . . . . . . . . .
. . . . . . . . . .
. . . . . . . . . .
. . . . . . . . . .
. . . . . . . . . .
--------------------
Allies: 2
Adversaries: 1
Ally 0 Casualties: 23 Initial Troop Count: 30
Ally 1 Casualties: 7 Initial Troop Count: 10
Adversary 0 Casualties: 12 Initial Troop Count: 15
A . A E . . . . . .
. . . . . . . . . .
. . . . . . . . . .
. . . . . . . . . .
. . . . . . . . . .
. . . . . . . . . .
. . . . . . . . . .
. . . . . . . . . .
. . . . . . . . . .
. . . . . . . . . .
--------------------
Allies: 2
Adversaries: 1
Ally 0 Casualties: 23 Initial Troop Count: 30
Ally 1 Casualties: 7 Initial Troop Count: 10
Adversary 0 Casualties: 13 Initial Troop Count: 15
A . A E . . . . . .
. . . . . . . . . .
. . . . . . . . . .
. . . . . . . . . .
. . . . . . . . . .
. . . . . . . . . .
. . . . . . . . . .
. . . . . . . . . .
. . . . . . . . . .
. . . . . . . . . .
--------------------

View File

@@ -0,0 +1,104 @@
Allies: 2
Adversaries: 2
Ally 0 Casualties: 0 Initial Troop Count: 30
Ally 1 Casualties: 0 Initial Troop Count: 10
Adversary 0 Casualties: 0 Initial Troop Count: 10
Adversary 1 Casualties: 0 Initial Troop Count: 15
A . A . . . . . . .
. E . . . . . . . .
. . . . . . . E . .
. . . . . . . . . .
. . . . . . . . . .
. . . . . . . . . .
. . . . . . . . . .
. . . . . . . . . .
. . . . . . . . . .
. . . . . . . . . .
--------------------
Allies: 2
Adversaries: 2
Ally 0 Casualties: 8 Initial Troop Count: 30
Ally 1 Casualties: 2 Initial Troop Count: 10
Adversary 0 Casualties: 9 Initial Troop Count: 10
Adversary 1 Casualties: 0 Initial Troop Count: 15
A . A . . . E . . .
. E . . . . . . . .
. . . . . . . . . .
. . . . . . . . . .
. . . . . . . . . .
. . . . . . . . . .
. . . . . . . . . .
. . . . . . . . . .
. . . . . . . . . .
. . . . . . . . . .
--------------------
Allies: 2
Adversaries: 1
Ally 0 Casualties: 8 Initial Troop Count: 30
Ally 1 Casualties: 2 Initial Troop Count: 10
Adversary 0 Casualties: 0 Initial Troop Count: 15
A . A E . . . . . .
. . . . . . . . . .
. . . . . . . . . .
. . . . . . . . . .
. . . . . . . . . .
. . . . . . . . . .
. . . . . . . . . .
. . . . . . . . . .
. . . . . . . . . .
. . . . . . . . . .
--------------------
Allies: 2
Adversaries: 1
Ally 0 Casualties: 8 Initial Troop Count: 30
Ally 1 Casualties: 3 Initial Troop Count: 10
Adversary 0 Casualties: 7 Initial Troop Count: 15
A . A E . . . . . .
. . . . . . . . . .
. . . . . . . . . .
. . . . . . . . . .
. . . . . . . . . .
. . . . . . . . . .
. . . . . . . . . .
. . . . . . . . . .
. . . . . . . . . .
. . . . . . . . . .
--------------------
Allies: 2
Adversaries: 1
Ally 0 Casualties: 8 Initial Troop Count: 30
Ally 1 Casualties: 4 Initial Troop Count: 10
Adversary 0 Casualties: 12 Initial Troop Count: 15
A . A E . . . . . .
. . . . . . . . . .
. . . . . . . . . .
. . . . . . . . . .
. . . . . . . . . .
. . . . . . . . . .
. . . . . . . . . .
. . . . . . . . . .
. . . . . . . . . .
. . . . . . . . . .
--------------------
Allies: 2
Adversaries: 1
Ally 0 Casualties: 8 Initial Troop Count: 30
Ally 1 Casualties: 5 Initial Troop Count: 10
Adversary 0 Casualties: 15 Initial Troop Count: 15
A . A E . . . . . .
. . . . . . . . . .
. . . . . . . . . .
. . . . . . . . . .
. . . . . . . . . .
. . . . . . . . . .
. . . . . . . . . .
. . . . . . . . . .
. . . . . . . . . .
. . . . . . . . . .
--------------------

Binary file not shown.

View File

@@ -0,0 +1,18 @@
{
"Map": {
"X": "10",
"Y" : "10",
"Grid": [
[0, 0, 0, 0, 0, 0, 0, 5, 5, 0],
[0, 1, 1, 1, 0, 0, 0, 5, 5, 0],
[0, 2, 2, 2, 0, 0, 0, 5, 4, 0],
[0, 2, 3, 2, 0, 0, 0, 4, 3, 0],
[0, 2, 2, 1, 0, 0, 0, 3, 2, 0],
[0, 0, 0, 0, 0, 0, 0, 2, 2, 0],
[0, 0, 0, 0, 0, 0, 0, 1, 1, 0],
[0, 0, 0, 1, 0, 0, 0, 1, 0, 0],
[0, 0, 0, 0, 0, 0, 0, 1, 0, 0],
[0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
]
}
}

View File

@@ -0,0 +1,81 @@
{
"Allies": [
{
"Troop":
{
"MovementSpeed": 1.5,
"SightDistance": 4,
"EngagementDistance": 3,
"WeaponDamage": 8.5,
"Marksmanship": 7,
"TroopCount": 30,
"Aggressiveness": 7,
"Defense": 6,
"Mission": "Defend",
"EntryPointX": 0,
"EntryPointY": 0,
"ObjectiveX": 0,
"ObjectiveY": 0
}
},
{
"Troop":
{
"MovementSpeed": 2.5,
"SightDistance": 2,
"EngagementDistance": 1,
"WeaponDamage": 5,
"Marksmanship": 4,
"TroopCount": 10,
"Aggressiveness": 10,
"Defense": 3,
"Mission": "Defend",
"EntryPointX": 0,
"EntryPointY": 2,
"ObjectiveX": 0,
"ObjectiveY": 0
}
}
],
"Adversaries": [
{
"Troop":
{
"MovementSpeed": 2.5,
"SightDistance": 3,
"EngagementDistance": 1,
"WeaponDamage": 7,
"Marksmanship": 4,
"TroopCount": 10,
"Aggressiveness": 10,
"Defense": 3,
"Mission": "Attack",
"EntryPointX": 1,
"EntryPointY": 1,
"ObjectiveX": 0,
"ObjectiveY": 0
}
},
{
"Troop":
{
"MovementSpeed": 2.5,
"SightDistance": 2,
"EngagementDistance": 1,
"WeaponDamage": 1,
"Marksmanship": 4,
"TroopCount": 15,
"Aggressiveness": 10,
"Defense": 3,
"Mission": "Attack",
"EntryPointX": 2,
"EntryPointY": 7,
"ObjectiveX": 0,
"ObjectiveY": 0
}
}
]
}