Exemple #1
0
    public override void updateOutputs()
    {
        //fuzzyficazione
        bfl = bombsFarLeft.calculateMembership(sensor.bombFunction);
        bl  = bombsLeft.calculateMembership(sensor.bombFunction);
        br  = bombsRight.calculateMembership(sensor.bombFunction);
        bfr = bombsFarRight.calculateMembership(sensor.bombFunction);

        bdl = boundCloseLeft.calculateMembership(sensor.boundDistance);
        bdr = boundCloseRight.calculateMembership(sensor.boundDistance);

        //FAM
        hardLeft  = FuzzyLib.fuzzyOr(br, bdr);
        left      = bfr;
        right     = bfl;
        hardRight = FuzzyLib.fuzzyOr(bl, bdl);

        //defuzzyficazione
        movementOutput = hardLeft * (-0.8f) + left * (-0.4f) + right * (0.4f) + hardRight * (0.8f);

        //display
        List <string> message = new List <string>();

        message.Add("==AVOID==");
        message.Add("bombs distance:");
        message.Add(bfl.ToString("F2") + "|" + bl.ToString("F2") + "|" + br.ToString("F2") + "|" + bfr.ToString("F2"));
        message.Add("bound distance:");
        message.Add(bdl.ToString("F2") + "|" + bdr.ToString("F2"));
        message.Add("movement:");
        message.Add(hardLeft.ToString("F2") + "|" + left.ToString("F2") + "|" + right.ToString("F2") + "|" + hardRight.ToString("F2"));
        message.Add("shooting");
        message.Add("false");

        setDisplayMessage(message);
    }
Exemple #2
0
    public override void updateOutputs()
    {
        //fuzzyficazione
        sfl = shieldFarLeft.calculateMembership(sensor.shieldDistance);
        sl  = shieldLeft.calculateMembership(sensor.shieldDistance);
        sr  = shieldRight.calculateMembership(sensor.shieldDistance);
        sfr = shieldFarRight.calculateMembership(sensor.shieldDistance);

        //FAM
        hardLeft  = FuzzyLib.fuzzyOr(sl, sfl);
        left      = 0;
        right     = 0;
        hardRight = FuzzyLib.fuzzyOr(sr, sfr);

        //defuzzyficazione
        spacebarOutput = false;
        movementOutput = hardLeft * (-0.8f) + left * (-0.4f) + right * (0.4f) + hardRight * (0.8f);

        //display
        List <string> message = new List <string>();

        message.Add("==SHELTER==");
        message.Add("shield distance:");
        message.Add(sfl.ToString("F2") + "|" + sl.ToString("F2") + "|" + sr.ToString("F2") + "|" + sfr.ToString("F2"));
        message.Add("movement:");
        message.Add(hardLeft.ToString("F2") + "|" + left.ToString("F2") + "|" + right.ToString("F2") + "|" + hardRight.ToString("F2"));
        message.Add("shooting");
        message.Add(spacebarOutput.ToString());

        setDisplayMessage(message);
    }
    public override void updateOutputs()
    {
        //variabile composta
        float targetPosition = sensor.redShipDistance + sensor.redShipLead;

        //fuzzyficazione
        float tgp, tgpp, tgppp, tgn, tgnn, tgnnn;

        tgp   = targetCloseRight.calculateMembership(targetPosition);
        tgpp  = targetRight.calculateMembership(targetPosition);
        tgppp = targetFarRight.calculateMembership(targetPosition);
        tgn   = targetCloseLeft.calculateMembership(targetPosition);
        tgnn  = targetLeft.calculateMembership(targetPosition);
        tgnnn = targetFarLeft.calculateMembership(targetPosition);

        float shield;

        shield = underShield.calculateMembership(sensor.shieldDistance);

        //FAM

        float hardLeft, left, right, hardRight;

        hardLeft  = FuzzyLib.fuzzyOr(tgn, FuzzyLib.fuzzyOr(tgnn, tgnnn));
        hardRight = FuzzyLib.fuzzyOr(tgp, FuzzyLib.fuzzyOr(tgpp, tgppp));
        left      = 0;
        right     = 0;

        //defuzzyficazione
        movementOutput = -0.8f * hardLeft - 0.4f * left + 0.4f * right + 0.8f * hardRight;
        spacebarOutput = FuzzyLib.toBool(FuzzyLib.fuzzyNot(shield));

        //display
        List <string> message = new List <string>();

        message.Add("==ATK RED SHIP==");
        message.Add("target distance:");
        message.Add(tgnnn.ToString("F2") + "|" + tgnn.ToString("F2") + "|" + tgn.ToString("F2") + (" l"));
        message.Add(tgp.ToString("F2") + "|" + tgpp.ToString("F2") + "|" + tgppp.ToString("F2") + (" r"));
        message.Add("shooting");
        message.Add(spacebarOutput.ToString());

        setDisplayMessage(message);
    }
