Пример #1
0
        public static int CalculateIndex(Cube cube, PruneTable prune)
        {
            int index = 0, product = 1;

            byte[] type;
            switch (prune.name)
            {
            case "CO":
                type = cube.CO;
                break;

            case "CP":
                type = cube.CP;
                break;

            case "EO":
                type = cube.EO;
                break;

            //case "EP":
            //    type = cube.EP;
            //    break;
            default:
                return(-1);
            }
            for (int i = 0; i < prune.arraySize; i++)
            {
                index   += (type[i] * product); //type[i] * n^i
                product *= prune.indexBase;
            }
            return(index);
        }
Пример #2
0
        public static void CreatePruningTable(string pruneName)
        {
            PruneTable prune = new PruneTable(pruneName);

            pruneDict.Add(pruneName, prune);
            Console.WriteLine("Creating pruning table: " + prune.name);
            for (byte depth = 0; prune.table.Count() < prune.maxCount && depth <= 20; depth++)
            {
                Cube cube = new Cube();
                if (DoAllTheMoves(cube, depth, 18, 19, prune, depth))
                {
                    break;
                }
            }
        }
Пример #3
0
 private static bool DoAllTheMoves(Cube cube, byte depth, byte prevMove, byte prevPrevMove, PruneTable prune, byte startDepth)
 {
     if (depth == 0)     //all moves done on all depths
     {
         if (prune.table.Count() < prune.maxCount)
         {
             int index = CalculateIndex(cube, prune);
             prune.AddIndex(index, startDepth);      //adds if not already added
             return(false);
         }
         else
         {
             return(true);    //done! all indices found
         }
     }
     else
     {
         for (byte move = 0; move < 18; move++)   //go through all moves
         {
             if (Algorithm.IsAllowedMove(move, prevMove, prevPrevMove))
             {
                 Cube newCube = new Cube(cube);
                 Algorithm.DoMove(newCube, move);
                 if (DoAllTheMoves(newCube, (byte)(depth - 1), move, prevMove, prune, startDepth))
                 {
                     return(true);
                 }
             }
         }
     }
     return(false);
 }