Cleaned up some files

This commit is contained in:
2020-12-15 00:37:47 -07:00
parent 257aaa331f
commit 00444fbba9
16 changed files with 93 additions and 124 deletions

View File

@@ -20,7 +20,6 @@
<e p="HexMap.cs" t="Include" />
<e p="ICell.cs" t="Include" />
<e p="IHexMap.cs" t="Include" />
<e p="IMap.cs" t="Include" />
<e p="IMapFactory.cs" t="Include" />
<e p="ISquareMap.cs" t="Include" />
<e p="MapFactory.cs" t="Include" />

View File

@@ -18,19 +18,19 @@
</component>
<component name="ChangeListManager">
<list default="true" id="dafcaeb7-80aa-43a3-a480-786fafb78c0b" name="Default Changelist" comment="">
<change beforePath="$PROJECT_DIR$/.idea/.idea.RobotIntelFinal/.idea/contentModel.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/.idea.RobotIntelFinal/.idea/contentModel.xml" afterDir="false" />
<change beforePath="$PROJECT_DIR$/.idea/.idea.RobotIntelFinal/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/.idea.RobotIntelFinal/.idea/workspace.xml" afterDir="false" />
<change beforePath="$PROJECT_DIR$/ConsoleApp/ConsoleApp.csproj" beforeDir="false" afterPath="$PROJECT_DIR$/ConsoleApp/ConsoleApp.csproj" afterDir="false" />
<change beforePath="$PROJECT_DIR$/ConsoleApp/CoreModule.cs" beforeDir="false" afterPath="$PROJECT_DIR$/ConsoleApp/CoreModule.cs" afterDir="false" />
<change beforePath="$PROJECT_DIR$/ConsoleApp/IPathPlanner.cs" beforeDir="false" afterPath="$PROJECT_DIR$/ConsoleApp/PathPlanners/IPathPlanner.cs" afterDir="false" />
<change beforePath="$PROJECT_DIR$/ConsoleApp/Maps/Cell.cs" beforeDir="false" afterPath="$PROJECT_DIR$/ConsoleApp/Maps/Cell.cs" afterDir="false" />
<change beforePath="$PROJECT_DIR$/ConsoleApp/Maps/GlobalDirection.cs" beforeDir="false" afterPath="$PROJECT_DIR$/ConsoleApp/Maps/GlobalDirection.cs" afterDir="false" />
<change beforePath="$PROJECT_DIR$/ConsoleApp/IVehicle.cs" beforeDir="false" afterPath="$PROJECT_DIR$/ConsoleApp/IVehicle.cs" afterDir="false" />
<change beforePath="$PROJECT_DIR$/ConsoleApp/Maps/HexMap.cs" beforeDir="false" afterPath="$PROJECT_DIR$/ConsoleApp/Maps/HexMap.cs" afterDir="false" />
<change beforePath="$PROJECT_DIR$/ConsoleApp/Maps/ICell.cs" beforeDir="false" afterPath="$PROJECT_DIR$/ConsoleApp/Maps/ICell.cs" afterDir="false" />
<change beforePath="$PROJECT_DIR$/ConsoleApp/Maps/IMap.cs" beforeDir="false" afterPath="$PROJECT_DIR$/ConsoleApp/Maps/IMap.cs" afterDir="false" />
<change beforePath="$PROJECT_DIR$/ConsoleApp/Maps/IHexMap.cs" beforeDir="false" afterPath="$PROJECT_DIR$/ConsoleApp/Maps/IHexMap.cs" afterDir="false" />
<change beforePath="$PROJECT_DIR$/ConsoleApp/Maps/IMap.cs" beforeDir="false" />
<change beforePath="$PROJECT_DIR$/ConsoleApp/Maps/IMapFactory.cs" beforeDir="false" afterPath="$PROJECT_DIR$/ConsoleApp/Maps/IMapFactory.cs" afterDir="false" />
<change beforePath="$PROJECT_DIR$/ConsoleApp/Maps/ISquareMap.cs" beforeDir="false" afterPath="$PROJECT_DIR$/ConsoleApp/Maps/ISquareMap.cs" afterDir="false" />
<change beforePath="$PROJECT_DIR$/ConsoleApp/Maps/MapFactory.cs" beforeDir="false" afterPath="$PROJECT_DIR$/ConsoleApp/Maps/MapFactory.cs" afterDir="false" />
<change beforePath="$PROJECT_DIR$/ConsoleApp/Maps/SquareMap.cs" beforeDir="false" afterPath="$PROJECT_DIR$/ConsoleApp/Maps/SquareMap.cs" afterDir="false" />
<change beforePath="$PROJECT_DIR$/ConsoleApp/PathPlanner.cs" beforeDir="false" afterPath="$PROJECT_DIR$/ConsoleApp/PathPlanners/PathPlanner.cs" afterDir="false" />
<change beforePath="$PROJECT_DIR$/ConsoleApp/PathPlanners/IPathPlanner.cs" beforeDir="false" afterPath="$PROJECT_DIR$/ConsoleApp/PathPlanners/IPathPlanner.cs" afterDir="false" />
<change beforePath="$PROJECT_DIR$/ConsoleApp/PathPlanners/PathPlanner.cs" beforeDir="false" afterPath="$PROJECT_DIR$/ConsoleApp/PathPlanners/PathPlanner.cs" afterDir="false" />
<change beforePath="$PROJECT_DIR$/ConsoleApp/SimRunner.cs" beforeDir="false" afterPath="$PROJECT_DIR$/ConsoleApp/SimRunner.cs" afterDir="false" />
<change beforePath="$PROJECT_DIR$/ConsoleApp/Vehicle.cs" beforeDir="false" afterPath="$PROJECT_DIR$/ConsoleApp/Vehicle.cs" afterDir="false" />
</list>
<option name="SHOW_DIALOG" value="false" />
<option name="HIGHLIGHT_CONFLICTS" value="true" />
@@ -70,16 +70,22 @@
<option value="$PROJECT_DIR$/ConsoleApp/CoreModule.cs" />
<option value="$PROJECT_DIR$/ConsoleApp/IPathPlanner.cs" />
<option value="$PROJECT_DIR$/ConsoleApp/PathPlanner.cs" />
<option value="$PROJECT_DIR$/ConsoleApp/PathPlanners/PathPlanner.cs" />
<option value="$PROJECT_DIR$/ConsoleApp/PathPlanners/IPathPlanner.cs" />
<option value="$PROJECT_DIR$/ConsoleApp/Maps/GlobalDirection.cs" />
<option value="$PROJECT_DIR$/ConsoleApp/Maps/HexCoordinates.cs" />
<option value="$PROJECT_DIR$/ConsoleApp/SimRunner.cs" />
<option value="$PROJECT_DIR$/ConsoleApp/Maps/Cell.cs" />
<option value="$PROJECT_DIR$/ConsoleApp/Maps/ICell.cs" />
<option value="$PROJECT_DIR$/ConsoleApp/Maps/MapFactory.cs" />
<option value="$PROJECT_DIR$/ConsoleApp/Maps/IMapFactory.cs" />
<option value="$PROJECT_DIR$/ConsoleApp/IVehicle.cs" />
<option value="$PROJECT_DIR$/ConsoleApp/Vehicle.cs" />
<option value="$PROJECT_DIR$/ConsoleApp/PathPlanners/IPathPlanner.cs" />
<option value="$PROJECT_DIR$/ConsoleApp/Maps/IMap.cs" />
<option value="$PROJECT_DIR$/ConsoleApp/PathPlanners/PathPlanner.cs" />
<option value="$PROJECT_DIR$/ConsoleApp/Maps/ISquareMap.cs" />
<option value="$PROJECT_DIR$/ConsoleApp/SimRunner.cs" />
<option value="$PROJECT_DIR$/ConsoleApp/Maps/SquareMap.cs" />
<option value="$PROJECT_DIR$/ConsoleApp/Maps/HexMap.cs" />
<option value="$PROJECT_DIR$/ConsoleApp/Maps/IHexMap.cs" />
</changedPaths>
</component>
<component name="ProjectId" id="1lIZ7IfsUjzqV2Jb1obOFvGFAfp" />
@@ -157,7 +163,7 @@
<workItem from="1607982179018" duration="634000" />
<workItem from="1607983288378" duration="86000" />
<workItem from="1607983862958" duration="7777000" />
<workItem from="1607993290571" duration="14428000" />
<workItem from="1607993290571" duration="16131000" />
</task>
<servers />
</component>
@@ -189,27 +195,14 @@
<line>34</line>
<properties documentPath="$PROJECT_DIR$/ConsoleApp/PathPlanner.cs" initialLine="34" containingFunctionPresentation="method 'GenerateOptimalSquarePath'">
<startOffsets>
<option value="1433" />
<option value="1466" />
</startOffsets>
<endOffsets>
<option value="1449" />
<option value="1482" />
</endOffsets>
</properties>
<option name="timeStamp" value="24" />
</line-breakpoint>
<line-breakpoint enabled="true" type="DotNet Breakpoints">
<url>file://$PROJECT_DIR$/ConsoleApp/Maps/HexMap.cs</url>
<line>62</line>
<properties documentPath="$PROJECT_DIR$/ConsoleApp/Maps/HexMap.cs" initialLine="63" containingFunctionPresentation="constructor 'HexMap'">
<startOffsets>
<option value="2218" />
</startOffsets>
<endOffsets>
<option value="2219" />
</endOffsets>
</properties>
<option name="timeStamp" value="33" />
</line-breakpoint>
</breakpoints>
</breakpoint-manager>
</component>

