コード例 #1
0
        public IHttpActionResult GetProportionValue(int id)
        {
            var list = new[] {
                ProportionValue.Create(0.6, new Spin("", 0)),
                ProportionValue.Create(0.307, new Spin("", .7)),
                ProportionValue.Create(0.05, new Spin("", 1.4)),
                ProportionValue.Create(0.03, new Spin("Free Spins", 4.9)),
                ProportionValue.Create(0.01, new Spin("", 10.5)),
                ProportionValue.Create(0.003, new Spin("Jackpot!", 35))



//0.6 0
//0.307   1
//0.05    2
//0.03    7
//0.01    15
//0.003   50



                //ProportionValue.Create(0.6, new Spin("",0)),
                //ProportionValue.Create(0.1, new Spin("",7)),
                //ProportionValue.Create(0.29, new Spin("",2)),
                //ProportionValue.Create(0.009, new Spin("Free Spins",5)),
                //ProportionValue.Create(0.001, new Spin("Jackpot!",200))
            };

            return(Ok(list.ChooseByRandom()));
        }
コード例 #2
0
    // Сопрограмма запускающая обратный отчет после чего запускает мяч в 4-х разных направлениях
    public IEnumerator DelayStart()
    {
        var random = new[]
        {
            ProportionValue.Create(0.25f, new Vector2(startForce, startForce)),
            ProportionValue.Create(0.25f, new Vector2(startForce, -startForce)),
            ProportionValue.Create(0.25f, new Vector2(-startForce, -startForce)),
            ProportionValue.Create(0.25f, new Vector2(-startForce, startForce)),
        };

        GoText.gameObject.SetActive(true);
        GoText.text = "Ready";
        GoText.GetComponent <Shadow>().effectColor    = Color.red;
        GoText.GetComponent <Shadow>().effectDistance = new Vector2(-6, 0);
        yield return(new WaitForSeconds(1));

        GoText.text = "Steady";
        GoText.GetComponent <Shadow>().effectColor    = Color.blue;
        GoText.GetComponent <Shadow>().effectDistance = new Vector2(6, 0);
        yield return(new WaitForSeconds(1));

        GoText.text = "Go";
        GoText.GetComponent <Shadow>().effectColor    = Color.green;
        GoText.GetComponent <Shadow>().effectDistance = new Vector2(0, 6);
        yield return(new WaitForSeconds(1));

        GoText.gameObject.SetActive(false);
        myRigidBody.velocity = random.ChoseByRandom();
    }
コード例 #3
0
        public void Init()
        {
            nextSpawn = Time.time + spawnTime;

            clist = new ProportionValue <string> [spawnables.Count];
            for (int a = 0; a < spawnables.Count; a++)
            {
                clist[a] = ProportionValue.Create(spawnables[a].spawnRate, spawnables[a].prefabName);
            }
        }
コード例 #4
0
    void PullBall()
    {
        var ramdom = new[]
        {
            ProportionValue.Create(0.5f, new Vector2(-startForce / 2, startForce)),
            ProportionValue.Create(0.5f, new Vector2(startForce / 2, startForce)),
        };

        myRigidBody.velocity = ramdom.ChoseByRandom();
    }
コード例 #5
0
    public void DoRNG(int fatigueLevel)
    {
        if (!isTutorialActive)
        {
            if (fatigueLevel == 0)
            {
                PlayerStats.NumSavedDrivers++;
            }
            else if (fatigueLevel == 1)
            {
                var list = new[] {
                    ProportionValue.Create(fatiguedChances[1] / 100, "true"),
                    ProportionValue.Create((100 - fatiguedChances[1]) / 100, "false")
                };

                if (list.ChooseByRandom() == "true")
                {
                    IncreaseNumFatiguedDrivers();
                }
                else
                {
                    PlayerStats.NumSavedDrivers++;
                }
            }
            else if (fatigueLevel == 2)
            {
                var list = new[] {
                    ProportionValue.Create(fatiguedChances[2] / 100, "true"),
                    ProportionValue.Create((100 - fatiguedChances[2]) / 100, "false")
                };

                if (list.ChooseByRandom() == "true")
                {
                    IncreaseNumFatiguedDrivers();
                }
                else
                {
                    PlayerStats.NumSavedDrivers++;
                }
            }
            else if (fatigueLevel == 3)
            {
                IncreaseNumFatiguedDrivers();
            }
        }
        else
        {
            if (fatigueLevel == 3)
            {
                numFatiguedDrivers++;
            }
        }
    }
