Esempio n. 1
0
        static void Main(string[] args)
        {
            WhatToTest condition = WhatToTest.NumberOfNumToOneRow;

            //TestSeeds(WhatToTest.NumberOfNumToOneRow, 500, 500);
            //TestSeeds(WhatToTest.NumberOfNumToPlate, 500, 500);
            TestAmountOfPlatesWithBingoAtOnce(500, 500);
        }
Esempio n. 2
0
        private void Update()
        {
            var currentSpeed = Dynamics.Velocity.magnitude;

            if (seq == null)
            {
                stage = Stage.End;
            }

            if (stage == Stage.End)
            {
                return;
            }

            if (firstRun && seq != null)
            {
                state    = States[seq.Value];
                duration = States[seq.Value].duration;

                state.throttle = state.throttle * 0.01f;
                state.brakes   = state.brakes * 0.01f;
                state.steering = state.steering * 0.01f;

                upperBound  = States[seq.Value].max_velocity * 0.9f;
                lowerBound  = States[seq.Value].min_velocity * 1.1f;
                maxVelocity = States[seq.Value].max_velocity;
                minVelocity = States[seq.Value].min_velocity;
                AccelInput  = 0f;
                SteerInput  = 0f;

                if (States[seq.Value].gear == "forward")
                {
                    whatToTest = (States[seq.Value].throttle > 0) ? WhatToTest.ForwardThrottle
                        : (States[seq.Value].brakes > 0) ? WhatToTest.ForwardBrake : WhatToTest.None;
                }
                else if (States[seq.Value].gear == "reverse")
                {
                    whatToTest = (States[seq.Value].throttle > 0) ? WhatToTest.ReverseThrottle
                        : (States[seq.Value].brakes > 0) ? WhatToTest.ReverseBrake : WhatToTest.None;
                }

                firstRun = false;
            }

            if (stage == Stage.Init)
            {
                if (whatToTest == WhatToTest.ForwardThrottle || whatToTest == WhatToTest.ForwardBrake)
                {
                    if (whatToTest == WhatToTest.ForwardThrottle && velocityState == VelocityState.Decreasing)
                    {
                        AccelInput = -1.0f;
                        if (currentSpeed < lowerBound)
                        {
                            stage         = Stage.Apply;
                            StartTime     = Time.time;
                            velocityState = VelocityState.Stay;
                            AccelInput    = state.throttle - state.brakes;
                            idxApply      = 0;
                        }
                    }
                    else if (whatToTest == WhatToTest.ForwardThrottle && velocityState == VelocityState.Increasing)
                    {
                        AccelInput = 1.0f;
                        if (currentSpeed > lowerBound && currentSpeed < upperBound)
                        {
                            stage         = Stage.Apply;
                            StartTime     = Time.time;
                            velocityState = VelocityState.Stay;
                            AccelInput    = state.throttle - state.brakes;
                            idxApply      = 0;
                        }
                    }

                    if (whatToTest == WhatToTest.ForwardBrake && velocityState == VelocityState.Decreasing)
                    {
                        AccelInput = -1.0f;
                        if (currentSpeed < upperBound && currentSpeed > lowerBound)
                        {
                            stage         = Stage.Apply;
                            StartTime     = Time.time;
                            velocityState = VelocityState.Stay;
                            AccelInput    = state.throttle - state.brakes;
                            idxApply      = 0;
                        }
                    }
                    else if (whatToTest == WhatToTest.ForwardBrake && velocityState == VelocityState.Increasing)
                    {
                        AccelInput = 1.0f;
                        if (currentSpeed > upperBound)
                        {
                            stage         = Stage.Apply;
                            StartTime     = Time.time;
                            velocityState = VelocityState.Stay;
                            AccelInput    = state.throttle - state.brakes;
                            idxApply      = 0;
                        }
                    }
                }
                else if (whatToTest == WhatToTest.ReverseThrottle || whatToTest == WhatToTest.ReverseBrake)
                {
                    if (Dynamics.Reverse == true)
                    {
                        if (whatToTest == WhatToTest.ReverseThrottle || whatToTest == WhatToTest.ReverseBrake)
                        {
                            if (whatToTest == WhatToTest.ReverseThrottle && velocityState == VelocityState.Decreasing)
                            {
                                AccelInput = -1.0f;
                                if (currentSpeed < lowerBound)
                                {
                                    stage         = Stage.Apply;
                                    StartTime     = Time.time;
                                    velocityState = VelocityState.Stay;
                                    AccelInput    = state.throttle - state.brakes;
                                    idxApply      = 0;
                                }
                            }
                            else if (whatToTest == WhatToTest.ReverseThrottle && velocityState == VelocityState.Increasing)
                            {
                                AccelInput = 1.0f;
                                if (currentSpeed > lowerBound && currentSpeed < upperBound)
                                {
                                    stage         = Stage.Apply;
                                    StartTime     = Time.time;
                                    velocityState = VelocityState.Stay;
                                    AccelInput    = state.throttle - state.brakes;
                                    idxApply      = 0;
                                }
                            }

                            if (whatToTest == WhatToTest.ReverseBrake && velocityState == VelocityState.Decreasing)
                            {
                                AccelInput = -1.0f;
                                if (currentSpeed < upperBound && currentSpeed > lowerBound)
                                {
                                    stage         = Stage.Apply;
                                    StartTime     = Time.time;
                                    velocityState = VelocityState.Stay;
                                    AccelInput    = state.throttle - state.brakes;
                                    idxApply      = 0;
                                }
                            }
                            else if (whatToTest == WhatToTest.ReverseBrake && velocityState == VelocityState.Increasing)
                            {
                                AccelInput = 1.0f;
                                if (currentSpeed > upperBound)
                                {
                                    stage         = Stage.Apply;
                                    StartTime     = Time.time;
                                    velocityState = VelocityState.Stay;
                                    AccelInput    = state.throttle - state.brakes;
                                    idxApply      = 0;
                                }
                            }
                        }
                    }
                    else
                    {
                        Dynamics.ShiftReverseAutoGearBox();
                    }
                }
            }
            else if (stage == Stage.Apply)
            {
                idxApply++;
                ElapsedTime = Time.time - StartTime;
                AccelInput  = state.throttle - state.brakes;
                SteerInput  = -state.steering;

                if (ElapsedTime > duration)
                {
                    stage       = Stage.DeInit;
                    ElapsedTime = 0f;
                }

                else if (currentSpeed > maxVelocity || currentSpeed < minVelocity)
                {
                    stage       = Stage.Init;
                    duration    = duration - ElapsedTime;
                    ElapsedTime = 0f;

                    if (currentSpeed > maxVelocity)
                    {
                        velocityState = VelocityState.Decreasing;
                        AccelInput    = 0f;
                        SteerInput    = 0f;
                    }
                    else if (currentSpeed < minVelocity)
                    {
                        velocityState = VelocityState.Increasing;
                        AccelInput    = 0f;
                        SteerInput    = 0f;
                    }
                }
            }

            else if (stage == Stage.DeInit)
            {
                AccelInput = -0.8f;
                SteerInput = 0f;

                if (currentSpeed < 0.5f)
                {
                    stage         = Stage.Init;
                    velocityState = VelocityState.Increasing;
                    seq           = (seq < States.Count - 1) ? seq + 1 : null;
                    firstRun      = true;
                }
            }

            //// Every 0.1 sec, it prints out debug msg.
            //if ((int)((Time.time - StartTime) * 10.0f) % 10 == 0)
            //{
            //    Debug.Log($"seq: {seq.Value}/{states.Count}, idxApply: {idxApply.Value}, stage: {stage.ToString()}, ElapsedTime: " +
            //            $"{ElapsedTime}, Duration: {duration}, curr_v: " +
            //            $"{currentSpeed} [max_v: {state.max_velocity}," +
            //            $" min_v: {state.min_velocity}, upper_v: {upperBound}, lower_v: {lowerBound}] AccelInput: {AccelInput} " +
            //            $"[throttle: {state.throttle}, brakes: {state.brakes}], " +
            //            $"SteerInput: {SteerInput} steer: [{state.steering}], gear: " +
            //            $"{dynamics.CurrentGear} [{state.gear}], whatToTest: {whatToTest}, " +
            //            $"velocityState: {velocityState}");
            //}
        }
