public void ApplyToMap(Grid3di map, int emptyCode) { map.Resize(w * 3, h * 3, 1); for (int Y = 0; Y < h; Y++) { for (int X = 0; X < w; X++) { Maze.Cell cell = GetAt(X, Y); int x0 = X * 3; int y0 = Y * 3; // fill block for (int y = y0; y < y0 + 3; y++) { for (int x = x0; x < x0 + 3; x++) { map.SetAt(x, y, map.BorderCode); } } // empty field in the center map.SetAt(x0 + 1, y0 + 1, emptyCode); if (cell.right == false) { map.SetAt(x0 + 2, y0 + 1, emptyCode); } if (cell.left == false) { map.SetAt(x0 + 0, y0 + 1, emptyCode); } if (cell.upper == false) { map.SetAt(x0 + 1, y0 + 0, emptyCode); } if (cell.lower == false) { map.SetAt(x0 + 1, y0 + 2, emptyCode); } } } }
static public void TestFunction() { String Map = "##############################" + "# # # #" + "# # ### # # # #" + "# # #aaaaa# # # #" + "# # #aaaaa# # # #" + "# # #aaaaaa # # #" + "# ### ####### # # #" + "# # # #" + "# # # #" + "##############################"; Grid3di map = new Grid3di(); map.Resize(30, 10); map.BorderCode = 99; Dictionary <char, int> valueLookup = new Dictionary <char, int>(); valueLookup['#'] = map.BorderCode; valueLookup[' '] = 0; valueLookup['a'] = 1; map.ParseLayerFromString(Map, valueLookup, 0); Dictionary <int, char> codeLookup = new Dictionary <int, char>(); codeLookup[0] = '='; codeLookup[map.BorderCode] = '@'; codeLookup[1] = 'a'; codeLookup[9] = '*'; // symbol for path map.ShowDebugInfo(codeLookup); List <Vec3di> solution = new List <Vec3di>(); AStarAgent pf = new AStarAgent(); pf.ownPosition = new Vec3di(2, 9, 0); pf.map = map; if (pf.FindPath(new Vec3di(28, 2, 0), solution, false) == AStarSearch.SearchState.SUCCEEDED) { Grid3di copy = new Grid3di(map); int i = 1; foreach (Vec3di step in solution) { //Zentronic.Debug.Log("step " + i + ":" + step.x + "/" + step.y); i++; copy.SetAt(step.x, step.y, step.z, 9); } copy.ShowDebugInfo(codeLookup); } else { Debug.LogError("unable to find path!"); } }