Example #1
0
        static void Main(string[] args)
        {
            CMath cm = new CMath();

            Console.WriteLine("m Prog.");
            cm.AddFun(5, 4);
        }
    public void spawnEnemy(float x, float y, int type = 0)
    {
        CEnemy enemy = new CEnemy();

        enemy.destroy();
        type = type == 0 ? CMath.randomIntBetween(1, 3) : type;

        switch (type)
        {
        case 1:
            enemy = (CEnemy) new CSalamandra(CSalamandra.TYPE_DONT_FALL);
            break;

        case 2:
            enemy = (CEnemy) new CGolemTierra(CGolemTierra.TYPE_DONT_FALL);
            break;

        case 3:
            enemy = (CEnemy) new CElementalAgua(CElementalAgua.TYPE_DONT_FALL);
            break;

        case 4:
            enemy = (CEnemy) new CBird(CBird.TYPE_DONT_FALL);
            break;
        }
        enemy.setState(CEnemy.STATE_FALLING);
        enemy.setXY(x - enemy.getWidth() / 2, y + enemy.getHeight() / 2);
        this.add(enemy);
    }
Example #3
0
 public void TestInverseConsecutiveIntegers()
 {
     for (var i = 1; i <= m_results.Length; i++)
     {
         Assert.AreEqual <int>(i, CMath.InverseSumOfConsecutiveInts(m_results[i - 1]), "Bad inverse sum at index " + i);
     }
 }
Example #4
0
 public void TestConsecutiveIntegers()
 {
     for (var i = 1; i <= m_results.Length; i++)
     {
         Assert.AreEqual <int>(m_results[i - 1], CMath.SumOfConsecutiveInts(i), "Bad sum at index " + i);
     }
 }
Example #5
0
    public CSequenceData RequestSequence(int aLane)
    {
        List <Runes> sequence = new List <Runes>();

        for (int i = 0; i < _currentSequenceCount; i++)
        {
            int random = CMath.randomIntBetween(0, 3);
            switch (random)
            {
            case 0:
                sequence.Add(Runes.FIRE);
                break;

            case 1:
                sequence.Add(Runes.OCCULT);
                break;

            case 2:
                sequence.Add(Runes.ENERGY);
                break;

            case 3:
            default:
                sequence.Add(Runes.STRENGTH);
                break;
            }
        }
        CSequenceData data = new CSequenceData(_currentSequenceWaitTime, sequence);

        _openSequences[aLane] = data;
        return(data);
    }
Example #6
0
 public void SetAt(long x, long y, bool val)
 {
     if (Wrap || (CMath.IsInRange(x, 0, width) && CMath.IsInRange(y, 0, height)))
     {
         this[x, y] = val;
     }
 }
 /// <summary>
 /// Called when a sequence's time is finished without success.
 /// </summary>
 public void OnSequenceEnded()
 {
     if (_currentEnemy == null && _currentHeart == null)
     {
         return;
     }
     if (_currentHeart != null)
     {
         _currentHeart.SetState(CHeart.STATE_DEATH);
         _currentHeart = null;
     }
     else
     {
         if (_currentEnemy.GetState() == CEnemy.STATE_ATTACK)
         {
             return;
         }
         _currentEnemy.SetState(CEnemy.STATE_ATTACK);
     }
     _ui.SetSequence(new List <Runes>());
     _elapsedTimeNoEnemy = 0;
     _ui.SetClockValue(0);
     _timeToWaitBetweenEnemies = CMath.RandomFloatBetween(CLevelManager.Inst.GetCurrentTimeEnemySpawn().x, CLevelManager.Inst.GetCurrentTimeEnemySpawn().y);
     _mercenary.SetState(CMercenary.STATE_ANGRY);
 }
Example #8
0
        public static void For(int fromInclusive, int toExclusive, Preference mode, Action <int> body)
        {
            int num_workers = HybridCPU.EffectiveProcessorCount(mode);

            uint count  = (uint)(toExclusive - fromInclusive);
            uint rng_sz = count / (uint)num_workers;

            uint left_ = count - rng_sz * (uint)num_workers;

            Action[] workers = new Action[num_workers];

            for (int i = 0; i < num_workers;)
            {
                uint temp = CMath.Normal(left_); // 0 or 1
                left_ -= temp;
                temp  += rng_sz;

                workers[i++]   = new RangeWorker(body, fromInclusive, (int)temp, mode).Run;
                fromInclusive += (int)temp;
            }

            Parallel.Invoke(new ParallelOptions {
                MaxDegreeOfParallelism = num_workers
            }, workers);
        }
