コード例 #1
0
ファイル: PackedExponentTape.cs プロジェクト: nerai/Nibbler
        public int?SuggestMacroSizeEx()
        {
            const bool print = false;

            if (print)
            {
                Log.Write("Searching best macro size for " + this);
            }
            var results = new Dictionary <int, int> ();

            for (int macro = 1; macro <= 8; macro++) // todo check gamma, make sure its still in 1 byte
            {
                byte previous = 0;                   // 0 intentional, refers to empty tape.
                int  nCells   = 0;

                foreach (var block in TapeContent(macro))
                {
                    var enc = Macro.EncodeAny(block);
                    if (enc != previous)
                    {
                        nCells++;
                        previous = enc;
                    }
                }

                results.Add(macro, nCells + macro);                  // Larger macro sizes should be used more rarely
            }

            var best = results
                       .OrderBy(x => x.Value)
                       .ThenBy(x => x.Key)
                       .First();

            if (print)
            {
                Log.WriteLine(best.Key + " (" + best.Value + " cells)");
            }

            return(best.Key);
        }