Example #1
0
    void Start()
    {
        gm      = GameObject.Find("GameManager").GetComponent <GameManager>();
        cs      = ColorScheme.baseColor;
        botType = gm.botType;

        ss              = gm.softSign;
        numberOfInputs  = gm.nInputs;
        numberOfOutputs = gm.nOutputs;
        numberOfHidden  = gm.nHidden;
        numberOfLayers  = gm.nLayers;
        ammo            = gm.shotsPerRound;
        bulletSpeed     = gm.bulletSpeed;
        fireRate        = gm.fireRate;
        movementSpeed   = gm.botMoveSpeed;
        rb              = GetComponent <Rigidbody2D>();
        bullet.GetComponent <Bullet>().movementSpeed = bulletSpeed;
        CheckType();

        sr        = GetComponent <SpriteRenderer>();
        baseColor = sr.color;

        nn             = new NeuralNetwork(numberOfInputs, numberOfOutputs, numberOfHidden, numberOfLayers); //Currently using non parametrized constructor.
        ID             = gameObject.name;
        enemy          = GameObject.Find("Enemy");
        scoreHitTarget = gm.hitScore;
        paused         = false;
    }
Example #2
0
    public float[] CalculateOutput(float[] inp, SoftSign ss)
    {
        float[] nextOutVal = new float[0];
        int     count      = 0;

        foreach (Matrix wi in wm)
        {
            count++;
            int     sizeIn = inp.Length;
            float[] input  = new float[sizeIn + 1];
            //Debug.Log(sizeIn);
            for (int i = 0; i < sizeIn - 1; i++)
            {
                input[i] = inp[i];
            }
            input[sizeIn] = 1; //bias term
            nextOutVal    = Vector.matVecMult(input, wi);
            if (count != wm.Count)
            {
                nextOutVal = Relu(nextOutVal);
            }
            inp = nextOutVal;
        }
        switch (ss)
        {
        case SoftSign.yes:
            return(Softsign(nextOutVal));

        case SoftSign.no:
            return(nextOutVal);
        }
        return(null); //NORMAL SOFTSIGN MODE
        //return nextOutVal; //FOR TESTING WITHOUT SOFTSIGN;
    }