예제 #1
0
    void Update()
    {
        mUpdateAudioSources = true;

        // Increment timer with realtime.
        mTimer += (Time.deltaTime / Time.timeScale);

        float totalTime = mTimeInPhase + mTimeMainPhase + mTimeOutPhase;

        if (mTimer < mTimeInPhase)
        {
            // IN.
            float factor = mTimer / mTimeInPhase;                              // [0,1]
            mCurrentTimeScale = CustomMath.Slerp(1, mTargetTimeScale, factor); // [1, mTargetTimeScale]
        }
        else if (mTimer < mTimeInPhase + mTimeMainPhase)
        {
            // MAIN.
            mCurrentTimeScale = mTargetTimeScale;
        }
        else
        {
            // OUT.
            float factor = Mathf.Clamp01((mTimer - mTimeInPhase - mTimeMainPhase) / mTimeOutPhase); // [0,1]
            mCurrentTimeScale = CustomMath.Slerp(mTargetTimeScale, 1, factor);                      // [mTargetTimeScale, 1]
        }
    }
예제 #2
0
        public Room(int x, int y)
        {
            int level = Program.ObteJuego().GetLevel();

            this.x = x;
            this.y = y;
            descr  = FileReader.RandomDescr("Text/roomDescr.txt");
            if (!(x == 0 && y == 0))
            {
                double prob = (level < 4) ? 0.1 + 0.3 * level / 4d : 0.4;
                if (CustomMath.RandomUnit() < prob)
                {
                    ene = new Enemigo(Enemigo.eneList[CustomMath.RandomIntNumber(Enemigo.eneList.Length - 1)], (int)Math.Pow(level, 1.2));
                }

                if (CustomMath.RandomUnit() < 0.02)
                {
                    if (CustomMath.RandomUnit() < 0.5)
                    {
                        item[0] = new ItemPocion("Poción de vida", CustomMath.RandomIntNumber(75, 50), ItemPocion.PocionType.hp);
                    }
                    else
                    {
                        item[0] = new ItemPocion("Poción de mana", CustomMath.RandomIntNumber(75, 50), ItemPocion.PocionType.mana);
                    }
                }
            }
        }
예제 #3
0
        private void ExerciseEnd(bool longExercise)
        {
            this.streamWriter.Close( );

            this.isWorking = false;
            this.pointList = CustomMath.DouglasPeuckerReduction(this.pointList, 1.0);

            this.streamWriter = new StreamWriter("dataSmoothed.txt");

            for (int i = 0; i < this.pointList.Count; i++)
            {
                this.streamWriter.WriteLine(this.pointList [i].Y);
            }

            this.streamWriter.Close( );

            bool fastExercise = false;

            if (Constant.GetCurrentMilliTime( ) - exerciseStartTime <= minExerciseTime)
            {
                fastExercise = true;
            }

            this.logic.Result(this.limExcessNum, this.limShortageNum,
                              this.fastWorkNum, this.longWorkNum, fastExercise, longExercise);
        }
예제 #4
0
        protected TSVector DesiredAcc(TSVector goal, out TSVector prefV, out FP factor, out FP time)
        {
            time  = FP.Zero;
            prefV = TSVector.zero;
            TSVector vPref = goal - _behaviour.position;
            FP       mag;

            factor = FP.One;
            vPref  = CustomMath.Normalize(vPref, out mag) * _behaviour.maxSpeed;
            if (mag * mag < GridMap._checkDeltaDstSqr)
            {
                return(TSVector.zero);
            }
            time = mag / _behaviour.maxSpeed;
            //driving force
            prefV = vPref;

            if (_behaviour.velocity == TSVector.zero)
            {
                _behaviour.preVelocity = prefV;
            }
            else
            {
                _behaviour.preVelocity = _behaviour.velocity;
            }
            if (_preVelDirection == TSVector.zero)
            {
                _preVelDirection = prefV * _behaviour.invMaxSpeed;
            }
            factor = _behaviour.baseData.maxForce * _behaviour.invMaxSpeed;
            TSVector desiredF = (vPref - _behaviour.preVelocity) * factor;///_ksi

            return(desiredF * _behaviour.baseData.invMass);
        }
        public void Example1()
        {
            string testData = "1 + 2 * 3 + 4 * 5 + 6";
            long   result   = CustomMath.Parse(testData);

            Assert.AreEqual(71, result);
        }