コード例 #6
0
ファイル: GameStateManager.cs プロジェクト: Zelacks/LD
    void ChooseBlueprint( )
    {
        List <ProportionValue <BuildingBlueprintSingle> > values = new List <ProportionValue <BuildingBlueprintSingle> >( );

        for (int i = 0; i < Candidates.Count; i++)
        {
            values.Add(ProportionValue.Create(Candidates[i].ChanceToChoose, Candidates[i]));
        }

        CurrentBlueprint = values.ChooseByRandom( );
        NewBlueprint?.Invoke(CurrentBlueprint);
    }
コード例 #7
0
    // Return a random valid prefab
    public Prefab GetPrefab()
    {
        var valid = new List <ProportionValue <Prefab> >();

        foreach (Prefab prefab in _prefabs)
        {
            if (prefab.toggle && prefab.percent > 0.0f && prefab.gameObject)
            {
                valid.Add(ProportionValue.Create(prefab.percent, prefab));
            }
        }

        return(valid.ChooseByRandom());
    }
コード例 #8
0
        /// <summary>
        /// Gives the spawned apple an random value.
        /// This value is based on the possibilityPercentages for each value.
        /// </summary>
        /// <param name="appleOBJ">The apple that needs to get a value</param>
        private void CalculateAppleValue(GameObject appleOBJ)
        {
            appleOBJ.transform.position = RandomHelper.RandomVector3(spawnArea.bounds.min, spawnArea.bounds.max);
            var apple = appleOBJ.GetComponent <Apple>();

            List <ProportionValue <int> > list = new List <ProportionValue <int> >();

            foreach (KeyValuePair <int, float> entry in numberPossibilityPercentage)
            {
                list.Add(ProportionValue.Create((entry.Value / 100), entry.Key));
            }

            apple.SetScore(list.ChooseByRandom());
        }
コード例 #9
0
        public LuckyWheelItemDto RandomWheelItem(out int resultForWheel)
        {
            var wheelItems = _luckyWheelItemRepositories.Read(a => true);
            IList <ProportionValue <LuckyWheelItem> > listRandom = new List <ProportionValue <LuckyWheelItem> >();

            foreach (var item in wheelItems)
            {
                listRandom.Add(ProportionValue.Create((item.WinningPercent / 100), item));
            }

            var result = listRandom.ChooseByRandom(out resultForWheel);

            return(Mapper.Map <LuckyWheelItemDto>(result));
        }
コード例 #10
0
ファイル: Battle.cs プロジェクト: Metasynic/PkmnEngine
        /* This function creates a default NPC turn to add to the round. */
        public void AddNpcTurn(PokemonInBattle user, PokemonInBattle target)
        {
            /* A new ProportionValue<Move> array is created with a length equal to the user's move array.
             * The moves are assigned with equal proportions so that each move has the same chance of being used. */
            ProportionValue <Move>[] moves = new ProportionValue <Move> [user.Moves.Count(m => m != null)];
            for (int i = 0; i < 4; i++)
            {
                if (user.Moves[i] != null)
                {
                    moves[i] = ProportionValue.Create(1.0 / user.Moves.Count(m => m != null), user.Moves[i]); // DOES NOT HANDLE UNCOMPACTED MOVE ARRAYS
                }
            }

            /* A new turn is created using the user, target and a move chosen randomly via ProportionValue choosing. */
            turns.Add(new TurnMove(user, target, this, moves.ChooseByRandom()));
        }
