示例#1
0
 public void Die()
 {
     if (currObservation.outcome != -1)
     {
         if (currObservation.outcome == 0)
         {
             currObservation.outcome = 1;
             bd.AddObservation(currObservation);
         }
     }
 }
示例#2
0
    void Update()
    {
        if (Input.GetKeyDown(KeyCode.A))
        {
            gate.hp -= 20;
            Debug.Log("Gate Damaged. HP: " + gate.hp);

            if (gate.hp <= 0)
            {
                Debug.Log("Gate broke");
            }
        }
        else if (Input.GetKeyDown(KeyCode.S))
        {
            Debug.Log("Saving");
            bd.Tab2File();
        }
        else if (Input.GetKeyDown(KeyCode.D))
        {
            bd.Tab2Screen();
        }
        else if (Input.GetKeyDown(KeyCode.Space))
        {
            if (!doingIt)
            {
                TestBayes();
            }
            //DebugTestBayes();
        }
        else if (Input.GetKeyDown(KeyCode.E))
        {
            bd.DumpStats();
        }

        if (currObservation.outcome != -1)
        {
            if (Input.GetKeyDown(KeyCode.Minus))
            {
                currObservation.outcome = 1;
                bd.AddObservation(currObservation);
                Debug.Log("Added Observation as negative");
                bd.BuildStats();
            }
            else if (Input.GetKeyDown(KeyCode.Equals))
            {
                currObservation.outcome = 0;
                bd.AddObservation(currObservation);
                Debug.Log("Added Observation as positive");
                bd.BuildStats();
            }
        }

        if (doingIt)
        {
            Vector3 pos       = transform.position;
            Vector3 targetPos = gate.transform.position;
            transform.position = Vector3.MoveTowards(pos, targetPos, moveSpeed * Time.deltaTime);
        }
    }
示例#3
0
    // For this example, hitting the spacebar will test a situation that is a "shouldn't play"
    // Then it adds the situation to the table as a "should play" to stack the odds
    // Eventually it will start saying yes
    void Update()
    {
        if (Input.GetKeyDown(KeyCode.Space))
        {
            Debug.Log("Test a day that's sunny, windy, temp 50, humidity 90");

            // This is where we assemble a situation for the Decider to test

            // We need to assemble an array of discrete and continuous values to test
            // Like how the conditions above had to be in the same order as the data file,
            // these values must be in the same order as the conditions that the values represent
            int[] discValues = new int[2];
            discValues[0] = 0;               // Outlook, 0 = sunny
            discValues[1] = 0;               // Windy, 0 = true

            int[] contValues = new int[2];
            contValues[0] = 66;               // temperature
            contValues[1] = 90;               // humidity

            // BayesDecider.Decide returns true/false to perform the action based on the values
            if (bd.Decide(contValues, discValues))                // <- We pass in the arrays we built above ^
            {
                Debug.Log("Let's play a round!");
            }
            else
            {
                Debug.Log("Let's stay home.");
            }

            Debug.Log("Added last case with true outcome");

            // Now we add an observation with the values and an outcome
            // We have to decide the outcome (ie if a character dies, it was a bad outcome)
            bd.AddObservation(contValues, discValues, 0);
            bd.Tab2Screen();
            bd.BuildStats();             // Then we rebuild the stats

            // You can also call BayesDecider.Tab2File to save the observation table
            // Just note that it will write over the existing file, so keeping a backup is a good idea
        }
    }