Working through some localization stuff will probably be pretty fluid.
This commit is contained in:
2020-12-14 16:08:59 -07:00
parent 2c5f0b73b9
commit d63066c150
19 changed files with 199 additions and 258 deletions

View File

@@ -5,6 +5,14 @@
<TargetFramework>netcoreapp3.1</TargetFramework>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)' == 'Debug' ">
<DebugType>full</DebugType>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)' == 'Release' ">
<DebugType>full</DebugType>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="DryIoc.dll" Version="4.5.2" />
</ItemGroup>

View File

@@ -1,9 +1,16 @@
using ConsoleApp.Maps;
namespace ConsoleApp
{
public interface IVehicle
{
int Length { get; }
int Width { get; }
int DetectorWidth { get; }
int DetectorOffset { get;}
int DetectorWidth { get;}
ICell CurrentHexCell { get; set; }
Heading HexHeading { get; set; }
Heading SquareHeading { get; set; }
ICell CurrentSquareCell { get; set; }
}
}

23
ConsoleApp/Maps/Cell.cs Normal file
View File

@@ -0,0 +1,23 @@
using System;
namespace ConsoleApp.Maps
{
public struct Cell : ICell
{
public int X { get; }
public int Y { get; }
public int Z { get; }
public Cell(int x, int y, int z = default)
{
if (z != default)
{
if (x + y + z != 0) throw new ArgumentException("x + y + z must be 0");
}
X = x;
Y = y;
Z = z;
}
}
}

View File

@@ -1,35 +1,49 @@
using System.Net.NetworkInformation;
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 = (0, 1);
if (x == 0 && y >= 1) _currentHeading = Oreientation.Forward;
//backward
if (x == 0 && y <= -1) _currentHeading = (0, -1);
if (x == 0 && y <= -1) _currentHeading = Oreientation.Backward;
//right
if (x >= 1 && y == 0) _currentHeading = (1, 0);
if (x >= 1 && y == 0) _currentHeading = Oreientation.Right;
//left
if (x <= -1 && y == 0) _currentHeading = (-1, 0);
if (x <= -1 && y == 0) _currentHeading = Oreientation.Left;
//left, back
if (x <= -1 && y <= -1) _currentHeading = (-1, -1);
if (x <= -1 && y <= -1) _currentHeading = Oreientation.LeftBack;
//right, forward
if (x >= 1 && y >= 1) _currentHeading = (1, 1);
if (x >= 1 && y >= 1) _currentHeading = Oreientation.RightForward;
//left, forward
if (x <= -1 && y >= 1) _currentHeading = (-1, 1);
if (x <= -1 && y >= 1) _currentHeading = Oreientation.LeftForward;
//right, back
if (x >= 1 && y <= -1) _currentHeading = (1, -1);
if (x >= 1 && y <= -1) _currentHeading = Oreientation.RightBack;
}
public Heading()
{
_currentHeading = (1,0);
_currentHeading = Oreientation.Forward;
CurrentHeading = _currentHeading;
}

View File

@@ -1,20 +0,0 @@
using System;
using System.Collections.Generic;
namespace ConsoleApp.Maps
{
public struct HexCell : IHexCell
{
public int X { get; }
public int Y { get; }
public int Z { get; }
public HexCell(int q, int r, int s)
{
if (q + r + s != 0) throw new ArgumentException("q + r + s must be 0");
X = q;
Y = r;
Z = s;
}
}
}

View File