コード例 #11
0
ファイル: WorldScreen.cs プロジェクト: Metasynic/PkmnEngine
        /* The CheckSpawn() function checks if a wild Pokemon battle will be triggered on this frame.
         * It is only called when the player's StepCheck bit is true, so it is only called once every step. */
        private void CheckSpawn()
        {
            /* This Random object will be needed for a lot of things later. */
            Random r = new Random();

            /* Each MapLayer in the map needs to be checked for a Tile with its Spawn bit set to true. */
            foreach (MapLayer layer in world.CurrentMap.MapLayers)
            {
                /* If tile that the player is standing on in the layer has its Spawn bit set to true, a battle may happen. */
                if (layer.GetTile(player.Sprite.TileLocation.X, player.Sprite.TileLocation.Y).Spawn)
                {
                    /* This condition determines whether an actual battle happens or not.
                     * If a random double between 0 and 187.5 is less than the level's grass encounter rate, then a battle will happen.
                     * The most likely a battle can be to happen is a VeryCommon encounter rate, which is 10.0.
                     * With a VeryCommon encounter rate, the chance of a battle occurring is 10/187.5.
                     * The least likely a battle can be to happen is with a VeryRare encounter rate, which has a chance of 1.25/187.5.
                     * Note the the encounter rate is not how likely it is for a certain Pokemon to be battled - it is how likely that a battle will happen at all. */
                    if ((r.NextDouble() * 187.5) < World.CurrentLevel.GrassEncounterRate)
                    {
                        /* A new array of ProportionValue<PokemonSpawn> objects is created with the length of the GrassSpawns in the current level.
                         * GrassSpawns is a list of PokemonSpawn objects for the level's grass, stating what Pokemon at what level can be encountered.
                         * The spawns array is filled with ProportionValues created using the PokemonSpawn's Percentage property, and the PokemonSpawn object itself. */
                        ProportionValue <PokemonSpawn>[] spawns = new ProportionValue <PokemonSpawn> [World.CurrentLevel.GrassSpawns.Count];
                        for (int i = 0; i < spawns.Length; i++) // NOTE TO SELF: IT WOULD BE MORE EFFICIENT TO CREATE THE ARRAY IN A HIGHER SCOPE, SINCE IT IS PART OF THE LEVEL, BUT THIS WILL DO FOR NOW.
                        {
                            spawns[i] = ProportionValue.Create(World.CurrentLevel.GrassSpawns[i].Percentage, World.CurrentLevel.GrassSpawns[i]);
                        }

                        /* The encounter for the spawn is found proportionally from the array using ChooseByRandom().
                         * A new Pokemon object is created using the encounter data's ID, gender, and minimum/maximum levels.
                         * The wild Pokemon's level is chosen randomly between the minimum and maximum level in the selected PokemonSpawn.
                         * The moveset is currently just "Scratch". Although dynamic moveset generation is not part of the user requirements,
                         * I could add it if I have time by choosing the last four moves that the species can learn before it reaches its level. */
                        PokemonSpawn encounter = spawns.ChooseByRandom();
                        Pokemon      p         = new Pokemon(DataManager.PokemonSpecies[encounter.ID], Pokemon.GetGender(DataManager.PokemonSpecies[encounter.ID].GenderRatio), new[] { DataManager.Moves["Scratch"], null, null, null }, (byte)PkmnUtils.RandomInclusive(encounter.MinLevel, encounter.MaxLevel), null);

                        /* A wild battle is essentially a fight against an enemy team of one Pokemon.
                         * The BattleScreen.InitBattle() is called, which sends the player and enemy to the screen and sets the battle background index to zero.
                         * Finally, the BattleScreen is pushed on to the state stack. */
                        GameRef.BattleScreen.InitBattle(player.Team, p, 0);
                        Change(ChangeType.Push, GameRef.BattleScreen);
                    }
                }
            }
        }
コード例 #12
0
        private string Ramdom(string data)
        {
            var srcs = data.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries).ToList();
            List <ProportionValue> listsrc = new List <ProportionValue>();

            foreach (var item in srcs)
            {
                ProportionValue model = new ProportionValue();
                if (!string.IsNullOrEmpty(item))
                {
                    var srcandratio = item.Split(new char[] { ':' }, StringSplitOptions.RemoveEmptyEntries).ToList();
                    model.Proportion = Convert.ToDouble(srcandratio[1]);
                    model.Value      = srcandratio[0];
                    listsrc.Add(model);
                }
            }
            return(ChooseByRandom(listsrc));
        }
コード例 #13
0
ファイル: MapLoader.cs プロジェクト: spyyouuu/easymoba
    public static List <Map> maps = new List <Map>(); // loaded maps

    private void Start()
    {
        // Load maps and nodes
        DataReader.readMaps(out maps);

        ushort mCount = (ushort)maps.Count;

        for (ushort i = 0; i < mCount; i++)
        {
            /*
             * CREATE PROPORTION RANDOM
             * */

            ushort cSpawns = (ushort)maps[i].creatureSpawns.Count;
            for (ushort b = 0; b < cSpawns; b++)
            {
                maps[i].creatureSpawns[b].clist = new ProportionValue <ushort> [maps[i].creatureSpawns[b].spawnObject.Length];
                ushort rVal = (ushort)maps[i].creatureSpawns[b].spawnObject.Length;
                for (ushort a = 0; a < rVal; a++)
                {
                    maps[i].creatureSpawns[b].clist[a] = ProportionValue.Create(maps[i].creatureSpawns[b].spawnObject[a].spawnRate, a);
                }
            }

            /*
             * END
             * */
            int sizeX = maps[i].data.width;
            int sizeY = maps[i].data.height;

            bool[][] movableMatrix = new bool[sizeX][];
            for (int widthTrav = 0; widthTrav < sizeX; widthTrav++)
            {
                movableMatrix[widthTrav] = new bool[sizeY];
                for (int heightTrav = 0; heightTrav < sizeY; heightTrav++)
                {
                    movableMatrix[widthTrav][heightTrav] = Mathf.RoundToInt(maps[i].data.GetPixel(widthTrav, heightTrav).r) < 0.1f;
                }
            }

            maps[i].aStar = new StaticGrid(sizeX, sizeY, movableMatrix);
        }
    }
