예제 #1
0
    // This method is invoked when a new enemy is spawned
    public void NotifyEnemySpawned(Enemy enemy)
    {
        // Only do something if AI is in charge of player
        if (IsAI)
        {
            // Ask AI to make a prediction and choose weapon
            string weaponStr = nbClassifier.Predict(
                new Dictionary <Attrib, string>()
            {
                { enemyTypeAttrib, enemy.Type.ToString() },
                { speedAttrib, enemy.SpeedCategory.ToString() }
            });

            // Convert the string returned by the AI into a weapon
            Enum.TryParse <PlayerWeapon>(weaponStr, out weapon);

            // Check what weapon was selected and act upon it
            switch (weapon)
            {
            case PlayerWeapon.Bow:
                spriteRenderer.sprite = bowSprite;
                break;

            case PlayerWeapon.Sword:
                spriteRenderer.sprite = swordSprite;
                break;
            }
        }
    }
예제 #2
0
    // Update is called once per frame
    void Update()
    {
        if (roomsEntered == nValue + 1)
        {
            roomsEntered = 0;
            //Debug.Log(lastRoomsVisited);
            nGramPredictor.RegisterSequence(lastRoomsVisited);
            lastRoomsVisited = new List <int>();
        }
        List <bool> stuffToClassify = new List <bool>()
        {
            guard.playerSighted, GameObject.Find("GameState").GetComponent <GameState>().alarm
        };

        guard.playerAggressive = bayesClassifier.Predict(stuffToClassify);
        Debug.Log("Aggressive: " + guard.playerAggressive);
    }
예제 #3
0
 public override Prediction <LblT> Predict(SparseVector <double> example)
 {
     return(mModel.Predict((BinaryVector)ModelUtils.ConvertExample(example, typeof(BinaryVector))));
 }
예제 #4
0
        static void Main(string[] args)
        {
            // Create two attributes and specify their possible values
            Attrib distance =
                new Attrib("distance", new string[] { "near", "far" });
            Attrib speed =
                new Attrib("speed", new string[] { "slow", "fast" });

            // Create a naive Bayes classifier with a set of labels and a
            // set of attributes
            NaiveBayesClassifier nbc = new NaiveBayesClassifier(
                new string[] { "Y", "N" },
                new Attrib[] { distance, speed });

            // Pass a few observations to the naive Bayes classifier

            nbc.Update("Y", new Dictionary <Attrib, string>()
            {
                { distance, "near" },
                { speed, "slow" }
            });

            nbc.Update("Y", new Dictionary <Attrib, string>()
            {
                { distance, "near" },
                { speed, "fast" }
            });

            nbc.Update("N", new Dictionary <Attrib, string>()
            {
                { distance, "far" },
                { speed, "fast" }
            });

            nbc.Update("Y", new Dictionary <Attrib, string>()
            {
                { distance, "far" },
                { speed, "fast" }
            });

            nbc.Update("N", new Dictionary <Attrib, string>()
            {
                { distance, "near" },
                { speed, "slow" }
            });

            nbc.Update("Y", new Dictionary <Attrib, string>()
            {
                { distance, "far" },
                { speed, "slow" }
            });

            nbc.Update("Y", new Dictionary <Attrib, string>()
            {
                { distance, "near" },
                { speed, "fast" }
            });

            // Make a prediction given a set of attribute-value pairs
            string prediction = nbc.Predict(new Dictionary <Attrib, string>()
            {
                { distance, "far" },
                { speed, "slow" }
            });

            // Show prediction
            Console.WriteLine($"Brake? {prediction}");
        }