예제 #6
0
        public void Root_ShouldThrowExceptionWhenRootIsLowerThan1()
        {
            long number = 4;
            int  root   = 0;

            CustomMath.Root(number, root);
        }
예제 #7
0
            private double CalculateCalibrationError(ConversionFactors prediction, List <TickDiffPair> validationSet)
            {
                /* ValidateCalibration
                 * to calculate a distance between close ticks and comparing that to the ground truth distance change.
                 *
                 */
                List <double> errors = new List <double>();

                foreach (TickDiffPair validationPair in validationSet)
                {
                    double pred;
                    if (UseAlt)
                    {
                        pred = Math.Sqrt(Math.Pow(prediction.Lat * validationPair.TickDiff1.mLatDiff, 2) +
                                         Math.Pow(prediction.Long * validationPair.TickDiff1.mLongDiff, 2) +
                                         Math.Pow(validationPair.TickDiff1.mAltDiff, 2));
                    }
                    else
                    {
                        pred = Math.Sqrt(Math.Pow(prediction.Lat * validationPair.TickDiff1.mLatDiff, 2) +
                                         Math.Pow(prediction.Long * validationPair.TickDiff1.mLongDiff, 2));
                    }
                    double relError = Math.Abs((pred - validationPair.TickDiff1.mDist) / validationPair.TickDiff1.mDist);
                    errors.Add(relError);
                }
                return(CustomMath.meanList(errors));
            }
        public void Example4()
        {
            string testData = "5 * 9 * (7 * 3 * 3 + 9 * 3 + (8 + 6 * 4))";
            long   result   = CustomMath.Parse(testData);

            Assert.AreEqual(12240, result);
        }
        public void Example5()
        {
            string testData = "((2 + 4 * 9) * (6 + 9 * 8 + 6) + 6) + 2 + 4 * 2";
            long   result   = CustomMath.Parse(testData);

            Assert.AreEqual(13632, result);
        }
예제 #10
0
        public void Example3()
        {
            string testData = "5 + (8 * 3 + 9 + 3 * 4 * 3)";
            long   result   = CustomMath.Parse(testData);

            Assert.AreEqual(437, result);
        }
예제 #11
0
    public override void Update(float deltaTime)
    {
        Vector3 deltaV = world.player.worldPosition - worldPosition;

        if (deltaV.sqrMagnitude < 10f * 10f)
        {
            MoveTo(new Vector2(deltaV.x, deltaV.z), 50f * deltaTime);
        }

        if (velocity.x != 0f && velocity.z != 0f)
        {
            viewAngle = Mathf.LerpAngle(viewAngle, Mathf.Atan2(velocity.z, velocity.x) * Mathf.Rad2Deg, deltaTime * 10f);
        }

        _entityParts[0].worldPosition = worldPosition + new Vector3(0f, 2f, 0f);
        _entityParts[1].worldPosition = worldPosition + CustomMath.HorizontalRotate(new Vector3(0.8f, 2.2f, 0f), viewAngle + 30f);
        _entityParts[2].worldPosition = worldPosition + CustomMath.HorizontalRotate(new Vector3(0.8f, 2.2f, 0f), viewAngle - 30f);
        _entityParts[3].worldPosition = worldPosition + CustomMath.HorizontalRotate(new Vector3(0.5f, 0.4f, 0.5f), viewAngle);
        _entityParts[4].worldPosition = worldPosition + CustomMath.HorizontalRotate(new Vector3(0.5f, 0.4f, -0.5f), viewAngle);
        _entityParts[5].worldPosition = worldPosition + CustomMath.HorizontalRotate(new Vector3(-0.5f, 0.4f, 0.5f), viewAngle);
        _entityParts[6].worldPosition = worldPosition + CustomMath.HorizontalRotate(new Vector3(-0.5f, 0.4f, -0.5f), viewAngle);

        for (int index = 0; index < _entityParts.Count; index++)
        {
            _entityParts[index].viewAngle = viewAngle;
        }

        base.Update(deltaTime);
    }