View File

@@ -8,7 +8,7 @@ namespace ConsoleApp
int Width { get; }
int DetectorOffset { get;}
int DetectorWidth { get;}
ICell CurrentHexCell { get; set; }
HexCore.Coordinate2D CurrentHexCell { get; set; }
Heading HexHeading { get; set; }
Heading SquareHeading { get; set; }
ICell CurrentSquareCell { get; set; }

View File

@@ -6,12 +6,12 @@ namespace ConsoleApp.Maps
{
public class HexMap : IHexMap
{
private int _mapHeight;
private int _mapWidth;
public Cell[,] Map { get; }
public Cell StartingCell { get; }
public Cell LastCell { get; }
public Graph HexGraph { get; }
public int Width { get; }
public int Height { get; }
public Graph Graph { get; }
/// <summary>
/// Generate Hex map with cells of 25cm X 25cm
@@ -28,25 +28,12 @@ namespace ConsoleApp.Maps
var xCellCount = (int)Math.Ceiling((decimal) (x) / 25);
var yCellCount = (int)Math.Ceiling((decimal) (y) / 25);
_mapHeight = yCellCount;
_mapWidth = xCellCount;
//Initialize Map
Map = new Cell[xCellCount, yCellCount];
//set Starting cell;
StartingCell = Map[0, 0];
Height = yCellCount;
Width = xCellCount;
var unclearedTerrain = new TerrainType(1, "uncleared");
var clearedTerrain = new TerrainType(2, "cleared");
//Populate Map
var list = new List<CellState>();
for (int i = 0; i < _mapHeight; i++)
{
for (int j = 0; j < _mapWidth; j++)
{
list.Add(new CellState(false, new Coordinate2D(i, j, OffsetTypes.OddRowsRight), unclearedTerrain));
}
}
var movement = new MovementType(1, "default");
var movementTypes = new MovementTypes(
new ITerrainType[] { unclearedTerrain, clearedTerrain },
@@ -59,24 +46,8 @@ namespace ConsoleApp.Maps
}
}
);
HexGraph = GraphFactory.CreateRectangularGraph(_mapWidth, _mapHeight, movementTypes, unclearedTerrain);
Graph = GraphFactory.CreateRectangularGraph(Width, Height, movementTypes, unclearedTerrain);
}
public List<GlobalDirection> PossibleMoves(ICell currentCell)
{
var x = currentCell.X;
var y = currentCell.Y;
var possibles = new List<GlobalDirection>();
if(currentCell.Y != _mapHeight)
possibles.Add(GlobalDirection.North);
if(currentCell.Y != 0)
possibles.Add(GlobalDirection.South);
if(currentCell.X != _mapWidth && currentCell.Y != _mapHeight)
possibles.Add(GlobalDirection.NorthEast);
return possibles;
}
}
}