コード例 #14
0
    // TODO: refactor this mess
    int GetNextOrbToSpawn()
    {
        int   num = (int)Spawner.weightForLastOrbDestroyed;
        float pctEmotionHealth = EmotionalHealth.currentEmotion / 100;
        float remainder        = (1 - pctEmotionHealth) / 2;

        if (num == 0)
        {
            var list = new[] {
                ProportionValue.Create(pctEmotionHealth, 0),
                ProportionValue.Create(remainder, 1),
                ProportionValue.Create(remainder, 2)
            };
            return(list.ChooseByRandom());
        }
        else if (num == 1)
        {
            var list = new[] {
                ProportionValue.Create(remainder, 0),
                ProportionValue.Create(pctEmotionHealth, 1),
                ProportionValue.Create(remainder, 2)
            };
            return(list.ChooseByRandom());
        }
        else if (num == 2)
        {
            var list = new[] {
                ProportionValue.Create(remainder, 0),
                ProportionValue.Create(remainder, 1),
                ProportionValue.Create(pctEmotionHealth, 2)
            };
            return(list.ChooseByRandom());
        }
        else
        {
            var list = new[] {
                ProportionValue.Create(pctEmotionHealth, 0),
                ProportionValue.Create(remainder, 1),
                ProportionValue.Create(remainder, 2)
            };
            return(list.ChooseByRandom());
        }
    }
コード例 #15
0
    private void SetDifficulty(GameDifficulty difficulty)
    {
        switch (difficulty)
        {
        case GameDifficulty.Easy:
            _easyWeight    = 0.6f;
            _mediumWeight  = 0.3f;
            _hardWeight    = 0.0f;
            _specialWeight = 0.1f;
            break;

        case GameDifficulty.Medium:
            _easyWeight    = 0.1f;
            _mediumWeight  = 0.6f;
            _hardWeight    = 0.1f;
            _specialWeight = 0.2f;
            break;

        case GameDifficulty.Hard:
            _easyWeight    = 0.0f;
            _mediumWeight  = 0.2f;
            _hardWeight    = 0.6f;
            _specialWeight = 0.2f;
            break;

        case GameDifficulty.Mixed:
            _easyWeight    = 0.25f;
            _mediumWeight  = 0.25f;
            _hardWeight    = 0.25f;
            _specialWeight = 0.25f;
            break;

        default:
            throw new ArgumentOutOfRangeException();
        }
        DifficultyValues = new List <ProportionValue <string> >
        {
            ProportionValue.Create(_easyWeight, "Easy"),
            ProportionValue.Create(_mediumWeight, "Medium"),
            ProportionValue.Create(_hardWeight, "Hard"),
            ProportionValue.Create(_specialWeight, "Special")
        };
    }
コード例 #16
0
    private void Start()
    {
        var random = new[]
        {
            ProportionValue.Create(0.2f, 25.0f),
            ProportionValue.Create(0.2f, -40.0f),
            ProportionValue.Create(0.2f, 35.0f),
            ProportionValue.Create(0.2f, -20.0f),
            ProportionValue.Create(0.2f, 50.0f)
        };

        rotateSpeed = random.ChoseByRandom();

        moveSpeed = Random.Range(1.0f, 3.0f);
        gm        = GM.Instance;
        if (gm == null)
        {
            Debug.LogError("GameManager not found!");
        }
    }
コード例 #17
0
    // Return a valid prefab
    public Prefab GetPrefab()
    {
        var validPrefabs = new List <ProportionValue <Prefab> >();

        var activePrefabs = prefabsTab[selectedTab].prefabs.Where(p => p.gameObject && p.active);

        if (activePrefabs.Count() > 1)
        {
            foreach (Prefab prefab in activePrefabs)
            {
                if (prefab.percent > 0.0f)
                {
                    validPrefabs.Add(ProportionValue.Create(prefab.percent, prefab));
                }
            }

            return(validPrefabs.ChooseRandomly());
        }

        return(activePrefabs.First());
    }
コード例 #18
0
 /* This static function uses the Gender Ratio of the Pokemon's species to randomly generate a Gender value for the Pokemon,
  * according to the proportions in the Gender Ratio. */
 public static Gender GetGender(GenderRatio ratio)
 {
     /* If the ratio's male and female values are both zero, the Pokemon is genderless. */
     if (ratio.male == 0 && ratio.female == 0)
     {
         return(Gender.none);
     }
     else
     {
         /* If the Pokemon can be male or female, the function uses the Mechanics.ProportionValue<T> class.
          * An array of two ProportionValue<Gender>s is created for the male and female proportion values.
          * The male and female ratioes are added to the array.
          * The ratios are bytes between 0 and 100, so they are converted to doubles between 0 and 1 to be used in the ProportionValue.
          * Finally, the ChooseByRandom() function is used to return a gender using the ratios from the GenderRatio passed in.
          * ChooseByRandom() works such that, for example, if the GenderRatio was 75 for male and 25 for female,
          * there is a 75% chance of the function returning male, and a 25% chance of it returning female. */
         ProportionValue <Gender>[] genders = new ProportionValue <Gender> [2];
         genders[0] = ProportionValue.Create(Convert.ToDouble(ratio.male) / 100, Gender.male);
         genders[1] = ProportionValue.Create(Convert.ToDouble(ratio.female) / 100, Gender.female);
         return(genders.ChooseByRandom());
     }
 }