예제 #12
0
        public override void Fire(Action onCompleteAction = null)
        {
            for (int i = 0; i < m_BulletCount; i++)
            {
                m_Waitor
                .AppendCallBack(() =>
                {
                    GameObject target = m_TargetGetter();
                    if (target != null)
                    {
                        m_LastDirection = CustomMath.GetNormalizedVectorFromDegree(CustomMath.GetTargetDegree(m_FireTransform.position, target.transform.position));
                    }

                    GameObject bullet = m_BulletManager.SpawnBullet(
                        m_EntityBulletType,
                        m_FireTransform.transform.position,
                        Quaternion.Euler(0, 0, 0),
                        m_MonoBehaviour as EnemyCore,
                        m_BulletSpeed,
                        m_BulletDamage,
                        m_DefaultDirection,
                        m_AllyFlag,
                        selfControlled: true,
                        m_LastDirection);
                })
                .Wait(m_ShotInterval);
            }

            if (onCompleteAction != null)
            {
                m_Waitor.AppendCallBack(onCompleteAction);
            }
            m_Waitor.Run();
        }
예제 #13
0
파일: Level.cs 프로젝트: ktos/Rex-1
        public void DrawCompassBar()
        {
            if (models.Count == 0)
            {
                return;
            }

            foreach (var item in models.OfType <ICollision>().Where(x => x.IsDetected).OrderByDescending(x => DistanceFromCamera(x)))
            {
                var m = item as Model;

                var angle2           = CustomMath.ConvertRadiansToDegrees(CustomMath.SimpleAngleBetweenTwoVectors(ModelRenderer.CameraForward, m.Position - ModelRenderer.CameraPosition));
                var compass_position = (angle2 / 180 * 64) + 64;

                var distance = Math.Sqrt(Math.Pow(m.Position.X - ModelRenderer.CameraPosition.X, 2) + Math.Pow(m.Position.Y - ModelRenderer.CameraPosition.Y, 2) + Math.Pow(m.Position.Z - ModelRenderer.CameraPosition.Z, 2));
                if (distance > 999)
                {
                    distance = 999;
                }

                int color = 14;
                if (item is Enemy && (item as Enemy).IsIdentified)
                {
                    color = 12;
                }

                if (item is Astronaut && item.IsIdentified)
                {
                    color = 10;
                }

                Engine.WriteText(new Point((int)compass_position, 2), "X", color);
                Engine.WriteText(new Point((int)compass_position - 1, 3), distance.ToString("000"), color);
            }
        }
예제 #14
0
    /// <summary>
    /// Tells the Queen to take their turn.
    /// also gives the Queen their input
    /// </summary>
    private void RunQueenTurn()
    {
        int xQcoord = (int)theQueen.transform.position.x;
        int zQcoord = (int)theQueen.transform.position.z;
        int yQcoord = CustomMath.fastfloor(theQueen.transform.position.y) + 1;

        float[] inputQ = new float[AntNetConfigs.Instance.Queen_Net_Extra_Inputs + AntNetConfigs.Instance.Queen_Net_Env_Inputs * AntNetConfigs.Instance.Queen_Net_Env_Features];
        int     indexQ = 0;

        inputQ[indexQ++] = GlobalFeeling;
        inputQ[indexQ++] = theQueen.transform.position.x / AntDist.GetLength(0);
        inputQ[indexQ++] = theQueen.transform.position.z / AntDist.GetLength(1);
        inputQ[indexQ++] = theQueen.transform.position.y / (ConfigurationManager.Instance.World_Height * ConfigurationManager.Instance.Chunk_Diameter);
        inputQ[indexQ++] = (float)Ants.Count / (AntNetConfigs.Instance.Num_Ants);
        inputQ[indexQ++] = (float)theQueen.health / AntNetConfigs.Instance.Max_Health;

        for (int x = xQcoord - QueenSightRadius; x <= xQcoord + QueenSightRadius; x++)
        {
            for (int z = zQcoord - QueenSightRadius; z <= zQcoord + QueenSightRadius; z++)
            {
                if (x < 0 || x >= AntDist.GetLength(0) || z < 0 || z >= AntDist.GetLength(1))
                {
                    indexQ += 3;
                }
                else
                {
                    inputQ[indexQ++] = BlockToFloat(WorldManager.Instance.GetBlock(x, WorldManager.Instance.Topography[x, z], z));
                    inputQ[indexQ++] = (WorldManager.Instance.Topography[x, z] - yQcoord) * 0.1f;
                    inputQ[indexQ++] = (AntDist[x, z]) * 0.5f;
                }
            }
        }
        theQueen.TakeTurn(inputQ);
        QueenCommand = (float)Math.Sin(theQueen.command);
    }