View File

@@ -1,7 +1,9 @@
using HexCore;
namespace ConsoleApp.Maps
{
public interface IHexMap : IMap
public interface IHexMap
{
Graph Graph { get; }
}
}

View File

@@ -1,16 +0,0 @@
using System.Collections.Generic;
using System.ComponentModel;
using HexCore;
namespace ConsoleApp.Maps
{
public interface IMap
{
public Cell[,] Map { get; }
Cell StartingCell { get; }
Cell LastCell { get; }
public List<GlobalDirection> PossibleMoves(ICell currentCell);
Graph HexGraph { get; }
}
}

View File

@@ -8,7 +8,8 @@ namespace ConsoleApp.Maps
int Height { get; }
int Width { get; }
int CellWidth { get; }
Dictionary<string, IMap> Maps { get; }
void GenerateMaps(int x, int y);
IHexMap GetHexMap();
ISquareMap GetSquareMap();
}
}

View File

@@ -1,7 +1,16 @@
using System.Collections.Generic;
using HexCore;
namespace ConsoleApp.Maps
{
public interface ISquareMap : IMap
public interface ISquareMap
{
Cell[,] Map { get; }
Cell StartingCell { get; }
Cell LastCell { get; }
List<GlobalDirection> PossibleMoves(ICell currentCell);
Cell GetCell(int x, int y);
int Height { get; }
int Width { get; }
}
}

