Exemple #1
0
        public static void Test2()
        {
            TtcPendulum initialPendulum = new TtcPendulum(null);

            for (int i = 0; i <= 288; i++)
            {
                bool swungThroughZero = initialPendulum.PerformSwing(i % 2 == 0);
                Config.Print(i + ": " + StringUtilities.FormatIntegerWithSign((int)initialPendulum._angle) + " " + swungThroughZero);
            }
            for (int i = 0; true; i++)
            {
                bool swungThroughZero = initialPendulum.PerformSwing(true);
                Config.Print(i + ": " + StringUtilities.FormatIntegerWithSign((int)initialPendulum._angle) + " " + swungThroughZero);
                if (initialPendulum._angle == 33578192)
                {
                    break;
                }
            }

            TtcPendulum testPendulum = (TtcPendulum)initialPendulum.Clone(null);

            for (int i = 0; i < Solution.Count; i++)
            {
                bool b = Solution[i];
                testPendulum.PerformSwing(b);
                Config.Print(i + ": " + StringUtilities.FormatIntegerWithSign((int)testPendulum._angle) + " " + testPendulum._angle);
            }
        }
Exemple #2
0
 public PendulumPossibility(
     TtcPendulum pendulum,
     List <bool> boolPermutation,
     PendulumPossibility predecessor)
 {
     Pendulum        = pendulum;
     BoolPermutation = boolPermutation;
     Predecessor     = predecessor;
 }
Exemple #3
0
        public static void Test()
        {
            TtcPendulum initialPendulum = new TtcPendulum(null);

            for (int i = 0; i <= 288; i++)
            {
                bool swungThroughZero = initialPendulum.PerformSwing(i % 2 == 0);
                Config.Print(i + ": " + StringUtilities.FormatIntegerWithSign((int)initialPendulum._angle) + " " + swungThroughZero);
            }
            for (int i = 0; true; i++)
            {
                bool swungThroughZero = initialPendulum.PerformSwing(true);
                Config.Print(i + ": " + StringUtilities.FormatIntegerWithSign((int)initialPendulum._angle) + " " + swungThroughZero);
                if (initialPendulum._angle == 33578192)
                {
                    break;
                }
            }

            int numSaved = 5;
            PendulumPossibility        initialPossibility = new PendulumPossibility(initialPendulum, new List <bool>(), null);
            List <PendulumPossibility> bestPossibilities  = new List <PendulumPossibility>()
            {
                initialPossibility
            };

            for (int i = 0; true; i++)
            {
                List <PendulumPossibility> nextPossilbiites = bestPossibilities.ConvertAll(
                    possibility => GetNextPendulumPossibilities(possibility)).SelectMany(list => list).ToList();
                bestPossibilities.Clear();
                bestPossibilities.AddRange(GetBestPossibilities(nextPossilbiites, numSaved));

                if (Math.Abs(bestPossibilities[0].Pendulum._angle) > int.MaxValue)
                {
                    break;
                }

                for (int j = 0; j < numSaved; j++)
                {
                    float angle = bestPossibilities[j].Pendulum._angle;
                    Config.Print("{0}: {1} {2}", i, StringUtilities.FormatIntegerWithSign((int)angle), angle / int.MaxValue);
                }
            }
            List <bool> totalBoolPermutation = GetTotalBoolPermutation(bestPossibilities[0]);

            Config.Print(string.Join("\r\n", totalBoolPermutation));
        }
Exemple #4
0
        public static List <PendulumPossibility> GetNextPendulumPossibilities(PendulumPossibility possibility)
        {
            List <PendulumPossibility> output = new List <PendulumPossibility>();

            foreach (List <bool> boolPermuation in BoolPermuations)
            {
                TtcPendulum pendulum = (TtcPendulum)possibility.Pendulum.Clone(null);
                foreach (bool b in boolPermuation)
                {
                    pendulum.PerformSwing(b);
                }
                PendulumPossibility nextPossibility = new PendulumPossibility(pendulum, boolPermuation, possibility);
                output.Add(nextPossibility);
            }
            return(output);
        }
            public List<int> GetIntermediateAngles()
            {
                int accelerationDirection = -1 * MoreMath.Sign(Amplitude);
                int angularVelocity = 0;
                int waitingTimer = 0;
                TtcPendulum pendulum = new TtcPendulum(new TtcRng(0), accelerationDirection, Amplitude, angularVelocity, Acceleration, waitingTimer);

                List<int> intermediateAngles = new List<int>();
                intermediateAngles.Add(pendulum._angle);
                while (true)
                {
                    pendulum.Update();
                    intermediateAngles.Add(pendulum._angle);
                    if (pendulum._angularVelocity == 0) break;
                }
                return intermediateAngles;
            }