diff --git a/.DS_Store b/.DS_Store
new file mode 100644
index 0000000..6ef9ce9
Binary files /dev/null and b/.DS_Store differ
diff --git a/.idea/.idea.RobotIntelFinal/.idea/contentModel.xml b/.idea/.idea.RobotIntelFinal/.idea/contentModel.xml
index 0e2c1f4..83db942 100644
--- a/.idea/.idea.RobotIntelFinal/.idea/contentModel.xml
+++ b/.idea/.idea.RobotIntelFinal/.idea/contentModel.xml
@@ -7,22 +7,26 @@
+
+
-
+
+
+
-
+
-
+
+
-
+
-
@@ -30,14 +34,28 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
-
-
+
+
+
\ No newline at end of file
diff --git a/.idea/.idea.RobotIntelFinal/.idea/modules.xml b/.idea/.idea.RobotIntelFinal/.idea/modules.xml
index d3cdc38..3bdf19a 100644
--- a/.idea/.idea.RobotIntelFinal/.idea/modules.xml
+++ b/.idea/.idea.RobotIntelFinal/.idea/modules.xml
@@ -2,7 +2,7 @@
-
+
\ No newline at end of file
diff --git a/.idea/.idea.RobotIntelFinal/.idea/workspace.xml b/.idea/.idea.RobotIntelFinal/.idea/workspace.xml
index 11b2854..0d747c3 100644
--- a/.idea/.idea.RobotIntelFinal/.idea/workspace.xml
+++ b/.idea/.idea.RobotIntelFinal/.idea/workspace.xml
@@ -4,6 +4,9 @@
Simulator/Simulator.csproj
ConsoleApp/ConsoleApp.csproj
+
+
+
@@ -15,67 +18,112 @@
-
-
-
-
-
-
-
-
+
+
+
+
+
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
@@ -86,15 +134,20 @@
+
+
+
+
+
-
+
-
+
@@ -104,7 +157,7 @@
-
+
@@ -127,6 +180,10 @@
+
+
+
+
@@ -137,6 +194,13 @@
1607286398679
+
+
+
+
+
+
+
@@ -160,35 +224,49 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+ file://$PROJECT_DIR$/ConsoleApp/PathPlanners/PathPlanner.cs
+ 34
+
+
+
+
+
+
+
+
+
+
+
+ file://$PROJECT_DIR$/ConsoleApp/PathPlanners/PathPlanner.cs
+ 87
+
+
+
+
+
+
+
+
+
+
+
+ file://$PROJECT_DIR$/ConsoleApp/PathPlanners/PathPlanner.cs
+ 85
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/ConsoleApp/ConsoleApp.csproj b/ConsoleApp/ConsoleApp.csproj
index cca39f4..6d8ae3b 100644
--- a/ConsoleApp/ConsoleApp.csproj
+++ b/ConsoleApp/ConsoleApp.csproj
@@ -5,8 +5,23 @@
netcoreapp3.1
+
+ full
+
+
+
+ full
+
+
+
+
+
+
+
+ PreserveNewest
+
diff --git a/ConsoleApp/CoreModule.cs b/ConsoleApp/CoreModule.cs
index 49473d5..e0e2585 100644
--- a/ConsoleApp/CoreModule.cs
+++ b/ConsoleApp/CoreModule.cs
@@ -1,16 +1,22 @@
-using System.Threading;
-using ConsoleApp;
+using ConsoleApp.Maps;
+using ConsoleApp.PathPlanners;
+using ConsoleApp.Sim;
using DryIoc;
-using Module = ConsoleApp.Module;
-namespace Final
+namespace ConsoleApp
{
- public class CoreModule : Module
+ public class CoreModule : IModule
{
- public virtual void Register(IContainer container, ExecutionContext executionContext)
+ public virtual void Register(IContainer container)
{
- //container.Register(Reuse.Singleton);
+ container.Register(Reuse.Singleton);
+ container.Register(Reuse.Singleton);
+ container.Register(Reuse.Singleton);
+ container.Register(Reuse.Singleton);
+ container.Register(Reuse.Singleton);
+ container.Register(Reuse.Singleton);
}
+
public virtual void Resolve(IContainer container)
{
diff --git a/ConsoleApp/IJsonDeserializor.cs b/ConsoleApp/IJsonDeserializor.cs
new file mode 100644
index 0000000..2b43207
--- /dev/null
+++ b/ConsoleApp/IJsonDeserializor.cs
@@ -0,0 +1,7 @@
+namespace ConsoleApp
+{
+ public interface IJsonDeserializor
+ {
+ T DeserializeObject(string filePath);
+ }
+}
\ No newline at end of file
diff --git a/ConsoleApp/JsonDeserializor.cs b/ConsoleApp/JsonDeserializor.cs
new file mode 100644
index 0000000..244832e
--- /dev/null
+++ b/ConsoleApp/JsonDeserializor.cs
@@ -0,0 +1,15 @@
+using System;
+using System.IO;
+using System.Text.Json;
+
+namespace ConsoleApp
+{
+ public class JsonDeserializor : IJsonDeserializor
+ {
+ public T DeserializeObject(string filePath)
+ {
+ var jString = File.ReadAllText(filePath);
+ return JsonSerializer.Deserialize(jString);
+ }
+ }
+}
\ No newline at end of file
diff --git a/ConsoleApp/Maps/Cell.cs b/ConsoleApp/Maps/Cell.cs
new file mode 100644
index 0000000..ef9bfd4
--- /dev/null
+++ b/ConsoleApp/Maps/Cell.cs
@@ -0,0 +1,25 @@
+using System;
+
+namespace ConsoleApp.Maps
+{
+ public enum Coverage
+ {
+ Uncoverd,
+ Covered
+ }
+ public struct Cell : ICell
+ {
+ public int X { get; }
+ public int Y { get; }
+ public Coverage Coverage { get; set; }
+
+ public Cell(int x, int y)
+ {
+ X = x;
+ Y = y;
+ Coverage = Coverage.Uncoverd;
+ }
+
+
+ }
+}
\ No newline at end of file
diff --git a/ConsoleApp/Maps/GlobalDirection.cs b/ConsoleApp/Maps/GlobalDirection.cs
new file mode 100644
index 0000000..675471f
--- /dev/null
+++ b/ConsoleApp/Maps/GlobalDirection.cs
@@ -0,0 +1,14 @@
+namespace ConsoleApp.Maps
+{
+ public enum GlobalDirection
+ {
+ North,
+ South,
+ East,
+ West,
+ NorthEast,
+ SouthEast,
+ NorthWest,
+ SouthWest
+ }
+}
\ No newline at end of file
diff --git a/ConsoleApp/Maps/Heading.cs b/ConsoleApp/Maps/Heading.cs
new file mode 100644
index 0000000..0a58e2b
--- /dev/null
+++ b/ConsoleApp/Maps/Heading.cs
@@ -0,0 +1,50 @@
+namespace ConsoleApp.Maps
+{
+ public class Oreientation
+ {
+ public static (int, int) Forward = (0, 1);
+ public static (int, int) Backward = (0, -1);
+ public static (int, int) Left = (-1, 0);
+ public static (int, int) Right = (1, 0);
+ public static (int, int) LeftBack = (-1, -1);
+ public static (int, int) LeftForward = (-1, 1);
+ public static (int, int) RightBack = (1, -1);
+ public static (int, int) RightForward = (1, 1);
+ }
+ public class Heading
+ {
+ private (int, int) _currentHeading;
+ public (int, int) CurrentHeading { get; }
+
+
+ public void SetHeading((int,int)frontAxel, (int,int)backAxel)
+ {
+ var x = frontAxel.Item1 - backAxel.Item1;
+ var y = frontAxel.Item2 - backAxel.Item2;
+ //forward
+ if (x == 0 && y >= 1) _currentHeading = Oreientation.Forward;
+ //backward
+ if (x == 0 && y <= -1) _currentHeading = Oreientation.Backward;
+ //right
+ if (x >= 1 && y == 0) _currentHeading = Oreientation.Right;
+ //left
+ if (x <= -1 && y == 0) _currentHeading = Oreientation.Left;
+ //left, back
+ if (x <= -1 && y <= -1) _currentHeading = Oreientation.LeftBack;
+ //right, forward
+ if (x >= 1 && y >= 1) _currentHeading = Oreientation.RightForward;
+ //left, forward
+ if (x <= -1 && y >= 1) _currentHeading = Oreientation.LeftForward;
+ //right, back
+ if (x >= 1 && y <= -1) _currentHeading = Oreientation.RightBack;
+
+ }
+ public Heading()
+ {
+ _currentHeading = Oreientation.Forward;
+ CurrentHeading = _currentHeading;
+ }
+
+
+ }
+}
\ No newline at end of file
diff --git a/ConsoleApp/Maps/HexCell.cs b/ConsoleApp/Maps/HexCell.cs
deleted file mode 100644
index 961f0f0..0000000
--- a/ConsoleApp/Maps/HexCell.cs
+++ /dev/null
@@ -1,7 +0,0 @@
-namespace ConsoleApp
-{
- public class HexCell
- {
-
- }
-}
\ No newline at end of file
diff --git a/ConsoleApp/Maps/HexMap.cs b/ConsoleApp/Maps/HexMap.cs
index 0f24d36..bbb7b51 100644
--- a/ConsoleApp/Maps/HexMap.cs
+++ b/ConsoleApp/Maps/HexMap.cs
@@ -1,7 +1,62 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using HexCore;
+using ImTools;
+
namespace ConsoleApp.Maps
{
- public class HexMap
+ public class HexMap : IHexMap
{
+
+ public int Width { get; }
+
+ public int Height { get; }
+
+ public Graph Graph { get; }
+ public OffsetTypes OffsetType { get; }
+ public MovementType DefaultMovement { get; }
+
+
+ ///
+ /// Generate Hex map with cells of 25cm X 25cm
+ ///
+ ///
+ ///
+ public HexMap(int x, int y)
+ {
+ //Set Offset Type for 2d -> 3d conversion
+ OffsetType = OffsetTypes.OddRowsRight;
+ //convert to cm
+ x *= 100;
+ y *= 100;
+
+ //calculate number of cells on x and y axis
+ var xCellCount = (int)Math.Ceiling((decimal) (x) / 25);
+ var yCellCount = (int)Math.Ceiling((decimal) (y) / 25);
+
+ Height = yCellCount;
+ Width = xCellCount;
+
+ var unclearedTerrain = new TerrainType(1, "uncleared");
+ var clearedTerrain = new TerrainType(2, "cleared");
+
+ DefaultMovement = new MovementType(1, "default");
+ var movementTypes = new MovementTypes(
+ new ITerrainType[] { unclearedTerrain, clearedTerrain },
+ new Dictionary>
+ {
+ [DefaultMovement] = new Dictionary
+ {
+ [unclearedTerrain] = 1,
+ [clearedTerrain] = 2
+ }
+ }
+ );
+ Graph = GraphFactory.CreateRectangularGraph(Width, Height, movementTypes, unclearedTerrain);
+ }
+
+
}
}
\ No newline at end of file
diff --git a/ConsoleApp/Maps/ICell.cs b/ConsoleApp/Maps/ICell.cs
new file mode 100644
index 0000000..db8db85
--- /dev/null
+++ b/ConsoleApp/Maps/ICell.cs
@@ -0,0 +1,9 @@
+namespace ConsoleApp.Maps
+{
+ public interface ICell
+ {
+ int X { get; }
+ int Y { get; }
+ Coverage Coverage { get; set; }
+ }
+}
\ No newline at end of file
diff --git a/ConsoleApp/Maps/IHexCell.cs b/ConsoleApp/Maps/IHexCell.cs
deleted file mode 100644
index b4a8d99..0000000
--- a/ConsoleApp/Maps/IHexCell.cs
+++ /dev/null
@@ -1,7 +0,0 @@
-namespace ConsoleApp.Maps
-{
- public interface IHexCell
- {
-
- }
-}
\ No newline at end of file
diff --git a/ConsoleApp/Maps/IHexMap.cs b/ConsoleApp/Maps/IHexMap.cs
index e183efe..a979480 100644
--- a/ConsoleApp/Maps/IHexMap.cs
+++ b/ConsoleApp/Maps/IHexMap.cs
@@ -1,7 +1,13 @@
+using HexCore;
+
namespace ConsoleApp.Maps
{
public interface IHexMap
{
-
+ Graph Graph { get; }
+ OffsetTypes OffsetType { get; }
+ int Width { get; }
+ int Height { get; }
+ MovementType DefaultMovement { get; }
}
}
\ No newline at end of file
diff --git a/ConsoleApp/Maps/IMapFactory.cs b/ConsoleApp/Maps/IMapFactory.cs
index 6630a5b..59cd0d3 100644
--- a/ConsoleApp/Maps/IMapFactory.cs
+++ b/ConsoleApp/Maps/IMapFactory.cs
@@ -1,3 +1,4 @@
+using System.Collections.Generic;
using System.Dynamic;
namespace ConsoleApp.Maps
@@ -6,7 +7,10 @@ namespace ConsoleApp.Maps
{
int Height { get; }
int Width { get; }
- SquareMap SquareMap { get; }
- void GenerateMaps(int x, int y);
+ int CellWidth { get; }
+ void GenerateMaps(int x, int y, double minePercentage);
+ IHexMap GetHexMap();
+ ISquareMap GetSquareMap();
+ IMineMap GetMineMap();
}
}
\ No newline at end of file
diff --git a/ConsoleApp/Maps/IMineMap.cs b/ConsoleApp/Maps/IMineMap.cs
new file mode 100644
index 0000000..b21ed22
--- /dev/null
+++ b/ConsoleApp/Maps/IMineMap.cs
@@ -0,0 +1,7 @@
+namespace ConsoleApp.Maps
+{
+ public interface IMineMap
+ {
+ bool[,] Map { get; }
+ }
+}
\ No newline at end of file
diff --git a/ConsoleApp/Maps/ISquareCell.cs b/ConsoleApp/Maps/ISquareCell.cs
deleted file mode 100644
index 7b118a5..0000000
--- a/ConsoleApp/Maps/ISquareCell.cs
+++ /dev/null
@@ -1,7 +0,0 @@
-namespace ConsoleApp.Maps
-{
- public interface ISquareCell
- {
-
- }
-}
\ No newline at end of file
diff --git a/ConsoleApp/Maps/ISquareMap.cs b/ConsoleApp/Maps/ISquareMap.cs
index 494a3b5..3d5e915 100644
--- a/ConsoleApp/Maps/ISquareMap.cs
+++ b/ConsoleApp/Maps/ISquareMap.cs
@@ -1,7 +1,17 @@
+using System.Collections.Generic;
+using HexCore;
+
namespace ConsoleApp.Maps
{
public interface ISquareMap
{
-
+ Cell[,] Map { get; }
+ Cell StartingCell { get; }
+ Cell LastCell { get; }
+ List PossibleMoves(ICell currentCell);
+ Cell GetCell(int x, int y);
+ int Height { get; }
+ int Width { get; }
+ List GetRange(Cell centerCell, int radius);
}
}
\ No newline at end of file
diff --git a/ConsoleApp/Maps/MapExtensions.cs b/ConsoleApp/Maps/MapExtensions.cs
new file mode 100644
index 0000000..8a046b4
--- /dev/null
+++ b/ConsoleApp/Maps/MapExtensions.cs
@@ -0,0 +1,20 @@
+namespace ConsoleApp.Maps
+{
+ public static class MapExtensions
+ {
+ public static void Fill2DArray(this T[,] arr, T value)
+ {
+ int numRows = arr.GetLength(0);
+ int numCols = arr.GetLength(1);
+
+ for (int i = 0; i < numRows; ++i)
+ {
+ for (int j = 0; j < numCols; ++j)
+ {
+ arr[i, j] = value;
+ }
+ }
+ }
+
+ }
+}
\ No newline at end of file
diff --git a/ConsoleApp/Maps/MapFactory.cs b/ConsoleApp/Maps/MapFactory.cs
index 2ca6254..a7418dc 100644
--- a/ConsoleApp/Maps/MapFactory.cs
+++ b/ConsoleApp/Maps/MapFactory.cs
@@ -1,3 +1,7 @@
+using System;
+using System.Collections.Generic;
+using ConsoleApp.Sim;
+
namespace ConsoleApp.Maps
{
public class MapFactory : IMapFactory
@@ -6,23 +10,37 @@ namespace ConsoleApp.Maps
private int _defaultWidth;
public int Height { get; protected set; }
public int Width { get; protected set; }
- public SquareMap SquareMap { get; }
- public HexMap HexMap { get; }
+ public int CellWidth { get; }
+
- public void GenerateMaps(int x, int y)
+ private ISquareMap _squareMap;
+
+ private IHexMap _hexMap;
+
+ private IMineMap _mineMap;
+
+ public void GenerateMaps(int x, int y, double minePercentage)
{
Width = x;
Height = y;
- throw new System.NotImplementedException();
+ _squareMap = new SquareMap(x, y);
+ _hexMap = new HexMap(x, y);
+ _mineMap = new MineMap(x, y, minePercentage);
}
+ public IHexMap GetHexMap() => _hexMap ?? throw new NullReferenceException("hex map not initialized");
+ public ISquareMap GetSquareMap() => _squareMap ?? throw new NullReferenceException("square map not initialized");
+ public IMineMap GetMineMap() => _mineMap ?? throw new NullReferenceException("mine map not initialized");
- public MapFactory()
+ public MapFactory(IVehicle vehicle)
{
+ CellWidth = vehicle.Width/2;
_defaultHeight = 0;
_defaultWidth = 0;
Height = _defaultHeight;
Width = _defaultWidth;
+ _hexMap = default;
+ _squareMap = default;
}
}
diff --git a/ConsoleApp/Maps/MineMap.cs b/ConsoleApp/Maps/MineMap.cs
new file mode 100644
index 0000000..bd2b8b1
--- /dev/null
+++ b/ConsoleApp/Maps/MineMap.cs
@@ -0,0 +1,33 @@
+using System;
+using System.Collections.Generic;
+
+namespace ConsoleApp.Maps
+{
+ public class MineMap : IMineMap
+ {
+ private int _mineCount;
+ private int _x;
+ private int _y;
+ public bool[,] Map { get; }
+ public MineMap(int x, int y, double minePercentage)
+ {
+ _x = x;
+ _y = y;
+ _mineCount = x*y*((int)minePercentage/100);
+ Map = new bool[x, y];
+ Map.Fill2DArray(false);
+ PlaceMines();
+ }
+
+ private void PlaceMines()
+ {
+ var rand = new Random();
+ for (int i = 0; i < _mineCount; i++)
+ {
+ var x = rand.Next(_x);
+ var y = rand.Next(_y);
+ Map[x, y] = true;
+ }
+ }
+ }
+}
\ No newline at end of file
diff --git a/ConsoleApp/Maps/SquareCell.cs b/ConsoleApp/Maps/SquareCell.cs
deleted file mode 100644
index 051bb42..0000000
--- a/ConsoleApp/Maps/SquareCell.cs
+++ /dev/null
@@ -1,7 +0,0 @@
-namespace ConsoleApp.Maps
-{
- public class SquareCell
- {
-
- }
-}
\ No newline at end of file
diff --git a/ConsoleApp/Maps/SquareMap.cs b/ConsoleApp/Maps/SquareMap.cs
index 90511c3..3ad78b6 100644
--- a/ConsoleApp/Maps/SquareMap.cs
+++ b/ConsoleApp/Maps/SquareMap.cs
@@ -1,7 +1,111 @@
+using System;
+using System.Collections.Generic;
+
+
namespace ConsoleApp.Maps
{
- public class SquareMap
+ public class SquareMap : ISquareMap
{
-
+ public Cell[,] Map { get;}
+ public Cell StartingCell { get; }
+ public Cell LastCell { get; }
+ public int Height { get; }
+ public int Width { get; }
+
+ ///
+ /// Returns a map with square cells
+ ///
+ ///
+ ///
+ public SquareMap(int x, int y)
+ {
+ //convert to cm
+ x *= 100;
+ y *= 100;
+ //calculate number of cells on x and y axis
+ var xCellCount = (int)Math.Ceiling((decimal) (x) / 25);
+ var yCellCount = (int)Math.Ceiling((decimal) (y) / 25);
+
+ //set Width and height Properties
+ Width = xCellCount-1;
+ Height = yCellCount-1;
+
+
+ //Initialize Map
+ Map = new Cell[xCellCount, yCellCount];
+
+ //set last cell;
+ StartingCell = Map[0, 0];
+ for (int i = 0; i < xCellCount; i++)
+ {
+ for (int j = 0; j < yCellCount; j++)
+ {
+ Map[i,j] = new Cell(i, j);
+ }
+ }
+ }
+
+
+ public List PossibleMoves(ICell currentCell)
+ {
+
+ var possibles = new List();
+ if (currentCell.X != 0)
+ possibles.Add(GlobalDirection.West);
+ if (currentCell.X != Width)
+ possibles.Add(GlobalDirection.East);
+ if (currentCell.Y != Height)
+ possibles.Add(GlobalDirection.North);
+ if (currentCell.Y != 0)
+ possibles.Add(GlobalDirection.South);
+
+ return possibles;
+ }
+
+ public List GetRange(Cell centerCell, int radius)
+ {
+ var inRange = new List();
+ var cx = centerCell.X;
+ var cy = centerCell.Y;
+ var topLeft = GetTopCellInBoundingBox(cx, cy, radius);
+ var bottomRight = GetBottomCellInBoundingBox(cx, cy, radius);
+ for (var i = topLeft.X; i < bottomRight.X; i++)
+ {
+ for (var j = bottomRight.Y; j < topLeft.Y; j++)
+ {
+ if (Math.Pow(i - cx, 2) + Math.Pow(j - cy, 2) < Math.Pow(radius,2))
+ {
+ inRange.Add(Map[i,j]);
+ }
+ }
+ }
+ return inRange;
+ }
+
+ private Cell GetTopCellInBoundingBox(int cx, int cy, int radius)
+ {
+ int topX, topY;
+ if (cy + radius > Height) topY = Height;
+ else
+ topY = cy + radius;
+ if (cx - radius < 0) topX = 0;
+ else
+ topX = cx - radius;
+ return Map[topX, topY];
+ }
+ private Cell GetBottomCellInBoundingBox(int cx, int cy, int radius)
+ {
+ int bottomX, bottomY;
+ if (cy - radius > 0) bottomY = 0;
+ else
+ bottomY = cy - radius;
+ if (cx + radius < Width) bottomX = Width;
+ else
+ bottomX = cx + radius;
+ return Map[bottomX, bottomY];
+ }
+
+ public Cell GetCell(int x, int y) => Map[x, y];
+
}
}
\ No newline at end of file
diff --git a/ConsoleApp/Module.cs b/ConsoleApp/Module.cs
deleted file mode 100644
index d4a31e6..0000000
--- a/ConsoleApp/Module.cs
+++ /dev/null
@@ -1,21 +0,0 @@
-using System;
-using System.Collections;
-using System.Collections.Generic;
-using System.Linq;
-using System.Collections.Generic;
-
-using DryIoc;
-
-namespace ConsoleApp
-{
- public abstract class Module : IModule
- {
- public virtual void Register(IContainer container)
- {
- }
-
- public virtual void Resolve(IContainer container)
- {
- }
- }
-}
\ No newline at end of file
diff --git a/ConsoleApp/PathPlanners/IPathPlanner.cs b/ConsoleApp/PathPlanners/IPathPlanner.cs
new file mode 100644
index 0000000..7c8a4a0
--- /dev/null
+++ b/ConsoleApp/PathPlanners/IPathPlanner.cs
@@ -0,0 +1,14 @@
+using System.Collections.Generic;
+using ConsoleApp.Maps;
+using ConsoleApp.Sim;
+using HexCore;
+
+namespace ConsoleApp.PathPlanners
+{
+ public interface IPathPlanner
+ {
+ Queue GenerateOptimalSquarePath(ISquareMap map, IVehicle vehicle);
+ Queue GenerateOptimalHexPath(IHexMap hexMap, IVehicle vehicle);
+ }
+
+}
\ No newline at end of file
diff --git a/ConsoleApp/PathPlanners/IReactivePathPlanner.cs b/ConsoleApp/PathPlanners/IReactivePathPlanner.cs
new file mode 100644
index 0000000..68375a1
--- /dev/null
+++ b/ConsoleApp/PathPlanners/IReactivePathPlanner.cs
@@ -0,0 +1,10 @@
+using System.Collections.Generic;
+using HexCore;
+
+namespace ConsoleApp.PathPlanners
+{
+ public interface IReactivePathPlanner
+ {
+ Queue ReactiveHexPath { get; }
+ }
+}
\ No newline at end of file
diff --git a/ConsoleApp/PathPlanners/PathPlanner.cs b/ConsoleApp/PathPlanners/PathPlanner.cs
new file mode 100644
index 0000000..5f50a66
--- /dev/null
+++ b/ConsoleApp/PathPlanners/PathPlanner.cs
@@ -0,0 +1,131 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using ConsoleApp.Maps;
+using ConsoleApp.Sim;
+using HexCore;
+
+namespace ConsoleApp.PathPlanners
+{
+ public class PathPlanner : IPathPlanner
+ {
+ public Queue GenerateOptimalSquarePath(ISquareMap map, IVehicle vehicle)
+ {
+ var path = new Queue();
+ var myCell = map.StartingCell;
+ var finished = false;
+ var width_cm = (double)(vehicle.DetectorRadius) * 100 * 2;
+ var swathOffset = (int)Math.Floor((decimal) (width_cm) / 25) + 1;
+ var currentHeading = GlobalDirection.North;
+ while (!finished)
+ {
+ var availableMoves = map.PossibleMoves(myCell);
+ if (availableMoves.Contains(GlobalDirection.North) && currentHeading == GlobalDirection.North &&
+ myCell.Y != map.Height)
+ {
+ path.Enqueue(map.GetCell(myCell.X, myCell.Y + 1));
+ myCell = map.GetCell(myCell.X, myCell.Y + 1);
+ }
+ else if (availableMoves.Contains(GlobalDirection.South) && currentHeading == GlobalDirection.South && myCell.Y != 0)
+ {
+ path.Enqueue(map.GetCell(myCell.X, myCell.Y - 1));
+ myCell = map.GetCell(myCell.X, myCell.Y - 1);
+ }
+ else
+ {
+ if (myCell.X + swathOffset >= map.Width)
+ {
+ finished = true;
+ }
+ else
+ {
+ for (int i = myCell.X; i < myCell.X + swathOffset; i++)
+ {
+ path.Enqueue(map.GetCell(i, myCell.Y));
+ }
+ myCell = map.GetCell(myCell.X+swathOffset, myCell.Y);
+ if (currentHeading == GlobalDirection.North)
+ currentHeading = GlobalDirection.South;
+ else if (currentHeading == GlobalDirection.South)
+ currentHeading = GlobalDirection.North;
+ }
+ }
+
+ }
+
+ return path;
+ }
+
+ public Queue GenerateOptimalHexPath(IHexMap hexMap, IVehicle vehicle)
+ {
+ var currentPostion = vehicle.CurrentHexCell;
+ var currentHeading = GlobalDirection.East;
+ var finished = false;
+ var path = new List();
+ while (!finished)
+ {
+ if (currentHeading == GlobalDirection.East)
+ {
+ path.AddRange(hexMap.Graph.GetShortestPath(
+ currentPostion,
+ new Coordinate2D(hexMap.Width, currentPostion.Y, hexMap.OffsetType),
+ hexMap.DefaultMovement));
+ currentPostion = new Coordinate2D(hexMap.Width, currentPostion.Y, hexMap.OffsetType);
+ }
+
+ else if(currentHeading == GlobalDirection.West)
+ {
+ path.AddRange(hexMap.Graph.GetShortestPath(
+ currentPostion,
+ new Coordinate2D(0, currentPostion.Y, hexMap.OffsetType),
+ hexMap.DefaultMovement));
+ currentPostion = new Coordinate2D(0, currentPostion.Y, hexMap.OffsetType);
+
+ }
+
+ if (currentPostion.Y + vehicle.DetectorRadius * 2 > hexMap.Height)
+ {
+ finished = true;
+ break;
+ }
+
+ Coordinate2D tmpPosition;
+ if(currentHeading == GlobalDirection.East)
+ tmpPosition = new Coordinate3D(
+ currentPostion.To3D().X-1,
+ currentPostion.To3D().Y,
+ currentPostion.To3D().Z+1).To2D(hexMap.OffsetType);
+ else
+ tmpPosition = new Coordinate3D(
+ currentPostion.To3D().X,
+ currentPostion.To3D().Y-1,
+ currentPostion.To3D().Z+1).To2D(hexMap.OffsetType);
+ while (hexMap.Graph.GetRange(currentPostion, vehicle.DetectorRadius*2).Contains(tmpPosition))
+ {
+ if(currentHeading == GlobalDirection.East)
+ tmpPosition = new Coordinate3D(
+ tmpPosition.To3D().X-1,
+ tmpPosition.To3D().Y,
+ tmpPosition.To3D().Z+1).To2D(hexMap.OffsetType);
+ else
+ tmpPosition = new Coordinate3D(
+ tmpPosition.To3D().X,
+ tmpPosition.To3D().Y-1,
+ tmpPosition.To3D().Z+1).To2D(hexMap.OffsetType);
+ }
+ path.AddRange(hexMap.Graph.GetShortestPath(
+ currentPostion,
+ tmpPosition,
+ hexMap.DefaultMovement));
+ currentPostion = tmpPosition;
+ if (currentHeading == GlobalDirection.East)
+ currentHeading = GlobalDirection.West;
+ else
+ currentHeading = GlobalDirection.East;
+
+
+ }
+ return new Queue(path);
+ }
+ }
+}
\ No newline at end of file
diff --git a/ConsoleApp/PathPlanners/ReactivePathPlanner.cs b/ConsoleApp/PathPlanners/ReactivePathPlanner.cs
new file mode 100644
index 0000000..a77e9b2
--- /dev/null
+++ b/ConsoleApp/PathPlanners/ReactivePathPlanner.cs
@@ -0,0 +1,20 @@
+using System.Collections.Generic;
+using HexCore;
+
+namespace ConsoleApp.PathPlanners
+{
+ public class ReactivePathPlanner : IReactivePathPlanner
+ {
+ public Queue ReactiveHexPath { get; }
+
+ public ReactivePathPlanner()
+ {
+ ReactiveHexPath = new Queue();
+ }
+
+ public void GenerateReactiveHexPath(Graph graph, ref List optimalPath, Coordinate2D minePosition)
+ {
+
+ }
+ }
+}
\ No newline at end of file
diff --git a/ConsoleApp/Program.cs b/ConsoleApp/Program.cs
index 6fb7869..4cc3a51 100644
--- a/ConsoleApp/Program.cs
+++ b/ConsoleApp/Program.cs
@@ -10,33 +10,35 @@ namespace ConsoleApp
static void Main(string[] args)
{
- _bootstrapper = new BootStrapper();
+ _bootstrapper = BootStrapper.BootstrapSystem(new CoreModule());
_userConsole = new UserConsole();
- StartSimulation();
+ Initialization();
+ Console.WriteLine("Program Completed");
}
- private static void StartSimulation()
+ private static void Initialization()
{
_userConsole.PrintStartMenu();
- var input = _userConsole.GetUserInput();
+ var input = UserConsole.GetUserInput();
if (input == "1")
{
var (x,y) = _userConsole.GetMapDimensions();
- RunSimulation(x, y);
+ var minePercentage = UserConsole.GetMinePercentage();
+ RunSimulation(x, y, minePercentage);
}
else
{
- _userConsole.PrintInvalidInput();
- StartSimulation();
+ UserConsole.PrintInvalidInput();
+ Initialization();
}
}
- private static void RunSimulation(int x,int y)
+ private static void RunSimulation(int x, int y, double minePercentage)
{
- var simRunner = _bootstrapper.Resolve();
var mapFactory = _bootstrapper.Resolve();
+ var simRunner = _bootstrapper.Resolve();
- mapFactory.GenerateMaps(x, y);
+ mapFactory.GenerateMaps(x, y, minePercentage);
simRunner.Run();
}
diff --git a/ConsoleApp/Sim/DetectionHead.cs b/ConsoleApp/Sim/DetectionHead.cs
new file mode 100644
index 0000000..a510d3c
--- /dev/null
+++ b/ConsoleApp/Sim/DetectionHead.cs
@@ -0,0 +1,20 @@
+using System.Collections.Generic;
+using ConsoleApp.Maps;
+using HexCore;
+
+namespace ConsoleApp.Sim
+{
+ public static class DetectionHead
+ {
+ public static List GetCoveredCells(
+ Graph graph,
+ Coordinate2D centerCoordinate,
+ int detectorRadius,
+ GlobalDirection direction) => graph.GetRange(centerCoordinate, detectorRadius);
+
+ public static List| GetCoveredCells(
+ ISquareMap squareMap,
+ Cell centerCell,
+ int detectorRadius) => squareMap.GetRange(centerCell, detectorRadius);
+ }
+}
\ No newline at end of file
diff --git a/ConsoleApp/Sim/IVehicle.cs b/ConsoleApp/Sim/IVehicle.cs
new file mode 100644
index 0000000..3db6ae0
--- /dev/null
+++ b/ConsoleApp/Sim/IVehicle.cs
@@ -0,0 +1,16 @@
+using ConsoleApp.Maps;
+
+namespace ConsoleApp.Sim
+{
+ public interface IVehicle
+ {
+ int Length { get; }
+ int Width { get; }
+ int DetectorOffset { get;}
+ int DetectorRadius { get;}
+ HexCore.Coordinate2D CurrentHexCell { get; set; }
+ Heading HexHeading { get; set; }
+ Heading SquareHeading { get; set; }
+ ICell CurrentSquareCell { get; set; }
+ }
+}
\ No newline at end of file
diff --git a/ConsoleApp/Sim/Vehicle.cs b/ConsoleApp/Sim/Vehicle.cs
new file mode 100644
index 0000000..e4cc62d
--- /dev/null
+++ b/ConsoleApp/Sim/Vehicle.cs
@@ -0,0 +1,31 @@
+using ConsoleApp.Maps;
+
+namespace ConsoleApp.Sim
+{
+ public class Vehicle : IVehicle
+ {
+ public int Length { get; }
+ public int Width { get; }
+
+ public int DetectorOffset { get;}
+ public int DetectorRadius { get;}
+ public HexCore.Coordinate2D CurrentHexCell { get; set; }
+ public Heading HexHeading { get; set; }
+ public Heading SquareHeading { get; set; }
+ public ICell CurrentSquareCell { get; set; }
+
+
+
+
+ public Vehicle(IJsonDeserializor jsonDeserializor)
+ {
+ var config = jsonDeserializor.DeserializeObject("/Users/brady.bodily/Documents/Repositories/CS5890_Robot_Intelligence/RobotIntelFinal/ConsoleApp/Sim/VehicleConfiguration.json");
+ Length = config.Length;
+ Width = config.Width;
+ DetectorRadius = config.DetectorRadius;
+ DetectorOffset = config.DetectorOffset;
+ CurrentHexCell = default;
+ CurrentSquareCell = default;
+ }
+ }
+}
\ No newline at end of file
diff --git a/ConsoleApp/Sim/VehicleConfiguration.cs b/ConsoleApp/Sim/VehicleConfiguration.cs
new file mode 100644
index 0000000..74c2b50
--- /dev/null
+++ b/ConsoleApp/Sim/VehicleConfiguration.cs
@@ -0,0 +1,10 @@
+namespace ConsoleApp.Sim
+{
+ public class VehicleConfiguration
+ {
+ public int Length { get; set; }
+ public int Width { get; set; }
+ public int DetectorRadius { get; set; }
+ public int DetectorOffset { get; set; }
+ }
+}
\ No newline at end of file
diff --git a/ConsoleApp/Sim/VehicleConfiguration.json b/ConsoleApp/Sim/VehicleConfiguration.json
new file mode 100644
index 0000000..adb580b
--- /dev/null
+++ b/ConsoleApp/Sim/VehicleConfiguration.json
@@ -0,0 +1,6 @@
+{
+ "Length": 3,
+ "Width": 2,
+ "DetectorRadius": 3,
+ "DetectorOffset": 2
+}
\ No newline at end of file
diff --git a/ConsoleApp/SimRunner.cs b/ConsoleApp/SimRunner.cs
index 3821e78..be04c2d 100644
--- a/ConsoleApp/SimRunner.cs
+++ b/ConsoleApp/SimRunner.cs
@@ -1,19 +1,59 @@
+using System;
+using System.Collections.Generic;
+using System.Threading;
+using System.Threading.Tasks;
using ConsoleApp.Maps;
+using ConsoleApp.PathPlanners;
+using ConsoleApp.Sim;
+using HexCore;
namespace ConsoleApp
{
public class SimRunner : ISimRunner
{
private IMapFactory _mapFactory;
+ private IVehicle _vehicle;
- public SimRunner(IMapFactory mapFactory)
+ private int _cellWidth;
+ private IPathPlanner _pathPlanner;
+ private IMineMap _mineMap;
+ private IReactivePathPlanner _reactivePathPlanner;
+
+
+ public SimRunner(IMapFactory mapFactory, IVehicle vehicle, IPathPlanner pathPlanner, IReactivePathPlanner reactivePathPlanner)
{
+
+ _cellWidth = mapFactory.CellWidth;
_mapFactory = mapFactory;
+ _vehicle = vehicle;
+ _pathPlanner = pathPlanner;
+ _reactivePathPlanner = reactivePathPlanner;
}
public void Run()
{
- throw new System.NotImplementedException();
+ _mineMap = _mapFactory.GetMineMap();
+ SquareSimulation();
+ HexSimulation();
+ // while(!squareTask.IsCompleted && !hexTask.IsCompleted){Thread.Sleep(500);}
+
}
+
+ private void HexSimulation()
+ {
+ var hexMap = _mapFactory.GetHexMap();
+ _vehicle.CurrentHexCell = new Coordinate2D(0, 0, OffsetTypes.OddRowsRight);
+ var optimalPath = _pathPlanner.GenerateOptimalHexPath(hexMap, _vehicle);
+ var reactivePath = _reactivePathPlanner.ReactiveHexPath;
+ }
+
+
+ private void SquareSimulation()
+ {
+ var squareMap = _mapFactory.GetSquareMap();
+ _vehicle.CurrentSquareCell = squareMap.StartingCell;
+ var optimalPath = _pathPlanner.GenerateOptimalSquarePath(squareMap, _vehicle);
+ }
+
}
}
\ No newline at end of file
diff --git a/ConsoleApp/UserConsole.cs b/ConsoleApp/UserConsole.cs
index 9f824d3..f59b44e 100644
--- a/ConsoleApp/UserConsole.cs
+++ b/ConsoleApp/UserConsole.cs
@@ -1,4 +1,5 @@
using System;
+using System.Collections.Generic;
using System.Linq;
using ConsoleApp.Maps;
@@ -6,8 +7,6 @@ namespace ConsoleApp
{
public class UserConsole : IUserConsole
{
- private IMapFactory _mapFactory;
-
public UserConsole()
{
}
@@ -19,28 +18,40 @@ namespace ConsoleApp
$"\t 2: Load custom map. \n");
}
- public string GetUserInput() => Console.ReadLine();
+ public static string GetUserInput() => Console.ReadLine();
- public void PrintInvalidInput()
- {
- Console.WriteLine($"Invalid input try again \n");
- }
+ public static void PrintInvalidInput() => Console.WriteLine($"Invalid input try again \n");
- public (int width, int height) GetMapDimensions()
+ public (int width, int height) GetMapDimensions()
{
- Console.WriteLine($"Enter Dimensions of map/area to clear as (x, y)");
- var input = GetUserInput();
- var numbers = input.Split();
- if (numbers.Length != 4)
+ Console.WriteLine($"Enter map height: ");
+ var x = GetUserInput();
+
+ if (!int.TryParse(x, out var width))
{
PrintInvalidInput();
GetMapDimensions();
}
- var parsedNumbers = numbers.Where(x => !(x.Equals("(") || x.Equals(")"))).ToList();
- int.TryParse(parsedNumbers[0], out var width);
- int.TryParse(parsedNumbers[1], out var height);
+ Console.WriteLine($"Enter map height: ");
+ var y = GetUserInput();
+ if (int.TryParse(y, out var height)) return (width, height);
+ PrintInvalidInput();
+ GetMapDimensions();
return (width, height);
}
+
+ public static double GetMinePercentage()
+ {
+
+ Console.WriteLine($"Enter desired percentage of mines: ");
+ var x = GetUserInput();
+
+ if (double.TryParse(x, out var percent)) return percent;
+ PrintInvalidInput();
+ GetMinePercentage();
+
+ return percent;
+ }
}
}
\ No newline at end of file
diff --git a/RobotIntelFinal.sln.DotSettings.user b/RobotIntelFinal.sln.DotSettings.user
new file mode 100644
index 0000000..1123785
--- /dev/null
+++ b/RobotIntelFinal.sln.DotSettings.user
@@ -0,0 +1,4 @@
+
+ /Users/brady.bodily/.dotnet/dotnet
+
+ /Users/brady.bodily/.dotnet/sdk/3.1.402/MSBuild.dll
\ No newline at end of file
| | | |