예제 #15
0
        public void Root_ShouldThrowExceptionWhenRootIsHigherThan10()
        {
            long number = 4;
            int  root   = 11;

            CustomMath.Root(number, root);
        }
예제 #16
0
    private void OnEnable()
    {
        if (unit == null && Static)
        {
            AgentBaseData data = new AgentBaseData();
            data.id                 = -1;
            data.mapId              = 0;
            data.playerId           = 0;
            data.eAgentType         = EAgentType.none;
            data.defaultTargetPos   = CustomMath.Vector3ToTsvec(this.transform.position);
            data.loopCallback       = this.Loop;
            data.boidsType          = (byte)EBoidsActiveType.all;
            data.maxSpeed           = FP.One * 3;
            data.position           = CustomMath.Vector3ToTsvec(this.transform.position);
            data.collidesWithLayer  = 1;
            data.viewRadius         = FP.One * 6;
            data.neighbourRadius    = FP.One * data.maxSpeed;
            data.neighbourRadiusSqr = data.neighbourRadius * data.neighbourRadius;
            data.colliderRadius     = 0.5f;//test

            data.pfm     = TestPathFinding._pfm;
            unit         = new PathFindingAgentBehaviour();
            unit.enabled = true;
            unit.Init(data);
        }

        if (unit != null)
        {
            unit.OnEnable();
        }
    }
예제 #17
0
        public RoomTreasure(int x, int y) : base(x, y)
        {
            this.descr = "En medio de la sala hay un cofre con objetos";
            int         value = 0;
            List <Item> list  = new List <Item> {
                new ItemScroll("Pergamino de salida", 1), new ItemScroll("Pergamino de visión", 0), new ItemPocion("Minipoción de maná", CustomMath.RandomIntNumber(50, 25), ItemPocion.PocionType.mana), new ItemPocion("Poción de maná", CustomMath.RandomIntNumber(75, 50), ItemPocion.PocionType.mana), new ItemPocion("Gran poción de maná", 100, ItemPocion.PocionType.mana), new ItemPocion("Minipoción de vida", CustomMath.RandomIntNumber(50, 25), ItemPocion.PocionType.hp), new ItemPocion("Poción de vida", CustomMath.RandomIntNumber(75, 50), ItemPocion.PocionType.hp), new ItemPocion("Gran poción de vida", 100, ItemPocion.PocionType.hp), new ItemArmor("Armadura tapizada", 5 + (5 * Program.level), Program.level, 45)
            };
            List <int> listValue = new List <int> {
                2, 2, 1, 2, 3, 1, 2, 3, 3
            };

            while (value < 3)
            {
                int rand = CustomMath.RandomIntNumber(list.Count - 1);
                GetItem(list[rand]);
                value += listValue[rand];
                if (value < 3)
                {
                    int xx = 3 - value;
                    for (int i = 0; i < list.Count; i++)
                    {
                        if (listValue[i] > xx)
                        {
                            listValue.RemoveAt(i);
                            list.RemoveAt(i);
                            i--;
                        }
                    }
                }
            }
        }
예제 #18
0
        public void Example2()
        {
            string testData = "2 * 3 + (4 * 5)";
            long   result   = CustomMath.Parse(testData);

            Assert.AreEqual(26, result);
        }
예제 #19
0
파일: Program.cs 프로젝트: Lera19/Homework
        static void Main(string[] args)
        {
            {
                while (true)
                {
                    Console.Write("Value input a: ");
                    double a = CustomMath.SetValue();
                    Console.Write("Value input b: ");
                    double b = CustomMath.SetValue();
                    Console.Write("Value input c: ");
                    double c = CustomMath.SetValue();

                    Console.WriteLine($"FORMULA: {a}x^2+({b})x+({c}) = 0 ");

                    CustomMath.Discrim(a, b, c);

                    Console.WriteLine("\nIf you want close this program input break: ");

                    {
                        string breakString = Console.ReadLine();
                        if (breakString == "break")
                        {
                            break;
                        }
                    }
                }
            }
        }