Exemple #4
0
    public void selectBehaviour()
    {
        //fuzzyficazione
        float dngl, dngm, dngh;

        dngl = dangerLow.calculateMembership(sensor.danger);
        dngm = dangerMedium.calculateMembership(sensor.danger);
        dngh = dangerHigh.calculateMembership(sensor.danger);

        float shc, shf;

        shc = shieldClose.calculateMembership(Mathf.Abs(sensor.shieldDistance));
        shf = shieldFar.calculateMembership(Mathf.Abs(sensor.shieldDistance));

        float rs;

        rs = redShipPresent.calculateMembership(sensor.redShipPresent);

        float sw, sm, ss;

        sw = screenWeak.calculateMembership(sensor.redShipScreen);
        sm = screenMedium.calculateMembership(sensor.redShipScreen);
        ss = screenStrong.calculateMembership(sensor.redShipScreen);

        float dh, du, dv;

        dh = distributionHorizontal.calculateMembership(sensor.alienDistributionIndex);
        du = distributionUndefined.calculateMembership(sensor.alienDistributionIndex);
        dv = distributionVertical.calculateMembership(sensor.alienDistributionIndex);

        float lwh, lwl;

        lwh = lowestAlienHigh.calculateMembership(sensor.lowestAlienHeight);
        lwl = lowestAlienLow.calculateMembership(sensor.lowestAlienHeight);

        //FAM
        float defend = FuzzyLib.fuzzyOr(dngm, dngh);
        float attack = dngl;

        //avoid = defend & !shc
        behaviours[avoid] = FuzzyLib.fuzzyAnd(defend, shf);

        //shelter = defend & shc
        behaviours [shelter] = FuzzyLib.fuzzyAnd(defend, shc);

        //atkred = attack & pres & (sw | dv | (sm & du & lwh))
        behaviours[atkRedship] = FuzzyLib.fuzzyAnd(
            attack,
            rs,
            FuzzyLib.fuzzyOr(sw, dv, FuzzyLib.fuzzyAnd(sm, du, lwh)));

        //atkClosest = attack & lwh & (dh | (!rs & (du | dv)))
        behaviours[atkClosest] = FuzzyLib.fuzzyAnd(
            attack,
            lwh,
            FuzzyLib.fuzzyOr(
                dh,
                FuzzyLib.fuzzyAnd(
                    FuzzyLib.fuzzyNot(rs),
                    FuzzyLib.fuzzyOr(du, dv))));

        //atkLowest = attack & lwl
        behaviours[atkLowest] = FuzzyLib.fuzzyAnd(attack, lwl);

        //defuzzyficazione
        behaviourIndex = MyUtils.argmax(behaviours);

        //display
        List <string> message = new List <string>();

        message.Add("==SELECTOR==");
        message.Add("danger level:");
        message.Add(dngl.ToString("F2") + "|" + dngm.ToString("F2") + "|" + dngh.ToString("F2"));
        message.Add("shield:");
        message.Add(shc.ToString("F2") + "|" + shf.ToString("F2"));
        message.Add("red ship present:");
        message.Add(rs.ToString("F2"));
        if (sensor.redShipPresent > 0)
        {
            message.Add("red ship screen:");
            message.Add(sw.ToString("F2") + "|" + sm.ToString("F2") + "|" + ss.ToString("F2"));
        }
        message.Add("alien distribution:");
        message.Add(dh.ToString("F2") + "|" + du.ToString("F2") + "|" + dv.ToString("F2"));
        message.Add("lowest alien height:");
        message.Add(lwh.ToString("F2") + "|" + lwl.ToString("F2"));
        message.Add("behavior index:");
        message.Add(behaviourIndex.ToString());

        setDisplayMessage(message);
    }
    public override void updateOutputs()
    {
        //variabile composta
        float targetPosition = sensor.lowestAlienDistance + sensor.lowestAlienLead;

        //fuzzyficazione
        float tgp, tgpp, tgppp, tgn, tgnn, tgnnn;

        tgp   = targetCloseRight.calculateMembership(targetPosition);
        tgpp  = targetRight.calculateMembership(targetPosition);
        tgppp = targetFarRight.calculateMembership(targetPosition);
        tgn   = targetCloseLeft.calculateMembership(targetPosition);
        tgnn  = targetLeft.calculateMembership(targetPosition);
        tgnnn = targetFarLeft.calculateMembership(targetPosition);

        float shield;

        shield = underShield.calculateMembership(sensor.shieldDistance);

        float sp, spp, sppp, sn, snn, snnn;

        sp   = speedLowPositive.calculateMembership(sensor.alienVelocity);
        spp  = speedMediumPositive.calculateMembership(sensor.alienVelocity);
        sppp = speedHighPositive.calculateMembership(sensor.alienVelocity);
        sn   = speedLowNegative.calculateMembership(sensor.alienVelocity);
        snn  = speedMediumNegative.calculateMembership(sensor.alienVelocity);
        snnn = speedHighNegative.calculateMembership(sensor.alienVelocity);

        //FAM
        float hardRight, right, hardLeft, left;
        float tgMovingRight, tgMovingLeft;
        float tgIsRight, tgIsLeft;

        // tgppp
        //OR
        // tgpp & (mvright | sn)
        //OR
        // shield & isright
        tgMovingRight = FuzzyLib.fuzzyOr(sp, spp, sppp);
        tgIsRight     = FuzzyLib.fuzzyOr(tgp, tgpp, tgppp);
        hardRight     = tgppp;
        hardRight     = FuzzyLib.fuzzyOr(hardRight, FuzzyLib.fuzzyAnd(tgpp, FuzzyLib.fuzzyOr(tgMovingRight, sn)));
        hardRight     = FuzzyLib.fuzzyOr(hardRight, FuzzyLib.fuzzyAnd(shield, tgIsRight));

        // tgp
        //OR
        // (tgpp & (tgnn | tgnnn))
        tgMovingLeft = FuzzyLib.fuzzyOr(tgnn, tgnnn);
        right        = FuzzyLib.fuzzyOr(tgp, FuzzyLib.fuzzyAnd(tgpp, tgMovingLeft));
        right        = FuzzyLib.fuzzyAnd(right, FuzzyLib.fuzzyNot(shield));

        // tgn
        //OR
        // (tgnn & (tgpp | tgppp))
        tgMovingRight = FuzzyLib.fuzzyOr(tgpp, tgppp);
        left          = FuzzyLib.fuzzyOr(tgn, FuzzyLib.fuzzyAnd(tgnn, tgMovingRight));
        left          = FuzzyLib.fuzzyAnd(left, FuzzyLib.fuzzyNot(shield));

        // tgnnn
        //OR
        // (tgnn & (mvleft | sp)
        //OR
        // shield & isleft
        tgMovingLeft = FuzzyLib.fuzzyOr(sn, snn, snnn);
        tgIsLeft     = FuzzyLib.fuzzyOr(tgn, tgnn, tgnnn);
        hardLeft     = tgnnn;
        hardLeft     = FuzzyLib.fuzzyOr(hardLeft, FuzzyLib.fuzzyAnd(tgnn, FuzzyLib.fuzzyOr(tgMovingLeft, sp)));
        hardLeft     = FuzzyLib.fuzzyOr(hardLeft, FuzzyLib.fuzzyAnd(shield, tgIsLeft));

        //defuzzyficazione
        movementOutput = (-0.8f) * hardLeft + (-0.4f) * left + 0.4f * right + 0.8f * hardRight;

        if ((left + hardLeft + right + hardRight) > 1)
        {
            Debug.Log(left.ToString("F2") + hardLeft.ToString("F2") + right.ToString("F2") + hardRight.ToString("F2"));
        }


        spacebarOutput = FuzzyLib.toBool(FuzzyLib.fuzzyNot(shield));

        //display
        List <string> message = new List <string>();

        message.Add("==ATK LOWEST==");
        message.Add("target distance:");
        message.Add(tgnnn.ToString("F2") + "|" + tgnn.ToString("F2") + "|" + tgn.ToString("F2") + (" l"));
        message.Add(tgp.ToString("F2") + "|" + tgpp.ToString("F2") + "|" + tgppp.ToString("F2") + (" r"));
        message.Add("target velocity:");
        message.Add(snnn.ToString("F2") + "|" + snn.ToString("F2") + "|" + sn.ToString("F2") + (" l"));
        message.Add(sp.ToString("F2") + "|" + spp.ToString("F2") + "|" + sppp.ToString("F2") + (" r"));
        message.Add("shield:");
        message.Add(shield.ToString("F2"));
        message.Add("movement:");
        message.Add(hardLeft.ToString("F2") + "|" + left.ToString("F2") + "|" + right.ToString("F2") + "|" + hardRight.ToString("F2"));
        message.Add("shooting");
        message.Add(spacebarOutput.ToString());

        setDisplayMessage(message);
    }