Example #9
0
 public override void setState(int aState)
 {
     base.setState(aState);
     if (getState() == STATE_STAND)
     {
         currentTimeStanding = CMath.randomIntBetween(minTimeStanding, maxTimeStanding);
         nextAmountOfSteps   = CMath.randomIntBetween(minSteps, maxSteps);
     }
     if (getState() == STATE_TAKING_STEP)
     {
         int c = CMath.randomIntBetween(0, 1);
         if (c == 0)
         {
             direction = LEFT;
         }
         else if (c == 1)
         {
             direction = RIGHT;
         }
         else
         {
             Debug.Log("Error random dio algo que no era");
         }
     }
 }
Example #10
0
    float SeamlessPerlinNoise2D(Vector2 p)
    {
        Vector2 move = (new Vector2(1, 1) + CMath.Hash21(seed)) * 100;

        p = (p + move) * frequence;
        return(SimplexNoise.SeamlessNoise(p.x, p.y, 10, 10, seed));
    }
Example #11
0
    /// <summary>
    /// 弧线曲线
    /// </summary>
    /// <param name="point1"></param>
    /// <param name="point2"></param>
    /// <param name="point3"></param>
    /// <param name="t"></param>
    /// <returns></returns>
    public static Vector3 Curve(Vector3 start, Vector3 end, float heigh, float rate)
    {
        if (rate > 1)
        {
            return(end);
        }
        Vector3 pos   = Vector3.Lerp(start, end, rate);
        float   rate1 = rate * 2f;

        float y = 0;

        if (rate1 > 0.7f) //下落
        {
            rate1 = (rate1 - 0.7f) / 1.3f;
            rate1 = CMath.BounceOut(rate1, 0, 1f, 1f);
            y     = Mathf.Lerp(heigh + start.y, end.y, rate1);
        }
        else //上升
        {
            rate1 = CMath.CubicOut(rate1, 0, 1f, 1f);
            y     = Mathf.Lerp(start.y, start.y + heigh, rate1);
        }
        pos.y = y;
        return(pos);
    }
Example #12
0
 public bool GetAt(long x, long y)
 {
     if (Wrap || (CMath.IsInRange(x, 0, width) && CMath.IsInRange(y, 0, height)))
     {
         return(this[x, y]);
     }
     return(false);
 }
Example #13
0
        public static int EffectiveMaxConcurrencyLevel(TaskScheduler taskScheduler, int value)
        {
            uint max = (uint)taskScheduler.MaximumConcurrencyLevel;

            return
                (max < int.MaxValue
                                ? (int)CMath.Min(max, (uint)value)
                                : value);
        }
Example #14
0
    /// <summary>
    /// 创建格子
    /// </summary>
    /// <returns></returns>
    public GameObject CreateCube()
    {
        if (CMath.CanRatioBingo(50, EPrecentType.PRECENT_100))
        {
            return(CPrefabManager.Instance.CreatePrefabInstance("BlackCube"));
        }

        return(CPrefabManager.Instance.CreatePrefabInstance("WhiteCube"));
    }
Example #15
0
    public void lookAt(float aX, float aY)
    {
        float xDiff = aX - getX();
        float yDiff = aY - getY();
        float aRad  = Mathf.Atan2(yDiff, xDiff);
        float aDeg  = CMath.radToDeg(aRad);

        setRotation(aDeg);
    }
Example #16
0
    float NormalPerlinNoise2D(Vector2 p)
    {
        Vector2 move = (new Vector2(1, 1) + CMath.Hash21(seed)) * 100;

        p = (p + move) * frequence;
        float sample = PerlinNoise.PerlinNoise_2D(p);

        return((sample * 0.5f + 0.5f) * amplitude);
    }
Example #17
0
        public void TestSigmoid()
        {
            var expected = .2;
            var actual   = CMath.Sigmoid(0, expected);

            Assert.AreEqual <double>(expected, actual, "For low-end of curve");

            actual = CMath.Sigmoid(1, expected);
            Assert.AreEqual <double>(1 - expected, actual, "For high-end of curve");
        }
Example #18
0
    float Wood(Vector2 p)
    {
        Vector2 move = (new Vector2(1, 1) + CMath.Hash21(seed)) * 100;

        p = (p + move) * frequence;
        float sample = PerlinNoise.PerlinNoise_2D(p) * 20;

        sample = sample - (int)sample;
        return((sample * 0.5f + 0.5f) * amplitude);
    }
