コード例 #1
0
        /// <summary>
        /// Reads a solution tree from a text file.
        /// </summary>
        /// TODO: has side effects, should be reprogrammed -- Seu
        /// <returns></returns>
        private CCTrie LoadTree()
        {
            var file = Resources.Load <TextAsset>(dataFile);

            if (file == null)
            {
                return(null);
            }

            var tree = new CCTrie(solved);

            int numBeforeHardest = puzzleMoves == 1 ? 0 : puzzlesPerLevel.Take(puzzleMoves - 1).Aggregate((ppl, sum) => ppl + sum);

            var initialStates = new List <PuzzleState>();

            int read      = 0;
            int first     = Sided ? 1 : 0;
            int numPieces = solved.Count;

            string[] leaves = file.text.Split('\n');
            foreach (var leaf in leaves)
            {
                string str = leaf.Trim();
                if (str.Length == 0)
                {
                    continue;
                }
                PuzzleState cc   = PuzzleState.FromCompactString(str.Substring(first, numPieces), solved.numColors, Sided);
                Move        move = Move.FromChar(str[first + numPieces]);
                tree.Add(cc, move);

                if (read >= numBeforeHardest && read < numBeforeHardest + puzzlesPerLevel[puzzleMoves - 1])
                {
                    initialStates.Add(cc);
                }
                read++;
            }

            if (initialStates.Count == 0)
            {
                Debug.LogErrorFormat("No initial states from Tree on level {0}", this.Ref);
            }

            InitialConfigs = initialStates.ToArray();

            return(tree);
        }
コード例 #2
0
        public void Init(bool forceLoadTree = false)
        {
            if (initialized)
            {
                return;
            }

            if (!Application.isMobilePlatform || forceLoadTree || this.forceLoadTree)
            {
                tree = LoadTree();
            }

            if (tree == null && !tutorialLevel)
            {
                var configs = ReadConfigs(this);
                if (configs == null)   // cannot initialize
                {
                    return;
                }
                InitialConfigs = configs.ToArray();
            }

            initialized = true;
        }