Пример #1
0
        public void Test_最小値と最大値が出現するか_整数(long seed, long count, int min, int max)
        {
            var random = new RandomState();

            int minValue = max;
            int maxValue = min;

            random.SetSeed(seed);

            for (int i = 0; i < count; i++)
            {
                var value = random.Range(min, max);

                if (minValue > value)
                {
                    minValue = value;
                }
                if (maxValue < value)
                {
                    maxValue = value;
                }
            }

            // 最小値と最大値が出現しているか
            Assert.AreEqual(min, minValue);
            Assert.AreEqual(max, maxValue);
        }
Пример #2
0
        public void Snapshot_Argument0_InitialEqualsSnapshot()
        {
            Random.State initialState = Random.state;
            Random.State snapshot     = RandomState.Snapshot(0);

            Assert.AreEqual(initialState, snapshot);
        }
Пример #3
0
    void Start()
    {
        FSMManager manager = GetComponent <FSMManager>();

        RandomState search = new RandomState();
        FollowState follow = new FollowState();
        EatState    eat    = new EatState();

        /**
         *  Search for "food"
         *      when locate -> follow it
         *          When arrive -> eat it;
         */
        manager.GetBasicState()
        .configure("Food",
                   o => follow.whenArrive((e) => eat.setToEat(e).setAfterEat((s) => search), o), (o) => {
            Debug.LogError("GOTCHA");
            return(null);
        });

        /**
         *  Search for "player"
         *      when locate -> follow it
         *          When arrive -> attack it;
         */
        //        search.config("Player", o => follow.config((e) => attack.setTarget(e), o));

        manager.setCurrentState(search);
    }
Пример #4
0
        public void Test_0と1の偏りが半々であるか(long seed, long count)
        {
            var random = new RandomState();

            long v0 = 0;
            long v1 = 0;

            random.SetSeed(seed);

            for (int i = 0; i < count; i++)
            {
                var value = random.Range(0, 1);

                if (value == 0)
                {
                    v0 += 1;
                }
                if (value == 1)
                {
                    v1 += 1;
                }
            }

            // 0 と 1 の割合が 50% 誤差率 0.01 % 以下
            Assert.AreEqual(50.0D, v0 / (double)(v0 + v1) * 100, 0.01D);
            Assert.AreEqual(50.0D, v1 / (double)(v0 + v1) * 100, 0.01D);

            // 0 と 1 以外の数が存在しないこと
            Assert.AreEqual(count, v0 + v1);
        }
Пример #5
0
        public void Test_ファイアーエムブレムの命中率(long seed, long count, double percent)
        {
            var random = new RandomState();

            var  avoidPercent = 100 - percent; // 命中率を敵の回避率に変換
            long hit          = 0;
            long miss         = 0;

            random.SetSeed(seed);

            for (int i = 0; i < count; i++)
            {
                int value = random.Range(0, 255);

                var hitPercent = (value / (double)255) * 100;

                // 命中率が回避率を上回ったとき、攻撃が成立する
                if (hitPercent >= avoidPercent)
                {
                    hit += 1;
                }
                else
                {
                    miss += 1;
                }
            }

            // 最小値と最大値の誤差率 0.01% 以下
            Assert.AreEqual(percent, hit / (double)(hit + miss) * 100, 0.01D);
            Assert.AreEqual((100 - percent), miss / (double)(hit + miss) * 100, 0.01D);
        }
Пример #6
0
        public void Test_最小値と最大値が出現するか_正規(long seed, long count)
        {
            var random = new RandomState();

            double minValue = 1.0D;
            double maxValue = 0.0D;

            random.SetSeed(seed);

            for (int i = 0; i < count; i++)
            {
                double value = random.Range(0.0D, 1.0D);

                if (minValue > value)
                {
                    minValue = value;
                }
                if (maxValue < value)
                {
                    maxValue = value;
                }
            }

            // 最小値と最大値の誤差 0.00001D 以下
            Assert.AreEqual(0.0D, minValue, 0.00001D);
            Assert.AreEqual(1.0D, maxValue, 0.00001D);
        }
Пример #7
0
        public void Snapshot_Argument0_InitialDoesNotEqualCurrent()
        {
            Random.InitState(-1);
            Random.State initialState = Random.state;
            RandomState.Snapshot(0);

            Assert.AreNotEqual(initialState, Random.state);
        }