Example #19
0
 public bool collides(CGameObject aGameObject)
 {
     if (CMath.dist(getX(), getY(), aGameObject.getX(), aGameObject.getY()) < (getRadius() + aGameObject.getRadius()))
     {
         return(true);
     }
     else
     {
         return(false);
     }
 }
    public Vector3 GetProjectedPos(Vector3 fromPosition, float height)
    {
        //Find angle at point C
        float cA = 70;
        //find a. a / sinA = c / sinC
        float   a = ((fromPosition.y - height) / CMath.Sin(cA)) * CMath.Sin(90);
        Vector3 v = fromPosition + new Vector3(0, CMath.Sin(-cA), CMath.Cos(-cA)) * a;

        //Debug.DrawLine(transform.position, v);
        return(v);
    }
Example #21
0
 public value_type this[long x, long y]
 {
     get
     {
         //Console.WriteLine($"{y} % {height} = {y % height}");
         return(array[CMath.Mod(y, height), CMath.Mod(x, width)]);
     }
     set
     {
         array[CMath.Mod(y, height), CMath.Mod(x, width)] = value;
     }
 }
Example #22
0
    /// <summary>
    /// 检查是否安全
    /// </summary>
    /// <returns></returns>
    private bool CheckIsSafe()
    {
        if (_nowGridIndex < SAFE_GRID_COUNT)
        {
            return(true);
        }

        int offset      = _nowGridIndex - _lastSafeIndex;
        int randomValue = CMath.Rand(20);

        return(randomValue <= offset);
    }
Example #23
0
    float Turbulence_Sum(Vector2 p)
    {
        Vector2 move = (new Vector2(1, 1) + CMath.Hash21(seed)) * 100;

        p = (p + move) * frequence;
        float sample = Mathf.Abs(PerlinNoise.PerlinNoise_2D(p)) +
                       0.5f * Mathf.Abs(PerlinNoise.PerlinNoise_2D(2 * p)) +
                       0.25f * Mathf.Abs(PerlinNoise.PerlinNoise_2D(4 * p)) +
                       0.125f * Mathf.Abs(PerlinNoise.PerlinNoise_2D(8 * p));

        return((sample * 0.5f + 0.5f) * amplitude);
    }
    private void createAsteroids()
    {
        CAsteroid asteroid;

        for (int i = 0; i < 10; i++)
        {
            asteroid = new CAsteroid(CAsteroid.TYPE_BIG, CMath.randomIntBetween(1, 3));
            asteroid.setXY(CMath.randomIntBetween(0, CGameConstants.SCREEN_WIDTH), CMath.randomIntBetween(0, CGameConstants.SCREEN_HEIGHT));
            asteroid.setVelX(CMath.randomFloatBetween(-500, 500));
            asteroid.setVelY(CMath.randomFloatBetween(-500, 500));
            CEnemyManager.inst().add(asteroid);
        }
    }
