public void DefLineLevels(int aBaseLevel) { // if it's 0-level (values containing) pyramid set next free line level to TopLineLevel if (Top4CellPyramid == null) { TopLineLevel = aBaseLevel; BottomLineLevel = aBaseLevel + 1; } else { int BottomPartBaseLevel = aBaseLevel + (int)Math.Pow(2, PyramidLevel - 1); if (GetActualUpside()) { BottomLeft4CellPyramid.DefLineLevels(aBaseLevel); BottomUpside4CellPyramid.DefLineLevels(aBaseLevel); BottomRight4CellPyramid.DefLineLevels(aBaseLevel); Top4CellPyramid.DefLineLevels(BottomPartBaseLevel); } else { Top4CellPyramid.DefLineLevels(aBaseLevel); BottomLeft4CellPyramid.DefLineLevels(BottomPartBaseLevel); BottomUpside4CellPyramid.DefLineLevels(BottomPartBaseLevel); BottomRight4CellPyramid.DefLineLevels(BottomPartBaseLevel); } } }
public PyramidClass(String aSource) { source = aSource; int len = source.Length; MaxLines = 1; MaxPyrLevel = 0; while (len > 1) { len = len / 4; MaxLines *= 2; MaxPyrLevel++; } MaxLines--; // Initializing top 4 cell pyramid TopPyramid = new FourCellPyramid(null, MaxPyrLevel, false); // defining line levels cells TopPyramid.DefLineLevels(0); // Filling pyramid from input string FillFromString(aSource); }
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; }