Пример #8
0
        public void FillTo(NamelessRogue.Engine.Utility.InternalRandom component)
        {
            var state = new RandomState();

            state.Seed            = Seed.ToArray();
            state.NumberGenerated = NumberGenerated;
            component.Restore(state);
        }
Пример #9
0
 public SerializedGame(bool check)
 {
     if (check == true)
     {
         Levels          = new MapState[Game.Levels.Count];
         MonstersOnLevel = new Monster[Game.Levels.Count][];
         //Rooms = new Rectangle[Game.Levels.Count][];
         Doors = new Door[Game.Levels.Count][];
         int i = 0;
         foreach (DungeonMap map in Game.Levels)
         {
             int j = 0;
             MonstersOnLevel[i] = new Monster[map.Monsters.Count];
             //Rooms[i] = new Rectangle[map.Rooms.Count];
             Doors[i] = new Door[map.Doors.Count];
             foreach (Door d in map.Doors)
             {
                 Doors[i][j] = d;
                 j++;
             }
             j = 0;
             //foreach (Rectangle room in map.Rooms)
             //{
             //    Rooms[i][j] = room;
             //    j++;
             //}
             j = 0;
             foreach (Monster monster in map.Monsters)
             {
                 MonstersOnLevel[i][j] = monster;
                 j++;
             }
             Levels[i] = map.Save();
             j         = 0;
             // Current version of Roguesharp doesn't save
             // IsExplored property in serialization process
             // so IsExplored property is being added manually
             foreach (ICell cell in map.GetAllCells())
             {
                 if (cell.IsExplored)
                 {
                     Levels[i].Cells[j] |= MapState.CellProperties.Explored;
                 }
                 j++;
             }
             i++;
         }
         Player   = Game.Player;
         Random   = Game.Random.Save();
         ts       = Game.ts;
         mapLevel = Game.mapLevel;
         steps    = Game.steps;
     }
 }
Пример #10
0
 public ZipfState(RandomState rstate, int size)
 {
     this.size   = size;
     this.rstate = rstate;
     table       = new double[size + 1];
     if (table == null)
     {
         Console.WriteLine("ZipfState constructor: can't create {0} entries for table",
                           size + 1);
     }
 }
Пример #11
0
    void Start()
    {
        fromAttr = GetComponent <BasicObjectAttr>();
        this.originalPos.transform.parent = null;
        FSMManager   manager = GetComponent <FSMManager>();
        NavMeshAgent agent   = GetComponent <NavMeshAgent>();

        RandomState search = new RandomState();
        FollowState follow = new FollowState();
        IdleState   idle   = new IdleState();

        idle.isInfinite = true;
        InvestigateState investigateState = new InvestigateState();

        manager.GetBasicState().configure("Player",
                                          (o) => {
            return(null);
        },
                                          (o) => {
            investigateState.setTargetPos(o.transform.position);
            investigateState.SetDoWhenArrive((s) => {
                Collider[] coll = Physics.OverlapSphere(gameObject.transform.position, fromAttr.dangerViewAreaRadius);
                Debug.Log("Clll" + coll.Length);
                foreach (Collider c in coll)
                {
                    if (c.tag.Equals("Player"))
                    {
                        var go            = Camera.main.GetComponent <GameOverCameraControl>();
                        go.showDeadEffect = true;
                        return(null);
                    }
                }

                idle.time       = fromAttr.investigateWaitTime;
                idle.isInfinite = false;
                idle.onComplete((s1) => {
                    investigateState.setTargetPos(this.originalPos.transform.position);
                    investigateState.SetDoWhenArrive((s2) => {
                        idle.isInfinite    = true;
                        transform.rotation = this.originalPos.transform.rotation;
                        agent.destination  = this.transform.position;
                        return(idle);
                    });
                    return(investigateState);
                });
                return(idle);
            });

            return(investigateState);
        });
        manager.setCurrentState(idle);
    }
Пример #12
0
            public override void OnPageStarted(WebView view, string url, Bitmap favicon)
            {
                Log(Type.Info, "Page started - " + url);

                if (url.Contains("http://redirect.test") && url.Contains(RandomState.ToString()))
                {
                    accessToken = Regex.Match(url, @"(?<=access_token=)(.*?)(?=&token_type)").ToString();
                    Log(Type.Info, "Page returned with access token!");

                    base.OnPageStarted(view, url, favicon);
                }

                base.OnPageStarted(view, url, favicon);
            }
