public static void Main() { //https://docs.google.com/spreadsheets/d/1v90ZW65jDo-c3_5oWHT7UYIYtDB3ma44uUdaoYh8TeQ/ String[,] grid = { {"_0", "_1", "_2", "_3"}, {"_8", "_9", "_10", "_11"}, {"_16", "_17", "_18", "_19"}, {"_24", "_25", "_26", "_27"}, }; Console.WriteLine("Grid valid? " + gridValid(grid, 4, 4)); InfoOfEachTile topLeft = new InfoOfEachTile("_9"); InfoOfEachTile topRight = new InfoOfEachTile("_10"); InfoOfEachTile bottomLeft = new InfoOfEachTile("_17"); InfoOfEachTile bottomRight = new InfoOfEachTile("_18"); InfoOfEachTile.connectHorizontal(topLeft, topRight); InfoOfEachTile.connectHorizontal(bottomLeft, bottomRight); InfoOfEachTile.connectVertical(topLeft, bottomLeft); InfoOfEachTile.connectVertical(topRight, bottomRight); String[,] miniGrid = miniGridFromTile(topLeft); for (var y = miniGrid.GetLowerBound(0); y <= miniGrid.GetUpperBound(0); y++) { for (var x = miniGrid.GetLowerBound(1); x <= miniGrid.GetUpperBound(1); x++) { Console.Write(miniGrid[y, x] == null ? "__ " : miniGrid[y, x] + " "); } Console.WriteLine(); } Console.WriteLine("GRID VALID: " + validateTile(bottomRight)); }
private static String getTileFromGrid(String[,] grid, int x, int y) { if (x < grid.GetLowerBound(1) || x > grid.GetUpperBound(1)) { return null; } if (y < grid.GetLowerBound(0) || y > grid.GetUpperBound(0)) { return null; } return getTile(grid[y, x]); }
private static void spread(ITileData tile, int x, int y, String[,] grid) { if (tile == null) { return; } if (x < grid.GetLowerBound(1) || x > grid.GetUpperBound(1)) { return; } if (y < grid.GetLowerBound(0) || y > grid.GetUpperBound(0)) { return; } if (grid[y, x] != "NOT VISITED") { return; } grid[y, x] = tile.getId(); spread(tile.getLeft(), x - 1, y, grid); spread(tile.getRight(), x + 1, y, grid); spread(tile.getUp(), x, y - 1, grid); spread(tile.getDown(), x, y + 1, grid); }