コード例 #1
0
    private void DebugTestBayes()
    {
        int[] discValues = new int[2];
        discValues[0] = 0;           // No enemies in way
        discValues[1] = 0;           // No enemies at gate

        int[] contValues = new int[2];
        contValues[0] = 66;                    // gate health
        contValues[1] = 10;                    // dist

        if (bd.Decide(contValues, discValues)) // <- We pass in the arrays we built above ^
        {
            Debug.Log("Let's repair!");
        }
        else
        {
            Debug.Log("Let's not and say we did.");
        }

        Debug.Log("Added last case with true outcome");
        bd.AddObservation(contValues, discValues, 0);
        bd.Tab2Screen();
        bd.BuildStats();
    }
コード例 #2
0
ファイル: BayesScript.cs プロジェクト: ckaron0912/Siege
    // 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
        }
    }
コード例 #3
0
ファイル: BayesBuilder.cs プロジェクト: ckaron0912/Siege
    public void TestBayes()
    {
        if (gate.hp < 100)
        {
            int gateHealth = Mathf.RoundToInt(Mathf.Max(0, gate.hp));

            float dist = Vector3.Distance(gate.transform.position, transform.position);

            Vector3 dir = (gate.transform.position - transform.position).normalized;

            RaycastHit[] hits = Physics.SphereCastAll(transform.position,
                                                      1.0f,
                                                      dir,
                                                      dist - 1.0f,
                                                      attackerSearchLayerMask);

            bool attackersInWay = false;
            for (int i = 0; i < hits.Length; i++)
            {
                if (hits[i].collider.gameObject.tag == "Attacker")
                {
                    attackersInWay = true;
                    break;
                }
            }

            float      radius = 10f;
            Vector3    pos    = gate.transform.position + dir * radius;
            Collider[] cols   = Physics.OverlapSphere(pos, radius, attackerSearchLayerMask);

            bool attackersAtGate = false;
            for (int i = 0; i < cols.Length; i++)
            {
                if (cols[i].gameObject.tag == "Attacker")
                {
                    attackersAtGate = true;
                    break;
                }
            }

            int[] discValues = new int[2];
            discValues[0] = (attackersInWay ? 1 : 0);
            discValues[1] = (attackersAtGate ? 1 : 0);

            int[] contValues = new int[2];
            contValues[0] = gateHealth;
            contValues[1] = Mathf.RoundToInt(dist);

            bool doIt = bd.Decide(contValues, discValues);

            string debug = "Attackers In Path: " + attackersInWay;
            debug += "\nAttackers At Gate: " + attackersAtGate;
            debug += "\nGate Health: " + gateHealth;
            debug += "\nDistance: " + dist;
            debug += "\nRepair?: " + doIt;
            //Debug.Log( debug );

            currObservation.continuousValues = contValues;
            currObservation.discreteValues   = discValues;
            currObservation.outcome          = (doIt ? 0 : 1);

            //Debug.Log( doIt );

            if (doIt)
            {
                doingIt = true;
                StartCoroutine(MonitorDoIt(dist));
            }
            else
            {
                StartCoroutine(MonitorDecision(dist));
            }
        }
    }