Пример #13
0
        /// <summary>
        /// Restores the state of the pseudo-random number generator based on the specified state parameter
        /// </summary>
        /// <example>
        /// If you generated three random numbers and then called Save to store the state and
        /// followed that up by generating 10 more numbers before calling Restore with the previously saved RandomState
        /// the Restore method should return the generator back to the state when Save was first called.
        /// This means that if you went on to generate 10 more numbers they would be the same 10 numbers that were
        /// generated the first time after Save was called.
        /// </example>
        /// <param name="state">The state to restore to, usually obtained from calling the Save method</param>
        /// <exception cref="ArgumentNullException">RandomState cannot be null</exception>
        public void Restore(RandomState state)
        {
            if (state == null)
            {
                throw new ArgumentNullException(nameof(state), "RandomState cannot be null");
            }

            _seed   = state.Seed[0];
            _random = new TRandom(_seed);
            for (long i = 0; i < state.NumberGenerated; i++)
            {
                _random.Next();
            }
        }
Пример #14
0
    // Update is called once per frame
    void Update()
    {
        if (BattleMachine2.IsEnemyChoosing)
        {
            RandomState.StateLimits = 4;
            RandomState.RandomStateMethod();
            Debug.Log("Virus 3 is Choosing");

            switch (RandomState.StateE)
            {
            case 1:
                _states.Attack();
                Debug.Log("2-Attack");
                Enemy3.IsVirus3Playing         = false;
                BattleMachine3.IsEnemyChoosing = false;
                BattleMachine3.OnPlayerTurn    = true;
                break;

            case 2:
                _states.Pixeling();
                Debug.Log("2-Pixel");
                Enemy3.IsVirus3Playing         = false;
                BattleMachine3.IsEnemyChoosing = false;
                BattleMachine3.OnPlayerTurn    = true;
                break;

            case 3:
                _states.Light();
                Debug.Log("2-Light");
                Enemy3.IsVirus3Playing         = false;
                BattleMachine3.IsEnemyChoosing = false;
                BattleMachine3.OnPlayerTurn    = true;
                break;

            case 4:
                _states.Bug();
                Debug.Log("2-Bug");
                Enemy3.IsVirus3Playing         = false;
                BattleMachine3.IsEnemyChoosing = false;
                BattleMachine3.OnPlayerTurn    = true;
                break;

            default:
                _states.Iddle();
                Debug.Log("3-idle");
                break;
            }
        }
    }
Пример #15
0
    private void Update()
    {
        if (countdown < 0 && randomState == RandomState.Waiting)
        {
            countdown   = Random.Range(rotationTime.Min, rotationTime.Max);
            randomState = RandomState.Rotating;
            Rotate      = Random.Range(rotationPower.Min, rotationTime.Max);
        }
        else if (countdown < 0 && randomState == RandomState.Rotating)
        {
            countdown   = Random.Range(timeBetweenRotations.Min, timeBetweenRotations.Max);
            randomState = RandomState.Waiting;
            Rotate      = 0;
        }

        countdown -= Time.deltaTime;
    }
Пример #16
0
        public void Restore_AfterGeneratingThreeNumbers_RegeneratesSameThreeNumbers()
        {
            IRandom random = new GaussianRandom();

            for (int i = 0; i < 4; i++)
            {
                random.Next(6);
            }
            RandomState state  = random.Save();
            int         first  = random.Next(6);
            int         second = random.Next(6);
            int         third  = random.Next(6);

            random.Restore(state);

            Assert.AreEqual(first, random.Next(6));
            Assert.AreEqual(second, random.Next(6));
            Assert.AreEqual(third, random.Next(6));
        }
Пример #17
0
    void Update()
    {
        if (Enemy.IsVirus1Playing)
        {
            RandomState.StateLimits = 3;
            RandomState.RandomStateMethod();
            Debug.Log("Virus is choosing");
            switch (RandomState.StateE)
            {
            case 1:
                _states.Attack();
                Debug.Log("2-Invisibility");
                Enemy.IsVirus1Playing         = false;
                BattleMachine.IsEnemyChoosing = false;
                BattleMachine.OnPlayerTurn    = true;
                break;

            case 2:
                _states.Attack();
                Debug.Log("2-Attack");
                Enemy.IsVirus1Playing         = false;
                BattleMachine.IsEnemyChoosing = false;
                BattleMachine.OnPlayerTurn    = true;
                break;

            case 3:
                _states.Scanner();
                Debug.Log("2-Scanner");
                Enemy.IsVirus1Playing         = false;
                BattleMachine.IsEnemyChoosing = false;
                BattleMachine.OnPlayerTurn    = true;
                break;

            default:
                Debug.Log("el enemy no hace nada we");
                _states.Iddle();
                Enemy.IsVirus1Playing         = false;
                BattleMachine.IsEnemyChoosing = false;
                BattleMachine.OnPlayerTurn    = true;
                break;
            }
        }
    }