コード例 #19
0
ファイル: MapGeneration.cs プロジェクト: bmgamedev/Honours
    private string PlatformerPathString(int maxIterations)
    {
        var rewriteS = new[]
        {
            ProportionValue.Create(0.33, "sffF"),
            ProportionValue.Create(0.33, "sffP"),
            ProportionValue.Create(0.34, "sffG"),
        };

        var rewriteP = new[]
        {
            ProportionValue.Create(0.25, "pP"),
            ProportionValue.Create(0.25, "pH"),
            ProportionValue.Create(0.25, "pG"),
            ProportionValue.Create(0.25, "pF"),
        };

        var rewriteH = new[]
        {
            ProportionValue.Create(0.1, "hH"),
            ProportionValue.Create(0.1, "hP"),
            ProportionValue.Create(0.1, "hF"),
            ProportionValue.Create(0.1, "hG"),

            ProportionValue.Create(0.15, "hghH"),
            ProportionValue.Create(0.15, "hghP"),
            ProportionValue.Create(0.15, "hghF"),
            ProportionValue.Create(0.15, "hghG"),
        };

        var rewriteF = new[]
        {
            ProportionValue.Create(0.33, "fF"),
            ProportionValue.Create(0.33, "fP"),
            ProportionValue.Create(0.34, "fG"),
        };

        var rewriteG = new[]
        {
            ProportionValue.Create(0.33, "gfP"),
            ProportionValue.Create(0.33, "gfG"),
            ProportionValue.Create(0.34, "gfF"),
        };

        string lastString = "S";
        string curString  = "";

        for (int i = 0; i < maxIterations; i++)
        {
            foreach (char c in lastString)
            {
                //for each char in string:
                switch (c)
                {
                case 'S':
                    curString += rewriteS.ChooseByRandom();
                    break;

                case 'F':
                    curString += rewriteF.ChooseByRandom();
                    break;

                case 'P':
                    curString += rewriteP.ChooseByRandom();
                    break;

                case 'H':
                    curString += rewriteH.ChooseByRandom();
                    break;

                case 'G':
                    curString += rewriteG.ChooseByRandom();
                    break;

                default:
                    //not a non-terminal symbol
                    curString += c;
                    break;
                }
            }

            //for each iteration, cur string = concatenate the combination of string returns from choosebyrandom and any terminals that aren't changed
            lastString = curString;
            curString  = "";
        }

        return(lastString += "e");
    }
コード例 #20
0
    void GetAction()
    {
        if (skills_attack.Length == 0)
        {
            return;
        }

        if (agent.skillStart != 0f)
        {
            return; // already in action
        }
        if (activeTarget != null)
        {
            distanceToActive = PhysikEngine.GetDistance(activeTarget.transform.position, transform.position);

            if (distanceToActive > vision)
            {
                activeTarget = null;
                return;
            }

            else if (!MapLoader.isBlocked(agent.session.map, transform.position, activeTarget.transform.position, false))  // TARGET IN SIGHT, SEARCH FOR SKILLS OR NOT MOVE TO TARGET
            {
                short tSpell = -1;

                /*
                 * DECIDE WITH PROPORTION RANDOM
                 * */
                /*
                 * */

                ProportionValue <ushort>[] clist = new ProportionValue <ushort> [skills_attack.Length];

                ushort rVal = (ushort)clist.Length;

                for (ushort r = 0; r < rVal; r++)
                {
                    ushort idx = (ushort)agent.skills.ToList().FindIndex(x => x == skills_attack[r]);
                    clist[r] = ProportionValue.Create((agent.cooldowns[idx] < Time.time) ? agent.skills[idx].botsDecideChance : 1, idx);
                }

                if (rVal > 1)
                {
                    rVal = clist.ChooseByRandom();
                }
                else
                {
                    rVal = clist[0].Value;
                }

                if (agent.skills[rVal].skillType != SkillType.Self)
                {
                    float distance = (agent.skills[rVal].skillType == SkillType.Area) ? 10 : (agent.skills[rVal].moveSpeed * agent.skills[rVal].life);

                    if ((distance * 3) / 4 > distanceToActive)
                    {
                        tSpell = (short)rVal;
                    }
                }
                else
                {
                    tSpell = (short)rVal;
                }

                if (tSpell != -1)
                {
                    /*
                     * CAST SPELL
                     * */
                    agent.session.LastAim(agent.customId, activeTarget.transform.position, transform.position);
                    agent.session.SkillRequest(agent.customId, (ushort)tSpell);
                    return;
                }
            }

            GetPath(activeTarget.transform.position);
        }
    }