@@ -5,16 +5,32 @@ namespace ConsoleApp.Maps
{
public class HexMap : IHexMap
{
private HexCell[,] Map { get; }
public Cell[,] Map { get; }
public ICell StartingCell { get; }
public ICell LastCell { get; }
/// <summary>
/// Generate Hex map with cells of 25cm X 25cm
/// </summary>
/// <param name="x"></param>
/// <param name="y"></param>
public HexMap(int x, int y)
{
Map = new HexCell[x+1,y+1];
for (int r = 0; r < y; r++) {
//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 last cell;
StartingCell = Map[0, 0];
Map = new Cell[xCellCount, yCellCount];
for (int r = 0; r < yCellCount; r++) {
int r_offset = Convert.ToInt32(Math.Floor(Convert.ToDouble(r)/2));
for (int q = r_offset; q < x - r_offset; q++) {
for (int q = r_offset; q < xCellCount - r_offset; q++) {
// Console.WriteLine($"r:{r}, q:{q}-----x:{x}, y:{y}");
Map[r, q] = new HexCell(q, r, -q-r);
Map[r, q] = new Cell(q, r, -q-r);
}
}
}

View File

@@ -1,7 +0,0 @@
namespace ConsoleApp.Maps
{
public interface IHexCell : ICell
{
}
}

View File

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

View File

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

View File

@@ -1,8 +0,0 @@
namespace ConsoleApp.Maps
{
public interface ISquareCell : ICell
{
new int X { get; }
new int Y { get; }
}
}

View File

@@ -8,6 +8,7 @@ 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 Dictionary<string, IMap> Maps { get; }
@@ -20,8 +21,9 @@ namespace ConsoleApp.Maps
Maps.Add("HexMap", new HexMap(x, y));
}
public MapFactory()
public MapFactory(IVehicle vehicle)
{
CellWidth = vehicle.Width/2;
_defaultHeight = 0;
_defaultWidth = 0;
Height = _defaultHeight;

View File

@@ -1,16 +0,0 @@
namespace ConsoleApp.Maps
{
public struct SquareCell : ISquareCell
{
public int X { get; }
public int Y { get; }
public int Z { get; }
public SquareCell(int x, int y)
{
X = x;
Y = y;
Z = default;
}
}
}

View File

@@ -5,16 +5,27 @@ namespace ConsoleApp.Maps
{
public class SquareMap : ISquareMap
{
public SquareCell[,] Map { get;}
public Cell[,] Map { get;}
public ICell StartingCell { get; }
public ICell LastCell { get; }
public SquareMap(int x, int y)
{
Map = new SquareCell[x,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 last cell;
StartingCell = Map[0, 0];
Map = new Cell[xCellCount, yCellCount];
for (int i = 0; i < x; i++)
{
for (int j = 0; j < y; j++)
{
Map[i,j] = new SquareCell(i, j);
Map[i,j] = new Cell(i, j);
}
}
}

View File

@@ -1,3 +1,7 @@
using System;
using System.Collections.Generic;
using System.Threading;
using System.Threading.Tasks;
using ConsoleApp.Maps;
namespace ConsoleApp
@@ -5,15 +9,59 @@ namespace ConsoleApp
public class SimRunner : ISimRunner
{
private IMapFactory _mapFactory;
private IVehicle _vehicle;
private IMap _squareMap;
private IMap _hexMap;
private int _cellWidth;
public SimRunner(IMapFactory mapFactory, IVehicle vehicle)
{
_squareMap = mapFactory.Maps["SquareMap"];
_hexMap = mapFactory.Maps["HexMap"];
_cellWidth = mapFactory.CellWidth;
_mapFactory = mapFactory;
_vehicle = vehicle;
}
public void Run()
{
_vehicle.CurrentHexCell = _hexMap.StartingCell;
_vehicle.CurrentSquareCell = _squareMap.StartingCell;
var squareTask = Task.Run(() => SquareSimulation());
var hexTask = Task.Run(() => HexSimulation());
while(!squareTask.IsCompleted && !hexTask.IsCompleted){Thread.Sleep(500);}
}
private void HexSimulation()
{
var optimalPath = GenerateHexPath();
}
private void SquareSimulation()
{
var optimalPath = GenerateSquarePath();
}
private object GenerateSquarePath()
{
throw new NotImplementedException();
}
private Queue<ICell> GenerateHexPath()
{
var path = new Queue<ICell>();
var currentCell = _vehicle.CurrentHexCell;
var possibles = _hexMap.PossibleMoves(currentCell);
while (currentCell != _hexMap.LastCell)
{
}
return path;
}
}
}

View File

@@ -1,4 +1,5 @@
using System;
using ConsoleApp.Maps;
namespace ConsoleApp
{
@@ -9,6 +10,12 @@ namespace ConsoleApp
public int DetectorOffset { get;}
public int DetectorWidth { get;}
public ICell CurrentHexCell { get; set; }
public Heading HexHeading { get; set; }
public Heading SquareHeading { get; set; }
public ICell CurrentSquareCell { get; set; }
public Vehicle(IJsonDeserializor jsonDeserializor)
{
@@ -17,8 +24,10 @@ namespace ConsoleApp
Width = config.Width;
DetectorWidth = config.DetectorWidth;
DetectorOffset = config.DetectorOffset;
CurrentHexCell = default;
CurrentSquareCell = default;
HexHeading = default;
SquareHeading = default;
}
}
}