Esempio n. 3
0
        private static void TestSeeds(WhatToTest condition, int AmountOfSeedsToTest, int PlatesPerEvent)
        {
            var random = new Random();

            if (condition == WhatToTest.NumberOfNumToOneRow)
            {
                using (CsvFileWriter writer = new CsvFileWriter("TestOfOneRow.csv"))
                {
                    CsvRow row = new CsvRow();
                    row.Add("Seed");
                    row.Add("AntalTal");
                    writer.WriteRow(row);
                    for (int i = 0; i < AmountOfSeedsToTest; i++)
                    {
                        BingoEvent TestEvent = new BingoEvent();
                        TestEvent.Initialize(RandomSeed(random), "Test nr." + i, PlatesPerEvent);
                        TestEvent.PInfo.CardList = TestEvent.PInfo.CardGenerator.GenerateCard(TestEvent.PInfo.PlatesGenerated);
                        Random rdnForEvents = new Random();
                        int    numbersNeededForCondition = 0;
                        while (!RunTestEvent(1, TestEvent))
                        {
                            PickRandomNumber(TestEvent, rdnForEvents);
                            numbersNeededForCondition++;
                        }
                        //Write here
                        CsvRow resultRow = new CsvRow();
                        row.Add(TestEvent.SInfo.OriginalSeed);
                        row.Add(numbersNeededForCondition.ToString());
                        writer.WriteRow(row);
                    }
                }
            }
            else if (condition == WhatToTest.NumberOfNumToPlate)
            {
                using (CsvFileWriter writer = new CsvFileWriter("TestOfPlate.csv"))
                {
                    CsvRow row = new CsvRow();
                    row.Add("Seed");
                    row.Add("AntalTal");
                    writer.WriteRow(row);
                    for (int i = 0; i < AmountOfSeedsToTest; i++)
                    {
                        BingoEvent TestEvent = new BingoEvent();
                        TestEvent.Initialize(RandomSeed(random), "Test nr." + i, PlatesPerEvent);
                        TestEvent.PInfo.CardList = TestEvent.PInfo.CardGenerator.GenerateCard(TestEvent.PInfo.PlatesGenerated);
                        Random rdnForEvents = new Random();
                        int    numbersNeededForCondition = 0;
                        while (!RunTestEvent(3, TestEvent))
                        {
                            PickRandomNumber(TestEvent, rdnForEvents);
                            numbersNeededForCondition++;
                        }
                        //Write here
                        CsvRow resultRow = new CsvRow();
                        row.Add(TestEvent.SInfo.OriginalSeed);
                        row.Add(numbersNeededForCondition.ToString());
                        writer.WriteRow(row);
                    }
                }
            }
        }