Пример #18
0
    // Start is called before the first frame update
    void Update()
    {
        if (Enemy.IsVirus1Playing)
        {
            RandomState.StateLimits = 3;
            RandomState.RandomStateMethod();
            switch (RandomState.StateE)
            {
            case 1:
                _states.Shoot();
                Debug.Log("2-Shoot");
                Enemy3.IsVirus2Playing         = false;
                BattleMachine3.IsEnemyChoosing = false;
                BattleMachine3.OnPlayerTurn    = true;
                break;

            case 2:
                _states.Block();
                Debug.Log("2-Blocking");
                Enemy3.IsVirus2Playing         = false;
                BattleMachine3.IsEnemyChoosing = false;
                BattleMachine3.OnPlayerTurn    = true;
                break;

            case 3:
                _states.Steal();
                Debug.Log("2-Steal");
                Enemy3.IsVirus2Playing         = false;
                BattleMachine3.IsEnemyChoosing = false;
                BattleMachine3.OnPlayerTurn    = true;
                break;

            default:
                _states.Iddle();
                Debug.Log("2-Iddle");
                Enemy3.IsVirus2Playing         = false;
                BattleMachine3.IsEnemyChoosing = false;
                BattleMachine3.OnPlayerTurn    = true;
                break;
            }
        }
    }
Пример #19
0
        //////////////////////////////////////////////////////////////////////////////
        //ZIPF Distribution                                                         *
        ////////////////////////////////////////////////////////////////////////////

        public ZipfState spec_zipf_setup(RandomState rstate, int size, double Z)
        {
            int    i;
            double zipf_sum;

            ZipfState theState = new ZipfState(rstate, size);

            if (theState == null)
            {
                return(null);
            }

            // compute zipf values for samples 1-n
            for (i = 1; i <= size; i++)
            {
                theState.table[i] = Math.Pow(((double)1.0 / ((double)i)), Z);
                //theState.table[i] = 1;   // SPL TOTAL HACK until POW works!!
            }

            // sum the values so we can compute probabilities.
            // at the same time, make the values cumulative
            zipf_sum = 0.0;
            for (i = 1; i <= size; i++)
            {
                zipf_sum         += theState.table[i];
                theState.table[i] = zipf_sum;
            }
            theState.table[size] = 0.0;
            theState.table[0]    = 0.0;

            // compute probability values by dividing by the sum.
            // also reverse the table so we have values starting at 1.0
            //  and descending to 0.0  (this is what spec_zipf needs)
            for (i = 0; i < size; i++)
            {
                theState.table[i] = 1.0 - (theState.table[i] / zipf_sum);
            }


            return(theState);
        }
Пример #20
0
    void Start()
    {
        fromAttr = GetComponent <BasicObjectAttr>();
        FSMManager manager = GetComponent <FSMManager>();

        RandomState      search           = new RandomState();
        FollowState      follow           = new FollowState();
        IdleState        idle             = new IdleState();
        PatrolState      patrol           = new PatrolState();
        InvestigateState investigateState = new InvestigateState();


        patrol.patrolRoute = patrolRoute;
        patrol.setAgent(GetComponent <NavMeshAgent>());
        manager.GetBasicState().configure("Player",
                                          (o) => {
            investigateState.setTargetPos(o.transform.position).SetDoWhenArrive(null);
            return(investigateState);
        },
                                          (o) => {
            investigateState.setTargetPos(o.transform.position);
            investigateState.SetDoWhenArrive((s) => {
                Collider[] coll = Physics.OverlapSphere(gameObject.transform.position, fromAttr.dangerViewAreaRadius);
                foreach (Collider c in coll)
                {
                    if (c.tag.Equals("Player"))
                    {
                        var go            = Camera.main.GetComponent <GameOverCameraControl>();
                        go.showDeadEffect = true;
                        return(null);
                    }
                }

                return(patrol);
            });

            return(investigateState);
        });
        manager.setCurrentState(patrol);
    }
