Getting close

This commit is contained in:
2020-12-16 04:02:37 -07:00
parent cf432a348b
commit f8ce6d0c83
27 changed files with 587 additions and 163 deletions

View File

@@ -17,6 +17,9 @@ namespace ConsoleApp.Maps
public OffsetTypes OffsetType { get; }
public MovementType DefaultMovement { get; }
public TerrainType ClearedTerrain { get; }
public TerrainType UnclearedTerrain { get; }
/// <summary>
@@ -28,35 +31,28 @@ namespace ConsoleApp.Maps
{
//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;
Height = y;
Width = x;
var unclearedTerrain = new TerrainType(1, "uncleared");
var clearedTerrain = new TerrainType(2, "cleared");
UnclearedTerrain = new TerrainType(1, "uncleared");
ClearedTerrain = new TerrainType(2, "cleared");
DefaultMovement = new MovementType(1, "default");
var movementTypes = new MovementTypes(
new ITerrainType[] { unclearedTerrain, clearedTerrain },
new ITerrainType[] { UnclearedTerrain, ClearedTerrain },
new Dictionary<IMovementType, Dictionary<ITerrainType, int>>
{
[DefaultMovement] = new Dictionary<ITerrainType, int>
{
[unclearedTerrain] = 1,
[clearedTerrain] = 2
[UnclearedTerrain] = 1,
[ClearedTerrain] = 2
}
}
);
Graph = GraphFactory.CreateRectangularGraph(Width, Height, movementTypes, unclearedTerrain);
Graph = GraphFactory.CreateRectangularGraph(Width, Height, movementTypes, UnclearedTerrain);
}
}
}

View File

@@ -9,5 +9,7 @@ namespace ConsoleApp.Maps
int Width { get; }
int Height { get; }
MovementType DefaultMovement { get; }
public TerrainType ClearedTerrain { get; }
public TerrainType UnclearedTerrain { get; }
}
}

View File

@@ -7,7 +7,6 @@ namespace ConsoleApp.Maps
{
int Height { get; }
int Width { get; }
int CellWidth { get; }
void GenerateMaps(int x, int y, double minePercentage);
IHexMap GetHexMap();
ISquareMap GetSquareMap();

View File

@@ -3,5 +3,8 @@ namespace ConsoleApp.Maps
public interface IMineMap
{
bool[,] Map { get; }
int TotalBombs { get; }
bool GetCell(int x, int y);
}
}

View File

@@ -15,6 +15,5 @@ namespace ConsoleApp.Maps
}
}
}
}
}

View File

@@ -10,7 +10,6 @@ namespace ConsoleApp.Maps
private int _defaultWidth;
public int Height { get; protected set; }
public int Width { get; protected set; }
public int CellWidth { get; }
@@ -22,11 +21,17 @@ namespace ConsoleApp.Maps
public void GenerateMaps(int x, int y, double minePercentage)
{
Width = x;
Height = y;
_squareMap = new SquareMap(x, y);
_hexMap = new HexMap(x, y);
_mineMap = new MineMap(x, y, minePercentage);
//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);
Width = xCellCount;
Height = yCellCount;
_squareMap = new SquareMap(xCellCount, yCellCount);
_hexMap = new HexMap(xCellCount, yCellCount);
_mineMap = new MineMap(xCellCount, yCellCount, minePercentage);
}
public IHexMap GetHexMap() => _hexMap ?? throw new NullReferenceException("hex map not initialized");
public ISquareMap GetSquareMap() => _squareMap ?? throw new NullReferenceException("square map not initialized");
@@ -34,7 +39,6 @@ namespace ConsoleApp.Maps
public MapFactory(IVehicle vehicle)
{
CellWidth = vehicle.Width/2;
_defaultHeight = 0;
_defaultWidth = 0;
Height = _defaultHeight;

View File

@@ -1,5 +1,7 @@
using System;
using System.Collections.Generic;
using System.IO;
using HexCore;
namespace ConsoleApp.Maps
{
@@ -9,24 +11,44 @@ namespace ConsoleApp.Maps
private int _x;
private int _y;
public bool[,] Map { get; }
public int TotalBombs { get; }
private List<Cell> _placedMines;
public MineMap(int x, int y, double minePercentage)
{
_x = x;
_y = y;
_mineCount = x*y*((int)minePercentage/100);
_placedMines = new List<Cell>();
_mineCount = (int)(x*y*(minePercentage/100));
TotalBombs = _mineCount;
Map = new bool[x, y];
Map.Fill2DArray(false);
PlaceMines();
using(TextWriter tw = new StreamWriter("/Users/brady.bodily/Documents/Repositories/CS5890_Robot_Intelligence/RobotIntelFinal/ConsoleApp/Output/Mines.txt"))
{
foreach (var s in _placedMines)
tw.WriteLine($"{s.X} {s.Y}");
}
}
public bool GetCell(int x, int y) => Map[x,y];
private void PlaceMines()
{
var rand = new Random();
for (int i = 0; i < _mineCount; i++)
for (var i = 0; i < _mineCount; i++)
{
var x = rand.Next(_x);
var y = rand.Next(_y);
Map[x, y] = true;
var x = rand.Next(5,_x-5);
var y = rand.Next(5,_y-5);
if (Map[x, y] == true)
{
i--;
}
else
{
Map[x, y] = true;
_placedMines.Add(new Cell(x,y));
}
}
}
}

View File

@@ -19,26 +19,21 @@ namespace ConsoleApp.Maps
/// <param name="y"></param>
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;
Width = x-1;
Height = y-1;
//Initialize Map
Map = new Cell[xCellCount, yCellCount];
Map = new Cell[x, y];
//set last cell;
StartingCell = Map[0, 0];
for (int i = 0; i < xCellCount; i++)
for (int i = 0; i < x; i++)
{
for (int j = 0; j < yCellCount; j++)
for (int j = 0; j < y; j++)
{
Map[i,j] = new Cell(i, j);
}