コード例 #21
0
ファイル: MapGeneration.cs プロジェクト: bmgamedev/Honours
    private string DungeonPathString(int maxIterations, string firstChar)
    {
        //Need a different set of rewrite options for each different dominant direction

        //initial room
        var rewriteXn = new[]
        {
            ProportionValue.Create(1, "aj.fnnj.F"),
        };

        var rewriteXs = new[]
        {
            ProportionValue.Create(1, "bk.gssk.G"),
        };

        var rewriteXe = new[]
        {
            ProportionValue.Create(1, "cl.heel.H"),
        };

        var rewriteXw = new[]
        {
            ProportionValue.Create(1, "dm.iwwm.I"),
        };

        //final room
        var rewriteZn = new[]
        {
            ProportionValue.Create(1.0, "nnj.fz"),
        };

        var rewriteZs = new[]
        {
            ProportionValue.Create(1.0, "ssk.gz"),
        };

        var rewriteZe = new[]
        {
            ProportionValue.Create(1.0, "eel.hz"),
        };

        var rewriteZw = new[]
        {
            ProportionValue.Create(1.0, "wwm.iz"),
        };

        //subsequent rooms room
        var rewriteRn = new[]
        {
            ProportionValue.Create(0.5, "nnj.frl.H"), //exit room east
            ProportionValue.Create(0.5, "nnj.frm.I"), //exit room west
        };

        var rewriteRs = new[]
        {
            ProportionValue.Create(0.5, "ssk.grl.H"), //exit room east
            ProportionValue.Create(0.5, "ssk.grm.I"), //exit room west
        };

        var rewriteRe = new[]
        {
            ProportionValue.Create(0.5, "eel.hrj.F"), //exit room north
            ProportionValue.Create(0.5, "eel.hrk.G"), //exit room south
        };

        var rewriteRw = new[]
        {
            ProportionValue.Create(0.5, "wwm.irj.F"), //exit room north
            ProportionValue.Create(0.5, "wwm.irk.G"), //exit room south
        };

        //entry
        //Fn - fnN, feE, fwW
        var rewriteFn = new[]
        {
            ProportionValue.Create(0.33, "fnN"),
            ProportionValue.Create(0.33, "feE"),
            ProportionValue.Create(0.34, "fwW"),
        };
        //Fe - fnN, feE, fsS
        var rewriteFe = new[]
        {
            ProportionValue.Create(0.5, "fnN"),
            ProportionValue.Create(0.5, "feE"),
        };
        //Fw - fnN, fsS, fwW
        var rewriteFw = new[]
        {
            ProportionValue.Create(0.5, "fnN"),
            ProportionValue.Create(0.5, "fwW"),
        };
        //Hn - hnN, heE, hwW
        var rewriteHn = new[]
        {
            ProportionValue.Create(0.5, "hnN"),
            ProportionValue.Create(0.5, "heE"),
        };
        //Hs - hsS, heE, hwW
        var rewriteHs = new[]
        {
            ProportionValue.Create(0.5, "hsS"),
            ProportionValue.Create(0.5, "heE"),
        };
        //He - hnN, heE, hsS
        var rewriteHe = new[]
        {
            ProportionValue.Create(0.33, "hnN"),
            ProportionValue.Create(0.33, "heE"),
            ProportionValue.Create(0.34, "hsS"),
        };
        //Gs - gsS, geE, gwW
        var rewriteGs = new[]
        {
            ProportionValue.Create(0.33, "gsS"),
            ProportionValue.Create(0.33, "geE"),
            ProportionValue.Create(0.34, "gwW"),
        };
        //Ge - gnN, geE, gsS
        var rewriteGe = new[]
        {
            ProportionValue.Create(0.5, "geE"),
            ProportionValue.Create(0.5, "gsS"),
        };
        //Gw - gnN, gsS, gwW
        var rewriteGw = new[]
        {
            ProportionValue.Create(0.5, "gsS"),
            ProportionValue.Create(0.5, "gwW"),
        };
        //In - inN, ieE, iwW
        var rewriteIn = new[]
        {
            ProportionValue.Create(0.5, "inN"),
            ProportionValue.Create(0.5, "iwW"),
        };
        //Is - isS, ieE, iwW
        var rewriteIs = new[]
        {
            ProportionValue.Create(0.5, "isS"),
            ProportionValue.Create(0.5, "iwW"),
        };
        //Iw - inN, isS, iwW
        var rewriteIw = new[]
        {
            ProportionValue.Create(0.33, "isS"),
            ProportionValue.Create(0.33, "inN"),
            ProportionValue.Create(0.34, "iwW"),
        };

        //direction
        //Nn - nj.F, nl.H, nm.I
        var rewriteNn = new[]
        {
            ProportionValue.Create(0.33, "nj.F"),
            ProportionValue.Create(0.33, "nl.H"),
            ProportionValue.Create(0.34, "nm.I"),
        };
        //Ne - nj.F, nl.H, nk.G
        var rewriteNe = new[]
        {
            ProportionValue.Create(0.5, "nj.F"),
            ProportionValue.Create(0.5, "nl.H"),
        };
        //Nw - nj.F, nm.I, nk.G
        var rewriteNw = new[]
        {
            ProportionValue.Create(0.5, "nj.F"),
            ProportionValue.Create(0.5, "nm.I"),
        };
        //En - ej.F, el.H, em.I
        var rewriteEn = new[]
        {
            ProportionValue.Create(0.5, "ej.F"),
            ProportionValue.Create(0.5, "el.H"),
        };
        //Es - em.I, ek.G, el.H
        var rewriteEs = new[]
        {
            ProportionValue.Create(0.5, "ek.G"),
            ProportionValue.Create(0.5, "el.H"),
        };
        //Ee - ej.F, el.H, ek.G
        var rewriteEe = new[]
        {
            ProportionValue.Create(0.33, "ek.G"),
            ProportionValue.Create(0.33, "el.H"),
            ProportionValue.Create(0.34, "ej.F"),
        };
        //Ss - sm.I, sk.G, sl.H
        var rewriteSs = new[]
        {
            ProportionValue.Create(0.33, "sk.G"),
            ProportionValue.Create(0.33, "sl.H"),
            ProportionValue.Create(0.34, "sm.I"),
        };
        //Sw - sj.F, sm.I, sk.G
        var rewriteSw = new[]
        {
            ProportionValue.Create(0.5, "sk.G"),
            ProportionValue.Create(0.5, "sm.I"),
        };
        //Se - sj.F, sl.H, sk.G
        var rewriteSe = new[]
        {
            ProportionValue.Create(0.5, "sk.G"),
            ProportionValue.Create(0.5, "sl.H"),
        };
        //Ww - wj.F, wm.I, wk.G
        var rewriteWw = new[]
        {
            ProportionValue.Create(0.33, "wk.G"),
            ProportionValue.Create(0.33, "wj.F"),
            ProportionValue.Create(0.34, "wm.I"),
        };
        //Wn - wj.F, wl.H, wm.I
        var rewriteWn = new[]
        {
            ProportionValue.Create(0.5, "wj.F"),
            ProportionValue.Create(0.5, "wm.I"),
        };
        //Ws - wm.I, wk.G, wl.H
        var rewriteWs = new[]
        {
            ProportionValue.Create(0.5, "wk.G"),
            ProportionValue.Create(0.5, "wm.I"),
        };



        string lastString = firstChar;
        string curString  = "";

        for (int i = 0; i < maxIterations; i++)
        {
            foreach (char c in lastString)
            {
                if (domDir == DominantDirection.NORTH)
                {
                    switch (c)
                    {
                    case 'I':
                        curString += rewriteIn.ChooseByRandom();
                        break;

                    case 'R':
                        curString += rewriteRn.ChooseByRandom();
                        break;

                    case 'F':
                        curString += rewriteFn.ChooseByRandom();
                        break;

                    case 'X':
                        curString += rewriteXn.ChooseByRandom();
                        break;

                    case 'Z':
                        curString += rewriteZn.ChooseByRandom();
                        break;

                    case 'W':
                        curString += rewriteWn.ChooseByRandom();
                        break;

                    case 'E':
                        curString += rewriteEn.ChooseByRandom();
                        break;

                    case 'N':
                        curString += rewriteNn.ChooseByRandom();
                        break;

                    case 'H':
                        curString += rewriteHn.ChooseByRandom();
                        break;

                    default:     //not a non-terminal symbol
                        curString += c;
                        break;
                    }
                }
                else if (domDir == DominantDirection.SOUTH)
                {
                    switch (c)
                    {
                    case 'I':
                        curString += rewriteIs.ChooseByRandom();
                        break;

                    case 'R':
                        curString += rewriteRs.ChooseByRandom();
                        break;

                    case 'G':
                        curString += rewriteGs.ChooseByRandom();
                        break;

                    case 'X':
                        curString += rewriteXs.ChooseByRandom();
                        break;

                    case 'Z':
                        curString += rewriteZs.ChooseByRandom();
                        break;

                    case 'W':
                        curString += rewriteWs.ChooseByRandom();
                        break;

                    case 'E':
                        curString += rewriteEs.ChooseByRandom();
                        break;

                    case 'S':
                        curString += rewriteSs.ChooseByRandom();
                        break;

                    case 'H':
                        curString += rewriteHs.ChooseByRandom();
                        break;

                    default:     //not a non-terminal symbol
                        curString += c;
                        break;
                    }
                }
                else if (domDir == DominantDirection.EAST)
                {
                    switch (c)
                    {
                    case 'F':
                        curString += rewriteFe.ChooseByRandom();
                        break;

                    case 'R':
                        curString += rewriteRe.ChooseByRandom();
                        break;

                    case 'G':
                        curString += rewriteGe.ChooseByRandom();
                        break;

                    case 'X':
                        curString += rewriteXe.ChooseByRandom();
                        break;

                    case 'Z':
                        curString += rewriteZe.ChooseByRandom();
                        break;

                    case 'N':
                        curString += rewriteNe.ChooseByRandom();
                        break;

                    case 'E':
                        curString += rewriteEe.ChooseByRandom();
                        break;

                    case 'S':
                        curString += rewriteSe.ChooseByRandom();
                        break;

                    case 'H':
                        curString += rewriteHe.ChooseByRandom();
                        break;

                    default:     //not a non-terminal symbol
                        curString += c;
                        break;
                    }
                }
                else if (domDir == DominantDirection.WEST)
                {
                    switch (c)
                    {
                    case 'F':
                        curString += rewriteFw.ChooseByRandom();
                        break;

                    case 'R':
                        curString += rewriteRw.ChooseByRandom();
                        break;

                    case 'G':
                        curString += rewriteGw.ChooseByRandom();
                        break;

                    case 'X':
                        curString += rewriteXw.ChooseByRandom();
                        break;

                    case 'Z':
                        curString += rewriteZw.ChooseByRandom();
                        break;

                    case 'N':
                        curString += rewriteNw.ChooseByRandom();
                        break;

                    case 'W':
                        curString += rewriteWw.ChooseByRandom();
                        break;

                    case 'S':
                        curString += rewriteSw.ChooseByRandom();
                        break;

                    case 'I':
                        curString += rewriteIw.ChooseByRandom();
                        break;

                    default:     //not a non-terminal symbol
                        curString += c;
                        break;
                    }
                }
            }

            //for each iteration, cur string = concatenate the combination of string returns from choosebyrandom and any terminals that aren't changed
            lastString = curString;
            curString  = "";
        }

        return(lastString);
    }