Пример #21
0
        private long SampleUsingInversion()
        {
            var px = qn;
            var U  = RandomState.NextDouble();
            var X  = 0L;

            while (U > px)
            {
                X++;
                if (X > bound)
                {
                    X  = 0;
                    px = qn;
                    U  = RandomState.NextDouble();
                }
                else
                {
                    U -= px;
                    px = ((NSamples - X + 1) * SuccessProbability * px) / (X * FailureProbability);
                }
            }
            return(X);
        }
Пример #22
0
        public double Spec_random(RandomState /*!*/ theState)
        // See "Random Number Generators: Good Ones Are Hard To Find",
        //     Park & Miller, CACM 31#10 October 1988 pages 1192-1201.
        ///////////////////////////////////////////////////////////
        // THIS IMPLEMENTATION REQUIRES AT LEAST 32 BIT INTEGERS !
        ///////////////////////////////////////////////////////////
        {
            int lo;
            int hi;
            int test;

            hi   = theState.val / Q_QUOTIENT;
            lo   = theState.val % Q_QUOTIENT;
            test = A_MULTIPLIER * lo - R_REMAINDER * hi;
            if (test > 0)
            {
                theState.val = test;
            }
            else
            {
                theState.val = test + M_MODULUS;
            }
            return((float)theState.val / M_MODULUS);
        }
Пример #23
0
/// <summary>
/// Constructor.
/// </summary>
/// <param name="hashGridSize">
///     The size of the hash grid. The larger this value, the
///     less reptition of random values across a given range
///     of coordinates. To eliminate repitition this value should
///     be equal to the maximum x or y coordinate, which ever is
///     larger.
/// </param>
/// <param name="hashGridScale">
///     Density of the the unique values per unit square. A value
///     of 1 produces a unique value for every unique coordinate,
///     while a value of .25f produces a unique value every 4 unique
///     coordinates square.
/// </param>
/// <param name="seed">
///     The random seed value used to create the values in the
///     hash grid.
/// </param>
/// <param name="randomValuesPerCooridnate">
///     The number of random values stored per coordinate.
/// </param>
    public RandomHashGrid(
        int hashGridSize,
        float hashGridScale,
        int seed,
        int randomValuesPerCooridnate
        )
    {
        _hashGridSize  = hashGridSize;
        _hashGridScale = hashGridScale;

        _grid = new RandomHash[hashGridSize * hashGridSize];

// Snapshot the current random state and initialize new random state with seed.
        Random.State snapshot = RandomState.Snapshot(seed);

// Populate grid with RandomHash structs.
        for (int i = 0; i < _grid.Length; i++)
        {
            _grid[i] = new RandomHash(randomValuesPerCooridnate);
        }

// Restore random state from snapshot.
        Random.state = snapshot;
    }
Пример #24
0
 public void SaveState()
 {
     m_RndState = m_Rnd.GetState();
 }
