Cleaned up some files
This commit is contained in:
@@ -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; }
|
||||
|
||||
@@ -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;
|
||||
Height = yCellCount;
|
||||
Width = xCellCount;
|
||||
|
||||
//Initialize Map
|
||||
Map = new Cell[xCellCount, yCellCount];
|
||||
//set Starting cell;
|
||||
StartingCell = Map[0, 0];
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,7 +1,9 @@
|
||||
using HexCore;
|
||||
|
||||
namespace ConsoleApp.Maps
|
||||
{
|
||||
public interface IHexMap : IMap
|
||||
public interface IHexMap
|
||||
{
|
||||
|
||||
Graph Graph { get; }
|
||||
}
|
||||
}
|
||||
@@ -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; }
|
||||
}
|
||||
}
|
||||
@@ -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();
|
||||
}
|
||||
}
|
||||
@@ -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; }
|
||||
}
|
||||
}
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -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,18 +54,19 @@ 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);
|
||||
|
||||
return possibles;
|
||||
}
|
||||
|
||||
|
||||
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];
|
||||
|
||||
}
|
||||
}
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
|
||||
@@ -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)
|
||||
@@ -52,7 +52,7 @@ namespace ConsoleApp.PathPlanners
|
||||
|
||||
return path;
|
||||
}
|
||||
|
||||
|
||||
public Queue<ICell> GenerateOptimalHexPath(HexMap hexMap, IVehicle vehicle)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
|
||||
@@ -13,6 +13,7 @@ namespace ConsoleApp
|
||||
_bootstrapper = BootStrapper.BootstrapSystem(new CoreModule());
|
||||
_userConsole = new UserConsole();
|
||||
Initialization();
|
||||
Console.WriteLine("Program Completed");
|
||||
}
|
||||
|
||||
private static void Initialization()
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
@@ -7,8 +7,6 @@ namespace ConsoleApp
|
||||
{
|
||||
public class UserConsole : IUserConsole
|
||||
{
|
||||
private IMapFactory _mapFactory;
|
||||
|
||||
public UserConsole()
|
||||
{
|
||||
}
|
||||
|
||||
@@ -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; }
|
||||
|
||||
Reference in New Issue
Block a user