Esempio n. 1
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;
        }
Esempio n. 2
0
 public void DoTransition()
 {
     // if this is value-containing pyramid, process the transition
     // else process the transition of sibling pyramids
     if (Top4CellPyramid == null)
     {
         // Do transition of this pyramid
         String sPattern   = GetStringRepresentation().Substring(0, 4);
         String newPattern = "0000";
         if (sPattern.Equals("0000"))
         {
             newPattern = "0000";
         }
         if (sPattern.Equals("0001"))
         {
             newPattern = "1000";
         }
         if (sPattern.Equals("0010"))
         {
             newPattern = "0001";
         }
         if (sPattern.Equals("0011"))
         {
             newPattern = "0010";
         }
         if (sPattern.Equals("0100"))
         {
             newPattern = "0000";
         }
         if (sPattern.Equals("0101"))
         {
             newPattern = "0010";
         }
         if (sPattern.Equals("0110"))
         {
             newPattern = "1011";
         }
         if (sPattern.Equals("0111"))
         {
             newPattern = "1011";
         }
         if (sPattern.Equals("1000"))
         {
             newPattern = "0100";
         }
         if (sPattern.Equals("1001"))
         {
             newPattern = "0101";
         }
         if (sPattern.Equals("1010"))
         {
             newPattern = "0111";
         }
         if (sPattern.Equals("1011"))
         {
             newPattern = "1111";
         }
         if (sPattern.Equals("1100"))
         {
             newPattern = "1101";
         }
         if (sPattern.Equals("1101"))
         {
             newPattern = "1110";
         }
         if (sPattern.Equals("1110"))
         {
             newPattern = "0111";
         }
         if (sPattern.Equals("1111"))
         {
             newPattern = "1111";
         }
         SetStringRepresentation(newPattern); // save transitioned value back to the pyramid
     }
     else
     {
         if (Top4CellPyramid != null)
         {
             Top4CellPyramid.DoTransition();
         }
         if (BottomLeft4CellPyramid != null)
         {
             BottomLeft4CellPyramid.DoTransition();
         }
         if (BottomUpside4CellPyramid != null)
         {
             BottomUpside4CellPyramid.DoTransition();
         }
         if (BottomRight4CellPyramid != null)
         {
             BottomRight4CellPyramid.DoTransition();
         }
     }
 }