Example #1
0
        // Get max possible reduce group level
        // true - reducing possible in base pyramids level
        // false - reducing is not possible
        public bool IsReducingPossible()
        {
            bool res = true;

            // if we have sub pyramides, get patterns of this pyramids
            if (Top4CellPyramid != null)
            {
                res = res && Top4CellPyramid.IsReducingPossible();
                res = res && BottomLeft4CellPyramid.IsReducingPossible();
                res = res && BottomUpside4CellPyramid.IsReducingPossible();
                res = res && BottomRight4CellPyramid.IsReducingPossible();
            }
            else
            {
                res = ((TopValue == BottomLeftValue) && (TopValue == BottomUpsideValue) && (TopValue == BottomRightValue));
            }
            return(res);
        }
Example #2
0
        static void Main(string[] args)
        {
            if (args.Length == 0)
            {
                Console.WriteLine("Error: There are on input arguments.");
                Console.ReadLine();
                return;
            }

            String sSource = args[0];

            Console.WriteLine("tribit.exe {0}", sSource);

            // Input data checking. If input data is invalid, then exit
            if (!CheckSourceData(sSource))
            {
                Console.ReadLine();
                return;
            }

            // In case of 1 cell pyramid just print it and exit
            if (sSource.Length == 1)
            {
                Console.WriteLine("{0}", sSource);
                Console.ReadLine();
                return;
            }

            // Initialize entire pyramid
            PyramidClass Pyramid = new PyramidClass(sSource);

            // Print this pyramid
            Console.WriteLine("{0}", Pyramid.GetString());

            FourCellPyramid TopPyramid = Pyramid.TopPyramid;

            // Transition iteration process
            while (true)
            {
                // Make transition step
                TopPyramid.DoTransition();

                // Print pyramid on current step
                Console.WriteLine("{0}", Pyramid.GetString());

                // Check pyramid for posibility of reducing it
                if (TopPyramid.IsReducingPossible())
                {
                    // if reduce possible, do it
                    TopPyramid.Reduce(true);

                    // the changes
                    // after reducing of the pyramid we must redefine line levels for cells
                    TopPyramid.DefLineLevels(0);

                    // Print pyramid just after reducing
                    Console.WriteLine("{0}", Pyramid.GetString());
                }

                // if pattern of root pyramid is definded, then reduce this root pyramid and finish algorithm
                if ((TopPyramid.PyramidLevel <= 1) && TopPyramid.IsReducingPossible())
                {
                    int value = TopPyramid.TopValue ? 1 : 0;
                    Console.WriteLine("{0}", value);
                    break;
                }
            }

            Console.ReadLine();
            return;
        }