public bool Equals(SearchNode p) { return(p.xx == xx && p.yy == yy); }
public int dist(SearchNode other) { return(Math.Abs(xx - other.xx) + Math.Abs(yy - other.yy)); }
public void changeWidth(int newWidth, Random rng) { this.width = newWidth; int width = objects["blocks"].GetLength(0); int height = objects["blocks"].GetLength(1); double[,] newBlock = new double[newWidth, height]; double[,] newEnemies = new double[newWidth, height]; double[,] newKeys = new double[newWidth, height]; double[,] newKeyItems = new double[newWidth, height]; double[,] newItems = new double[newWidth, height]; double[,] newPuzzles = new double[newWidth, height]; double[,] newTraps = new double[newWidth, height]; double[,] newWater = new double[newWidth, height]; double[,] newTeleporters = new double[newWidth, height]; int widthDiff = newWidth - width; List <SearchNode> optimalPath = getPath(nodes[width / 2, 0], nodes[width / 2, height - 1], getScore, rng); SearchNode[] duplicatedPoints = new SearchNode[height]; foreach (SearchNode node in optimalPath) { if (duplicatedPoints[node.yy] == null) { duplicatedPoints[node.yy] = node; } } for (int ii = 0; ii < width; ii++) { for (int jj = 0; jj < height; jj++) { if (ii < duplicatedPoints[jj].xx) { newBlock[ii, jj] = objects["blocks"][ii, jj]; newEnemies[ii, jj] = objects["enemies"][ii, jj]; newKeys[ii, jj] = objects["keys"][ii, jj]; newKeyItems[ii, jj] = objects["keyItems"][ii, jj]; newItems[ii, jj] = objects["items"][ii, jj]; newPuzzles[ii, jj] = objects["puzzles"][ii, jj]; newTraps[ii, jj] = objects["traps"][ii, jj]; newWater[ii, jj] = objects["water"][ii, jj]; newTeleporters[ii, jj] = objects["teleporters"][ii, jj]; } else if (ii > duplicatedPoints[jj].xx) { newBlock[ii + widthDiff, jj] = objects["blocks"][ii, jj]; newEnemies[ii + widthDiff, jj] = objects["enemies"][ii, jj]; newKeys[ii + widthDiff, jj] = objects["keys"][ii, jj]; newKeyItems[ii + widthDiff, jj] = objects["keyItems"][ii, jj]; newItems[ii + widthDiff, jj] = objects["items"][ii, jj]; newPuzzles[ii + widthDiff, jj] = objects["puzzles"][ii, jj]; newTraps[ii + widthDiff, jj] = objects["traps"][ii, jj]; newWater[ii + widthDiff, jj] = objects["water"][ii, jj]; newTeleporters[ii + widthDiff, jj] = objects["teleporters"][ii, jj]; } else { for (int xx = 0; xx <= widthDiff; xx++) { newBlock[ii + xx, jj] = objects["blocks"][duplicatedPoints[jj].xx, jj]; newEnemies[ii + xx, jj] = objects["enemies"][duplicatedPoints[jj].xx, jj]; newKeys[ii, jj] = objects["keys"][duplicatedPoints[jj].xx, jj]; newKeyItems[ii + xx, jj] = objects["keyItems"][duplicatedPoints[jj].xx, jj]; newItems[ii + xx, jj] = objects["items"][duplicatedPoints[jj].xx, jj]; newPuzzles[ii + xx, jj] = objects["puzzles"][duplicatedPoints[jj].xx, jj]; newTraps[ii + xx, jj] = objects["traps"][duplicatedPoints[jj].xx, jj]; newWater[ii + xx, jj] = objects["water"][duplicatedPoints[jj].xx, jj]; newTeleporters[ii + xx, jj] = objects["teleporters"][duplicatedPoints[jj].xx, jj]; } } } } objects["blocks"] = newBlock; objects["water"] = newWater; objects["teleporters"] = newTeleporters; objects["puzzles"] = newPuzzles; objects["traps"] = newTraps; objects["keyItems"] = newKeyItems; objects["items"] = newItems; objects["keys"] = newKeys; objects["enemies"] = newEnemies; nodes = new SearchNode[newWidth, height]; for (int ii = 0; ii < newWidth; ii++) { for (int jj = 0; jj < height; jj++) { nodes[ii, jj] = new SearchNode(ii, jj); } } }
public void changeHeight(int newHeight, Random rng) { this.height = newHeight; int width = objects["blocks"].GetLength(0); int height = objects["blocks"].GetLength(1); double[,] newBlock = new double[width, newHeight]; double[,] newEnemies = new double[width, newHeight]; double[,] newKeys = new double[width, newHeight]; double[,] newKeyItems = new double[width, newHeight]; double[,] newItems = new double[width, newHeight]; double[,] newPuzzles = new double[width, newHeight]; double[,] newTraps = new double[width, newHeight]; double[,] newWater = new double[width, newHeight]; double[,] newTeleporters = new double[width, newHeight]; int heightDiff = newHeight - height; List <SearchNode> optimalPath = getPath(nodes[0, height / 2], nodes[width - 1, height / 2], getScore, rng); SearchNode[] duplicatedPoints = new SearchNode[width]; foreach (SearchNode node in optimalPath) { if (duplicatedPoints[node.xx] == null) { duplicatedPoints[node.xx] = node; } } for (int ii = 0; ii < width; ii++) { for (int jj = 0; jj < height; jj++) { if (jj < duplicatedPoints[ii].yy) { newBlock[ii, jj] = objects["blocks"][ii, jj]; newEnemies[ii, jj] = objects["enemies"][ii, jj]; newKeys[ii, jj] = objects["keys"][ii, jj]; newKeyItems[ii, jj] = objects["keyItems"][ii, jj]; newItems[ii, jj] = objects["items"][ii, jj]; newPuzzles[ii, jj] = objects["puzzles"][ii, jj]; newTraps[ii, jj] = objects["traps"][ii, jj]; newWater[ii, jj] = objects["water"][ii, jj]; newTeleporters[ii, jj] = objects["teleporters"][ii, jj]; } else if (jj > duplicatedPoints[ii].yy) { newBlock[ii, jj + heightDiff] = objects["blocks"][ii, jj]; newEnemies[ii, jj + heightDiff] = objects["enemies"][ii, jj]; newKeys[ii, jj + heightDiff] = objects["keys"][ii, jj]; newKeyItems[ii, jj + heightDiff] = objects["keyItems"][ii, jj]; newItems[ii, jj + heightDiff] = objects["items"][ii, jj]; newPuzzles[ii, jj + heightDiff] = objects["puzzles"][ii, jj]; newTraps[ii, jj + heightDiff] = objects["traps"][ii, jj]; newWater[ii, jj + heightDiff] = objects["water"][ii, jj]; newTeleporters[ii, jj + heightDiff] = objects["teleporters"][ii, jj]; } else { for (int yy = 0; yy <= heightDiff; yy++) { newBlock[ii, jj + yy] = objects["blocks"][ii, duplicatedPoints[ii].yy]; newEnemies[ii, jj + yy] = objects["enemies"][ii, duplicatedPoints[ii].yy]; newKeys[ii, jj + yy] = objects["keys"][ii, duplicatedPoints[ii].yy]; newKeyItems[ii, jj + yy] = objects["keyItems"][ii, duplicatedPoints[ii].yy]; newItems[ii, jj + yy] = objects["items"][ii, duplicatedPoints[ii].yy]; newPuzzles[ii, jj + yy] = objects["puzzles"][ii, duplicatedPoints[ii].yy]; newTraps[ii, jj + yy] = objects["traps"][ii, duplicatedPoints[ii].yy]; newWater[ii, jj + yy] = objects["water"][ii, duplicatedPoints[ii].yy]; newTeleporters[ii, jj + yy] = objects["teleporters"][ii, duplicatedPoints[ii].yy]; } } } } objects["blocks"] = newBlock; objects["water"] = newWater; objects["teleporters"] = newTeleporters; objects["puzzles"] = newPuzzles; objects["traps"] = newTraps; objects["keyItems"] = newKeyItems; objects["items"] = newItems; objects["keys"] = newKeys; objects["enemies"] = newEnemies; nodes = new SearchNode[width, newHeight]; for (int ii = 0; ii < width; ii++) { for (int jj = 0; jj < newHeight; jj++) { nodes[ii, jj] = new SearchNode(ii, jj); } } }
public bool[][] GetReachability(Random rand) { nodes = new SearchNode[width, height]; for (int ii = 0; ii < width; ii++) { for (int jj = 0; jj < height; jj++) { nodes[ii, jj] = new SearchNode(ii, jj); } } bool[] doors = new bool[4]; for (int ii = 0; ii < 4; ii++) { doors[ii] = true; } foreach (var type in objects.Values) { doors[0] = doors[0] && type[0, 5] < 0.5f && type[0, 6] < 0.5f; doors[1] = doors[1] && type[width - 1, 5] < 0.5f && type[width - 1, 6] < 0.5f; doors[2] = doors[2] && type[4, height - 1] < 0.5f && type[5, height - 1] < 0.5f; doors[3] = doors[3] && type[4, 0] < 0.5f && type[5, 0] < 0.5f; } int[][] doorLocs = new int[4][]; doorLocs[0] = new int[] { 0, 5 }; doorLocs[1] = new int[] { width - 1, 5 }; doorLocs[2] = new int[] { 4, height - 1 }; doorLocs[3] = new int[] { 4, 0 }; bool[][] reachabilityTable = new bool[4][]; for (int ii = 0; ii < 4; ii++) { reachabilityTable[ii] = new bool[4]; } for (int ii = 0; ii < 4; ii++) { for (int jj = ii; jj < 4; jj++) { reachabilityTable[ii][jj] = doors[ii] && doors[jj]; reachabilityTable[jj][ii] = doors[ii] && doors[jj]; if (reachabilityTable[ii][jj]) { List <SearchNode> path = getPath(nodes[doorLocs[ii][0], doorLocs[ii][1]], nodes[doorLocs[jj][0], doorLocs[jj][1]], getBlocked, rand); foreach (var node in path) { if (objects["blocks"][node.xx, node.yy] > 0.5f) { reachabilityTable[ii][jj] = false; reachabilityTable[jj][ii] = false; break; } } } } } int bitcount = 0; int bitmask = 0; foreach (var row in reachabilityTable) { foreach (var d in row) { if (d) { bitmask += (int)Math.Pow(2, bitcount); } bitcount++; } } connections = bitmask; return(reachabilityTable); }