View File

@@ -1,3 +1,4 @@
using System;
using System.Collections.Generic;
namespace ConsoleApp.Maps
@@ -8,18 +9,23 @@ namespace ConsoleApp.Maps
private int _defaultWidth;
public int Height { get; protected set; }
public int Width { get; protected set; }
public int CellWidth { get; protected set; }
public int CellWidth { get; }
public Dictionary<string, IMap> Maps { get; }
private ISquareMap _squareMap;
private IHexMap _hexMap;
public void GenerateMaps(int x, int y)
{
Width = x;
Height = y;
Maps.Add("SquareMap",new SquareMap(x, y));
Maps.Add("HexMap", new HexMap(x, y));
_squareMap = new SquareMap(x, y);
_hexMap = new HexMap(x, y);
}
public IHexMap GetHexMap() => _hexMap ?? throw new NullReferenceException("hex map not initialized");
public ISquareMap GetSquareMap() => _squareMap ?? throw new NullReferenceException("square map not initialized");
public MapFactory(IVehicle vehicle)
{
@@ -28,7 +34,8 @@ namespace ConsoleApp.Maps
_defaultWidth = 0;
Height = _defaultHeight;
Width = _defaultWidth;
Maps = new Dictionary<string, IMap>();
_hexMap = default;
_squareMap = default;
}
}

View File

@@ -1,6 +1,7 @@
using System;
using System.Collections.Generic;
using HexCore;
using ImTools;
namespace ConsoleApp.Maps
{
@@ -12,9 +13,11 @@ namespace ConsoleApp.Maps
public int Height { get; }
public int Width { get; }
private int _mapWidth;
private int _mapHeight;
/// <summary>
/// Returns a map with square cells
/// </summary>
/// <param name="x"></param>
/// <param name="y"></param>
public SquareMap(int x, int y)
{
HexGraph = default;
@@ -25,11 +28,10 @@ namespace ConsoleApp.Maps
var xCellCount = (int)Math.Ceiling((decimal) (x) / 25);
var yCellCount = (int)Math.Ceiling((decimal) (y) / 25);
//set Width and height fields and Properties
_mapWidth = xCellCount-1;
_mapHeight = yCellCount-1;
Height = _mapHeight;
Width = _mapWidth;
//set Width and height Properties
Width = xCellCount-1;
Height = yCellCount-1;
//Initialize Map
Map = new Cell[xCellCount, yCellCount];
@@ -52,9 +54,9 @@ namespace ConsoleApp.Maps
var possibles = new List<GlobalDirection>();
if (currentCell.X != 0)
possibles.Add(GlobalDirection.West);
if (currentCell.X != _mapWidth)
if (currentCell.X != Width)
possibles.Add(GlobalDirection.East);
if (currentCell.Y != _mapHeight)
if (currentCell.Y != Height)
possibles.Add(GlobalDirection.North);
if (currentCell.Y != 0)
possibles.Add(GlobalDirection.South);
@@ -64,6 +66,7 @@ namespace ConsoleApp.Maps
public Graph HexGraph { get; }
public Cell this[in int x, in int y] => Map[x, y];
public Cell GetCell(int x, int y) => Map[x, y];
}
}

View File