예제 #20
0
        public void Root_ShouldThrowExceptionWhenNumberIsLongerThan17()
        {
            long number = 123456789123456789;
            int  root   = 2;

            CustomMath.Root(number, root);
        }
예제 #21
0
 public void MathTests_IsPairNumber()
 {
     Assert.IsTrue(CustomMath.IsPairNumber(2));
     Assert.IsTrue(CustomMath.IsPairNumber(10));
     Assert.IsTrue(CustomMath.IsPairNumber(0));
     Assert.IsTrue(!CustomMath.IsPairNumber(1));
     Assert.IsTrue(!CustomMath.IsPairNumber(5));
 }
예제 #22
0
    public override void Update(float deltaTime)
    {
        _transitFactor = Mathf.Clamp01(_transitFactor + (_transiting ? -deltaTime : deltaTime) / 0.5f);

        _fadeSprite.alpha = CustomMath.Curve(1f - _transitFactor, 1f);

        base.Update(deltaTime);
    }
예제 #23
0
        public void Example24()
        {
            string     testData = "5 * 9 * (7 * 3 * 3 + 9 * 3 + (8 + 6 * 4))";
            CustomMath math     = new CustomMath();
            long       result   = math.ParseUsingStack(testData);

            Assert.AreEqual(669060, result);
        }
예제 #24
0
        public void Example22()
        {
            string     testData = "2 * 3 + (4 * 5)";
            CustomMath math     = new CustomMath();
            long       result   = math.ParseUsingStack(testData);

            Assert.AreEqual(46, result);
        }
예제 #25
0
        public void Example23()
        {
            string     testData = "5 + (8 * 3 + 9 + 3 * 4 * 3)";
            CustomMath math     = new CustomMath();
            long       result   = math.ParseUsingStack(testData);

            Assert.AreEqual(1445, result);
        }
예제 #26
0
        public void Example25()
        {
            string     testData = "((2 + 4 * 9) * (6 + 9 * 8 + 6) + 6) + 2 + 4 * 2";
            CustomMath math     = new CustomMath();
            long       result   = math.ParseUsingStack(testData);

            Assert.AreEqual(23340, result);
        }
예제 #27
0
        public TSVector2 upperBound; ///< the upper vertex
                                     /// Verify that the bounds are sorted.
        public bool IsValid()        //warning
        {
            TSVector2 d     = upperBound - lowerBound;
            bool      valid = d.x >= FP.Zero && d.y >= FP.Zero;

            valid = valid && CustomMath.IsValid(lowerBound) && CustomMath.IsValid(upperBound);//to be checked
            return(valid);
        }
예제 #28
0
        public override void OnUseItem(World world, Player player, ItemContainer itemContainer, Vector3 targetPosition)
        {
            Vector3 shootPosition        = player.worldPosition + CustomMath.HorizontalRotate(new Vector3(0.7f, 1f, 0f), player.viewAngle);
            Vector3 bulletTargetPosition = targetPosition + Vector3.up + Random.insideUnitSphere;
            Vector3 bulletVelocity       = (bulletTargetPosition - shootPosition).normalized * 16f;

            world.SpawnEntity(new Granade(player, new Damage(player, Random.Range(10f, 20f)), bulletVelocity), shootPosition);
            world.worldCamera.ShakeCamera(4f);
        }
예제 #29
0
        public void Abs_ShouldReturnSameNumberWhenGivenPositiveNumber()
        {
            decimal number   = 5;
            decimal expected = 5;

            decimal result = CustomMath.Abs(number);

            Assert.AreEqual(expected, result);
        }
예제 #30
0
    public RayTrace GetRayAtScreenPosition(Vector2 position)
    {
        Vector3 startRaytracePosition = CustomMath.HorizontalRotate(new Vector3(
                                                                        (position.x + position.y * 2f) / PixelsPerTile - Chunk.Height,
                                                                        Chunk.Height,
                                                                        (position.y * 2f - position.x) / PixelsPerTile - Chunk.Height), _viewAngle - 45f);

        return(_world.RayTraceTile(startRaytracePosition, CustomMath.HorizontalRotate(new Vector3(1f, -1f, 1f), _viewAngle - 45f), 0f));
    }