示例#1
0
        void Randomize(Matchspace space)
        {
            List <int> types = new List <int>();

            for (int b = 0; b < buckets.Length; b++)
            {
                for (int i = 0; i < buckets[b]; i++)
                {
                    types.Add(b);
                }
            }
            for (int i = types.Count - 1; i > 0; i--)
            {
                int buffer = types[i];
                int random = types[Random.Range(0, i)];
                types[i]      = types[random];
                types[random] = buffer;
            }
            int count = 0;

            foreach (Matchable match in space.grid)
            {
                if (count < types.Count)
                {
                    match.type = types[count];
                    count++;
                }
                else
                {
                    match.type = -1;
                }
            }
        }
示例#2
0
 public void StartLevel(int index)
 {
     this.index = index;
     if (currentLevel)
     {
         Destroy(currentLevel.gameObject);
     }
     currentLevel = levels[index].Generate();
     onLevelStart?.Invoke(currentLevel);
     levelActive = true;
 }
示例#3
0
        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);
        }
示例#4
0
        public override Matchspace Generate()
        {
            Matchspace space = Matchspace.Create(spaceSize);

            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 = (x + y + z) % types;
                    }
                }
            }
            return(space);
        }
示例#5
0
        static IEnumerable <SwapPair> PossibleSwaps(Matchspace space)
        {
            var surfaceNoMatch = from Matchable match in space.grid
                                 where !match.Hidden() && !match.AnyMatch()
                                 select match;

            foreach (Matchable first in surfaceNoMatch.Where(first => first.AnyAlmost()))
            {
                foreach (Matchable second in surfaceNoMatch)
                {
                    if (SwapPair.MatchingSwap(first, second))
                    {
                        yield return(new SwapPair(first, second));
                    }
                }
            }
        }
示例#6
0
        public static void SaveToTypeMap(Matchspace space)
        {
            if (!Directory.Exists(SAVE_FOLDER))
            {
                Directory.CreateDirectory(SAVE_FOLDER);
            }
            int count = 0;

            while (File.Exists(SAVE_FOLDER + fileName + count + ".json"))
            {
                count++;
            }
            TypeMap saveMap = new TypeMap(space);
            string  json    = JsonUtility.ToJson(saveMap);

            Debug.Log("Saving to: " + SAVE_FOLDER);
            File.WriteAllText(SAVE_FOLDER + fileName + count + ".json", json);
        }
示例#7
0
 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());
 }
示例#8
0
        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);
        }
示例#9
0
文件: TypeMap.cs 项目: Roluda/Match3D
        public TypeMap(Matchspace space)
        {
            width  = space.width;
            height = space.height;
            depth  = space.height;
            List <int> typelist = new List <int>();

            for (int x = 0; x < space.width; x++)
            {
                for (int y = 0; y < space.height; y++)
                {
                    for (int z = 0; z < space.depth; z++)
                    {
                        typelist.Add(space.grid[x, y, z].type);
                    }
                }
            }
            types = typelist.ToArray();
        }
示例#10
0
        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);
            }
        }
示例#11
0
 public static bool Search(Matchspace space)
 {
     return(Search(space, out List <SwapPair> list));
 }
示例#12
0
文件: Rotator.cs 项目: Roluda/Match3D
 public void NewTarget(Matchspace target)
 {
     targetObject = target.gameObject;
 }
示例#13
0
 public void ShowSpace(Matchspace space)
 {
     currentLevel = space;
     StartCoroutine(PresentSpace());
 }
示例#14
0
 public void Setup(Matchspace space)
 {
     currentSpace = space;
 }