コード例 #22
0
    void GetSupport()
    {
        if (skills_defense.Length == 0)
        {
            return;
        }

        MobileAgent ally = agent.session.agents.Find(x => (x == agent || (x.team == agent.team && agent.session.teamsize != 0)) && !x.isDead && x.health < x.maxHealth / 2 && (x == agent || PhysikEngine.GetDistance(x.transform.position, agent.transform.position) <= 20));

        if (ally == null)
        {
            return;
        }

        if (ally != agent && agent.session.teamsize == 0)
        {
            ally = agent;
        }

        if (ally == agent || !MapLoader.isBlocked(agent.session.map, transform.position, ally.transform.position, false)) // TARGET IN SIGHT
        {
            short tSpell = -1;

            /*
             * DECIDE WITH PROPORTION RANDOM
             * */
            /*
             * */

            ProportionValue <ushort>[] clist = new ProportionValue <ushort> [skills_defense.Length];

            ushort rVal = (ushort)clist.Length;

            for (ushort r = 0; r < rVal; r++)
            {
                ushort idx = (ushort)agent.skills.ToList().FindIndex(x => x == skills_defense[r]);
                clist[r] = ProportionValue.Create((agent.cooldowns[idx] < Time.time) ? agent.skills[idx].botsDecideChance : 1, idx);
            }

            if (rVal > 1)
            {
                rVal = clist.ChooseByRandom();
            }
            else
            {
                rVal = clist[0].Value;
            }

            float distance = (agent.skills[rVal].skillType == SkillType.Area) ? 10 : (agent.skills[rVal].moveSpeed * agent.skills[rVal].life);

            if ((distance * 3) / 4 > distanceToActive)
            {
                tSpell = (short)rVal;
            }

            if (tSpell != -1)
            {
                /*
                 * CAST SPELL
                 * */
                agent.session.LastAim(agent.customId, ally.transform.position, transform.position);
                agent.session.SkillRequest(agent.customId, (ushort)tSpell);
                return;
            }
        }
        //
    }