Example #25
0
    private string BuildJSONHeader()
    {
        string s = @"{
			""username"":"""             + username + @""",
            ""icon_emoji"":""" + iconEmojii + @""",
            ""text"": """ + prefixText + @" "",
            ""attachments"": [
            {
				""color"" : """                 + CMath.ColorToHex(barColor) + @""" ,
				""fields"": [ "                ;

        return(s);
    }
    public override void OnInspectorGUI()
    {
        Transform transform = (Transform)target;

        // Make this Undo-able
        Undo.RecordObject(transform, "Transform Custom Update");

        EditorGUILayout.BeginVertical();
        // position
        EditorGUILayout.BeginHorizontal();
        EditorGUILayout.LabelField("Position", GUILayout.MaxWidth(labelWidth));
        positionState = (RelativeState)EditorGUILayout.EnumPopup(positionState);
        if (positionState == RelativeState.Global)
        {
            transform.position = EditorGUILayout.Vector3Field("", CMath.RoundToPoint(transform.position, roundPlaces));
        }
        else
        {
            transform.localPosition = EditorGUILayout.Vector3Field("", CMath.RoundToPoint(transform.localPosition, roundPlaces));
        }
        EditorGUILayout.EndHorizontal();
        // rotation
        EditorGUILayout.BeginHorizontal();
        EditorGUILayout.LabelField("Rotation", GUILayout.MaxWidth(labelWidth));
        rotationState = (RelativeState)EditorGUILayout.EnumPopup(rotationState);
        if (rotationState == RelativeState.Global)
        {
            transform.eulerAngles = EditorGUILayout.Vector3Field("", CMath.RoundToPoint(transform.eulerAngles, roundPlaces));
        }
        else
        {
            transform.localEulerAngles = EditorGUILayout.Vector3Field("", CMath.RoundToPoint(transform.localEulerAngles, roundPlaces));
        }
        EditorGUILayout.EndHorizontal();
        // scale
        EditorGUILayout.BeginHorizontal();
        EditorGUILayout.LabelField("Scale", GUILayout.MaxWidth(labelWidth));
        scaleState = (RelativeState)EditorGUILayout.EnumPopup(scaleState);
        if (scaleState == RelativeState.Global)
        {
            EditorGUI.BeginDisabledGroup(true);
            EditorGUILayout.Vector3Field("", CMath.RoundToPoint(transform.lossyScale, roundPlaces));             // can't set global scale
            EditorGUI.EndDisabledGroup();
        }
        else
        {
            transform.localScale = EditorGUILayout.Vector3Field("", CMath.RoundToPoint(transform.localScale, roundPlaces));
        }
        EditorGUILayout.EndHorizontal();
        EditorGUILayout.EndVertical();
    }
        private void Solve(Matrix Mat)
        {
            var mat = Mat.Values;

            if (mat[0] <= 0.0)
            {
                throw new ArgumentOutOfRangeException("Cholesky factorization unsolved");
            }
            mat[0] = Math.Sqrt(mat[0]);
            double d     = mat[0];
            int    nRows = Mat.RowCount;
            int    nCols = Mat.ColumnCount;

            for (int i = 1; i < nCols; i++)
            {
                Mat[i, 0] /= mat[0];
            }
            for (int j = 1; j < nCols; j++)
            {
                int u = j * nCols + j;
                for (int k = 0; k < j; k++)
                {
                    mat[u] -= CMath.Square(Mat[j, k]);
                }
                if (mat[u] <= 0.0)
                {
                    throw new ArgumentOutOfRangeException("Cholesky factorization unsolved");
                }
                mat[u] = Math.Sqrt(mat[u]);
                d     *= mat[u];
                for (int i = j + 1; i < nCols; i++)
                {
                    int v = i * nCols + j;
                    for (int k = 0; k < j; k++)
                    {
                        mat[v] -= Mat[i, k] * Mat[j, k];
                    }
                    mat[v] /= mat[u];
                }
            }
            Determinant = d * d;
            for (int i = 0; i < nCols - 1; i++)
            {
                for (int j = i + 1; j < nCols; j++)
                {
                    Mat[i, j] = 0.0;
                }
            }
            Factor = Mat;
        }
Example #28
0
        protected override void CUpdate()
        {
            base.CUpdate();
            Vector3 pos = useWorldPos ? trans.position : trans.localPosition;

            t += delta * Time.deltaTime;
            if (t > 1f)
            {
                t = 1f;
            }
            pos = CMath.GetBezierPoint(fromPos, heightPos, toPos, t);
            if (useWorldPos)
            {
                trans.position = pos;
            }
            else
            {
                trans.localPosition = pos;
            }
            if (t == 1f)
            {
                if (CollisionEvent != null)
                {
                    CollisionEvent();
                }
                if (canBounce)
                {
                    Vector3 nextPos    = toPos + (toPos - fromPos) * elasticity;
                    float   nextHeight = height * elasticity;
                    float   nextDelta  = delta / elasticity;
                    Go(nextPos, nextHeight, nextDelta, useWorldPos, canBounce, elasticity, null, EndEvent);
                    if (height < 0.1f)
                    {
                        if (EndEvent != null)
                        {
                            EndEvent();
                        }
                        this.enabled = false;
                    }
                }
                else
                {
                    if (EndEvent != null)
                    {
                        EndEvent();
                    }
                    this.enabled = false;
                }
            }
        }
Example #29
0
    /// <summary>
    ///
    /// </summary>
    private void rePositionAndScaleMask()
    {
        // Calculate the new xScale
        float xScale = CMath.lerp(1, 0, mInitialMaskScale, 1, mCurrentPercent);

        mLifeMask.transform.localScale = new Vector3(xScale, 1, 1);

        // Calculate the new pos.
        float xPos = CMath.lerp(1, 0, mInitialMaskXPos, mBarXPos, mCurrentPercent);

        Vector3 pos = mLifeMask.transform.localPosition;

        mLifeMask.transform.localPosition = new Vector3(xPos, pos.y, pos.z);
    }
Example #30
0
        public static long DecryptNumber(string Encrypted)
        {
            int[] aKey    = GetKeyForEncryptNumber();
            int   Antilog = GetAntilogForEncryptNumber();

            string[] aEncrypted = CArray.SplitByLength(Encrypted, 1);

            for (int i = 0; i < aEncrypted.Length; i++)
            {
                aEncrypted[i] = (CMath.Get10FromN(aEncrypted[i], Antilog) ^ aKey[i % 10]).ToString();
            }

            return(Convert.ToInt64(string.Join("", aEncrypted)));
        }