Пример #25
0
 /// <summary>
 /// Restores the state of the generator which is essentially a no-op for this generator
 /// </summary>
 /// <param name="state">Not used</param>
 public void Restore(RandomState state)
 {
     // No operation required
 }
    void Update()
    {
        switch (states)
        {
        case BattleStates.Start:
            this.setActivateButtonStatePlayerEnemy(1);
            break;


        case BattleStates.PlayerSelection:



            this.dialogText.text = "Select Hacker H o E ,  Life energy Hacker: " + this.scoreData.hLife + ", Mago: " + this.scoreData.mLife +
                                   "\n Vida del enemigo 1 " + lifeBattleVirus1 + " Vida del enemigo 2: " + lifeBattleVirus2;

            Debug.Log("H o E");

            if (Input.GetKeyDown(KeyCode.H) || this.botonPresionado == 1)
            {
                Player.IsHackerPlaying = true;
                dialogText.text        = "You selected hacker";
                states = BattleStates.EnemySelection;
            }
            else if (Input.GetKeyDown(KeyCode.E) || this.botonPresionado == 2)
            {
                dialogText.text      = "You selected mago";
                Player.IsMagoPlaying = true;
                states = BattleStates.EnemySelection;
            }

            break;

        case BattleStates.SkillSelection:

            this.dialogText.text = "Select an action  \n\n ScoreData ShootPoint: " + scoreData.shootingPoints;

            if (Player.IsMagoPlaying)
            {
                if (Input.GetKeyDown(KeyCode.H))
                {
                    _damage = 5;
                    // _states.Pixeling();
                    Debug.Log("pixel");
                    Player.IsMagoPlaying = false;
                    RestScore();
                    states = BattleStates.Enemyturn;
                }
                else if (Input.GetKeyDown(KeyCode.K) && Mago.Instance._electricityLimit > 0)
                {
                    _damage       = 10;
                    scoreData.xp += 10;
                    //_states.Electricity();
                    Debug.Log("Electricity");
                    Player.IsMagoPlaying = false;
                    Mago.Instance._electricityLimit--;
                    RestScore();
                    states = BattleStates.Enemyturn;
                }
                else if (Input.GetKeyDown(KeyCode.L) && scoreData.mana >= 25)
                {
                    //_states.Light();
                    Debug.Log("Light");
                    _damage              = 15;
                    scoreData.mana      -= 25;
                    Player.IsMagoPlaying = false;
                    RestScore();
                    states        = BattleStates.Enemyturn;
                    scoreData.xp += 10;
                }
                else if (Input.GetKeyDown(KeyCode.M) && shopData.healSold == true)
                {
                    scoreData.hLife = 100;
                    scoreData.mLife = 100;
                    scoreData.mana  = 0;
                    Debug.Log("heal");
                    _damage = 0;
                    Player.IsMagoPlaying = false;
                    RestScore();
                    scoreData.xp += 5;
                    states        = BattleStates.Enemyturn;
                }
                else if (Input.GetKeyDown(KeyCode.N) && shopData.electroshockSold == true)
                {
                    _damage = 20;
                    Debug.Log("electroshock");
                    Player.IsMagoPlaying = false;
                    scoreData.xp        += 5;
                    RestScore();
                    states = BattleStates.Enemyturn;
                }
                else if (Input.GetKeyDown(KeyCode.O) && shopData.updateSold == true)
                {
                    scoreData.mLife += 50;
                    _damage          = 0;
                    Debug.Log("update");
                    Player.IsMagoPlaying = false;
                    RestScore();
                    states = BattleStates.Enemyturn;
                }
                if (lifeBattleVirus1 <= 0 & lifeBattleVirus2 <= 0)
                {
                    states = BattleStates.Won;
                }
            }
            else if (Player.IsHackerPlaying)
            {
                if (Input.GetKey(KeyCode.H))
                {
                    _damage = 5;
                    Debug.Log("1");
                    Player.IsHackerPlaying = false;
                    RestScore();
                    states = BattleStates.Enemyturn;
                }
                else if (Input.GetKey(KeyCode.K))
                {
                    _damage = 10;
                    Debug.Log("2");
                    Player.IsHackerPlaying = false;
                    scoreData.xp          += 5;
                    RestScore();
                    states = BattleStates.Enemyturn;
                }
                else if (Input.GetKey(KeyCode.L) && scoreData.mana >= 25) //añadir condicion
                {
                    _damage         = 15;
                    scoreData.mana -= 25;
                    Debug.Log("3");
                    scoreData.xp          += 10;
                    Player.IsHackerPlaying = false;
                    RestScore();
                    states = BattleStates.Enemyturn;
                }
                else if (Input.GetKeyDown(KeyCode.M) && shopData.resettingSold == true)
                {
                    scoreData.hLife = 100;
                    scoreData.mana += 25;
                    Debug.Log("4 shop");
                    Player.IsHackerPlaying = false;
                    RestScore();
                    states = BattleStates.Enemyturn;
                }
                else if (Input.GetKeyDown(KeyCode.N) && shopData.controlzSold == true)
                {
                    scoreData.hLife = +_damage;
                    _damage         = 0;
                    Debug.Log("5 shop");
                    Player.IsHackerPlaying = false;
                    RestScore();
                    states = BattleStates.Enemyturn;
                }
                else if (Input.GetKeyDown(KeyCode.O) && shopData.deleteSold == true)
                {
                    _damage       = 20;
                    scoreData.xp += 5;
                    Debug.Log("6 shop");
                    Player.IsHackerPlaying = false;
                    RestScore();
                    states = BattleStates.Enemyturn;
                }
            }
            break;

        case BattleStates.EnemySelection:

            this.dialogText.text = "Select an anemy to attack";
            Debug.Log("B o V");

            this.setActivateButtonStatePlayerEnemy(2);

            if (Input.GetKey(KeyCode.V))
            {
                this.dialogText.text = ("Attack to Virus 1");
                virus1Choosed        = true;
                states = BattleStates.SkillSelection;
            }

            else if (Input.GetKey(KeyCode.B))
            {
                this.dialogText.text = ("Attack to Virus 2");
                virus2Choosed        = true;
                states = BattleStates.SkillSelection;
            }
            if (lifeBattleVirus1 <= 0 & lifeBattleVirus2 <= 0)
            {
                states = BattleStates.Won;
                EndBattle();
            }
            break;

        case BattleStates.Enemyturn:
            Debug.Log("Enemy Turn");
            dialogText.text = "Enemy Turn";

            if (c % 2 == 0)
            {
                this.dialogText.text = ("Enemy 1 Selected");
                Debug.Log("enemy 1");
                Virus1 virus1Controller = virus1.GetComponent <Virus1>();
                Enemy.IsVirus1Playing = true;
                dialogText.text       = "Virus 1 Attacking! \n\n" + virus1Controller.ToString();
                states = BattleStates.EnemySelect;
                //states = BattleStates.Enemyturn;
            }
            else
            {
                this.dialogText.text = ("Enemy 2 Selected");
                Debug.Log("enemy 2");
                Virus1 virus2Controller = virus2.GetComponent <Virus1>();
                Enemy.IsVirus1Playing = true;
                this.dialogText.text  = "" + virus2Controller.ToString();
                dialogText.text       = "Virus 2 Attacking! " + virus2Controller.ToString();
                states = BattleStates.EnemySelect;
                //states = BattleStates.Enemyturn;
            }
            c++;

            break;

        case BattleStates.EnemySelect:

            RandomState.StateLimits = 3;
            RandomState.RandomStateMethod();
            this.dialogText.text = ("Virus is choosing");
            switch (RandomState.StateE)
            {
            case 1:
                //_states.Attack();
                _damage = 5;
                this.dialogText.text = ("2-Invisibility");
                Debug.Log("enemy");
                Enemy.IsVirus1Playing = false;
                states = BattleStates.EnemySelectPlayer;
                break;

            case 2:
                //_states.Attack();
                _damage = 10;
                this.dialogText.text = ("2-Attack");
                Debug.Log("enemy");
                Enemy.IsVirus1Playing = false;
                states = BattleStates.EnemySelectPlayer;
                break;

            case 3:
                //_states.Scanner();
                _damage = 15;
                this.dialogText.text = ("2-Scanner");
                Debug.Log("enemy");
                Enemy.IsVirus1Playing = false;
                states = BattleStates.EnemySelectPlayer;
                break;

            default:
                this.dialogText.text  = ("No anda el virus");
                Enemy.IsVirus1Playing = false;
                break;
            }

            //states = BattleStates.EnemySelect;  //Esto lo puse yo para probar
            break;


        case BattleStates.EnemySelectPlayer:


            if (RandomState.StateE % 2 == 0)
            {
                this.dialogText.text = ("Attack to Hacker");
                Debug.Log("to hacker");
                scoreData.hLife = scoreData.hLife - _damage;
                //states = BattleStates.PlayerSelection;
            }
            else
            {
                this.dialogText.text = ("Attack to Mago");
                Debug.Log("to mago");
                scoreData.mLife = scoreData.mLife - Virus1.Instance._damage;
                //states = BattleStates.PlayerSelection;
            }


            //Le ponemos un OR exclusivo
            if (scoreData.hLife <= 0 || scoreData.mLife <= 0)     //el score es la vida de los players
            {
                states = BattleStates.Lost;
                EndBattle();
            }

            //this.dialogText.text = "Vida del personaje " + scoreData.mLife + ", hacker: " + scoreData.hLife;


            //Esto lo puse yo para probar
            states = BattleStates.PlayerSelection;

            break;

        default: break;
        }

        /*  if (OnPlayerTurn)
         * {
         *    states = BattleStates.PlayerTurn;
         *    StartCoroutine(PlayerTurn());
         * }
         * else if (!OnPlayerTurn)
         * {
         *    states = BattleStates.Enemyturn;
         *    StartCoroutine(EnemyTurn());
         * }*/
    }
