static bool Depthsearch(Matchspace space, Stack <SwapPair> path) { foreach (SwapPair step in PossibleSwaps(space)) { step.Swap(); space.Step(); path.Push(step); if (space.IsSolvable() && Depthsearch(space, path)) { break; } else { path.Pop().Swap(); space.Step(); } } return(space.InEquilibrium()); }
public override Matchspace Generate() { int count = 0; Matchspace space = Matchspace.Create(spaceSize); do { count++; Randomize(space); space.Step(); } while (!EquilibriumFinder.Search(space)); Debug.Log("Iterations until solution found: " + count); return(space); }
public override Matchspace Generate() { Vector3Int size = new Vector3Int(typeMap.width, typeMap.height, typeMap.depth); Matchspace space = Matchspace.Create(size); int[,,] types = typeMap.GetTypes(); for (int x = 0; x < space.width; x++) { for (int y = 0; y < space.height; y++) { for (int z = 0; z < space.depth; z++) { space.grid[x, y, z].type = types[x, y, z]; } } } space.Step(); return(space); }
public static bool Search(Matchspace space, out List <SwapPair> steps) { Stack <SwapPair> path = new Stack <SwapPair>(); if (Depthsearch(space, path)) { steps = path.ToList(); steps.Reverse(); while (path.Count > 0) { path.Pop().Swap(); space.Step(); } return(true); } else { steps = null; return(false); } }