@@ -5,7 +5,7 @@ namespace ConsoleApp.PathPlanners
{
public interface IPathPlanner
{
Queue<ICell> GenerateOptimalSquarePath(SquareMap map, IVehicle vehicle);
Queue<ICell> GenerateOptimalSquarePath(ISquareMap map, IVehicle vehicle);
Queue<ICell> GenerateOptimalHexPath(HexMap hexMap, IVehicle vehicle);
}

View File

@@ -6,7 +6,7 @@ namespace ConsoleApp.PathPlanners
{
public class PathPlanner : IPathPlanner
{
public Queue<ICell> GenerateOptimalSquarePath(SquareMap map, IVehicle vehicle)
public Queue<ICell> GenerateOptimalSquarePath(ISquareMap map, IVehicle vehicle)
{
var path = new Queue<ICell>();
var myCell = map.StartingCell;
@@ -20,13 +20,13 @@ namespace ConsoleApp.PathPlanners
if (availableMoves.Contains(GlobalDirection.North) && currentHeading == GlobalDirection.North &&
myCell.Y != map.Height)
{
path.Enqueue(map[myCell.X, myCell.Y + 1]);
myCell = map[myCell.X, myCell.Y + 1];
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[myCell.X, myCell.Y - 1]);
myCell = map[myCell.X, myCell.Y - 1];
path.Enqueue(map.GetCell(myCell.X, myCell.Y - 1));
myCell = map.GetCell(myCell.X, myCell.Y - 1);
}
else
{
@@ -38,9 +38,9 @@ namespace ConsoleApp.PathPlanners
{
for (int i = myCell.X; i < myCell.X + swathOffset; i++)
{
path.Enqueue(map[i, myCell.Y]);
path.Enqueue(map.GetCell(i, myCell.Y));
}
myCell = map[myCell.X+swathOffset, myCell.Y];
myCell = map.GetCell(myCell.X+swathOffset, myCell.Y);
if (currentHeading == GlobalDirection.North)
currentHeading = GlobalDirection.South;
else if (currentHeading == GlobalDirection.South)

View File

@@ -13,6 +13,7 @@ namespace ConsoleApp
_bootstrapper = BootStrapper.BootstrapSystem(new CoreModule());
_userConsole = new UserConsole();
Initialization();
Console.WriteLine("Program Completed");
}
private static void Initialization()

View File

@@ -4,6 +4,7 @@ using System.Threading;
using System.Threading.Tasks;
using ConsoleApp.Maps;
using ConsoleApp.PathPlanners;
using HexCore;
namespace ConsoleApp
{
@@ -28,7 +29,7 @@ namespace ConsoleApp
public void Run()
{
//SquareSimulation();
SquareSimulation();
HexSimulation();
// while(!squareTask.IsCompleted && !hexTask.IsCompleted){Thread.Sleep(500);}
@@ -36,15 +37,15 @@ namespace ConsoleApp
private void HexSimulation()
{
var hexMap = (HexMap)_mapFactory.Maps["HexMap"];
_vehicle.CurrentHexCell = hexMap.StartingCell;
var optimalPath = _pathPlanner.GenerateOptimalHexPath(hexMap, _vehicle);
var hexMap = _mapFactory.GetHexMap();
_vehicle.CurrentHexCell = new Coordinate2D(0, 0, OffsetTypes.OddRowsRight);
//var optimalPath = _pathPlanner.GenerateOptimalHexPath(hexMap, _vehicle);
}
private void SquareSimulation()
{
var squareMap = (SquareMap)_mapFactory.Maps["SquareMap"];
var squareMap = _mapFactory.GetSquareMap();
_vehicle.CurrentSquareCell = squareMap.StartingCell;
var optimalPath = _pathPlanner.GenerateOptimalSquarePath(squareMap, _vehicle);
}

View File

@@ -7,8 +7,6 @@ namespace ConsoleApp
{
public class UserConsole : IUserConsole
{
private IMapFactory _mapFactory;
public UserConsole()
{
}

View File

@@ -10,7 +10,7 @@ namespace ConsoleApp
public int DetectorOffset { get;}
public int DetectorWidth { get;}
public ICell CurrentHexCell { get; set; }
public HexCore.Coordinate2D CurrentHexCell { get; set; }
public Heading HexHeading { get; set; }
public Heading SquareHeading { get; set; }
public ICell CurrentSquareCell { get; set; }