Пример #27
0
 double Random(RandomState random, double min, double max)
 {
     return(min + random.Generator.NextDouble() * (max - min));
 }
Пример #28
0
 public Companion Random()
 {
     return(Companions[RandomState.Next(Companions.Length)]);
 }
Пример #29
0
 public virtual void Seed(int?seed = null)
 {
     RandomState = Seeding.GetState(seed);
 }
Пример #30
0
 /// <summary>
 /// Restores the state of the generator which is essentially a no-op for this generator
 /// </summary>
 /// <param name="state">Not used</param>
 public void Restore( RandomState state )
 {
     // No operation required
 }
Пример #31
0
        private long SampleUsingBTPE()
        {
            // The following code is ported from NumPy's binomial
            // sampling implementation.
            double r, q, fm, p1, xm, xl, xr, c, laml, lamr, p2, p3, p4;
            double a, u, v, s, F, rho, t, A, nrq, x1, x2, f1, f2, z, z2, w, w2, x;
            long   m, y, k, i;

            /* initialize */
            r    = Min(SuccessProbability, FailureProbability);
            q    = 1.0 - r;
            fm   = NSamples * r + r;
            m    = (long)Floor(fm);
            p1   = Floor(2.195 * Sqrt(NSamples * r * q) - 4.6 * q) + 0.5;
            xm   = m + 0.5;
            xl   = xm - p1;
            xr   = xm + p1;
            c    = 0.134 + 20.5 / (15.3 + m);
            a    = (fm - xl) / (fm - xl * r);
            laml = a * (1.0 + a / 2.0);
            a    = (xr - fm) / (xr * q);
            lamr = a * (1.0 + a / 2.0);
            p2   = p1 * (1.0 + 2.0 * c);
            p3   = p2 + c / laml;
            p4   = p3 + c / lamr;


            /* sigh ... */
Step10:
            nrq = NSamples * r * q;
            u   = RandomState.NextDouble() * p4;
            v   = RandomState.NextDouble();
            if (u > p1)
            {
                goto Step20;
            }
            y = (long)Floor(xm - p1 * v + u);
            goto Step60;

Step20:
            if (u > p2)
            {
                goto Step30;
            }
            x = xl + (u - p1) / c;
            v = v * c + 1.0 - Abs(m - x + 0.5) / p1;
            if (v > 1.0)
            {
                goto Step10;
            }
            y = (long)Floor(x);
            goto Step50;

Step30:
            if (u > p3)
            {
                goto Step40;
            }
            y = (long)Floor(xl + Log(v) / laml);
            /* Reject if v == 0.0 since cast of inf not well defined */
            if ((y < 0) || (v == 0.0))
            {
                goto Step10;
            }
            v = v * (u - p2) * laml;
            goto Step50;

Step40:
            y = (long)Floor(xr - Log(v) / lamr);
            /* Reject if v == 0.0 since cast of inf not well defined */
            if ((y > NSamples) || (v == 0.0))
            {
                goto Step10;
            }
            v = v * (u - p3) * lamr;

Step50:
            k = Abs(y - m);
            if ((k > 20) && (k < ((nrq) / 2.0 - 1)))
            {
                goto Step52;
            }

            s = r / q;
            a = s * (NSamples + 1);
            F = 1.0;
            if (m < y)
            {
                for (i = m + 1; i <= y; i++)
                {
                    F *= (a / i - s);
                }
            }
            else if (m > y)
            {
                for (i = y + 1; i <= m; i++)
                {
                    F /= (a / i - s);
                }
            }
            if (v > F)
            {
                goto Step10;
            }
            goto Step60;

Step52:
            rho = (k / (nrq)) * ((k * (k / 3.0 + 0.625) + 0.16666666666666666) / nrq + 0.5);
            t   = -k * k / (2 * nrq); // lgtm [cs/loss-of-precision]
            A   = Log(v);
            if (A < (t - rho))
            {
                goto Step60;
            }
            if (A > (t + rho))
            {
                goto Step10;
            }

            x1 = y + 1;
            f1 = m + 1;
            z  = NSamples + 1 - m;
            w  = NSamples - y + 1;
            x2 = x1 * x1;
            f2 = f1 * f1;
            z2 = z * z;
            w2 = w * w;
            if (A > (xm * Log(f1 / x1)
                     + (NSamples - m + 0.5) * Log(z / w)
                     + (y - m) * Log(w * r / (x1 * q))
                     + (13680.0 - (462.0 - (132.0 - (99.0 - 140.0 / f2) / f2) / f2) / f2) / f1 / 166320.0
                     + (13680.0 - (462.0 - (132.0 - (99.0 - 140.0 / z2) / z2) / z2) / z2) / z / 166320.0
                     + (13680.0 - (462.0 - (132.0 - (99.0 - 140.0 / x2) / x2) / x2) / x2) / x1 / 166320.0
                     + (13680.0 - (462.0 - (132.0 - (99.0 - 140.0 / w2) / w2) / w2) / w2) / w / 166320.0))
            {
                goto Step10;
            }

Step60:
            if (SuccessProbability > 0.5)
            {
                y = NSamples - y;
            }

            return(y);
        }