Пример #1
0
    private void Update()
    {
        if (networkvisual == null)
        {
            networkvisual = GameObject.Find("Network");
        }
        if (afkenable)
        {
            if (speedup * deathtimer >= afk & !inlas & !dead)
            {
                FindObjectOfType <Holocaust_2>().ImDeadLOL(prisoner_number);
                Destroy(gameObject);
                dead = true;
            }
            if (velocity.x == 0 & velocity.y == 0)
            {
                deathtimer += Time.deltaTime;
            }
            else
            {
                deathtimer = 0;
            }
        }
        if (singafkenable)
        {
            if (speedup * deathtimer2 >= singafk & !inlas & !dead)
            {
                FindObjectOfType <Holocaust_2>().ImDeadLOL(prisoner_number);
                Destroy(gameObject);
            }
            if (velocity.x == 0 & xory == 1)
            {
                deathtimer2 += Time.deltaTime;
            }
            else
            {
                if (velocity.y == 0 & xory == 0)
                {
                    deathtimer2 += Time.deltaTime;
                }
                else
                {
                    deathtimer2 = 0; xory = 1 - xory;
                }
            }
        }

        #region Think
        float[] input_array        = inman.GetInput(gameObject);
        int     input_array_length = input_array.Length;
        input_array[input_array_length - 4] = Tanh(obj.position.x, 4f);
        input_array[input_array_length - 3] = Tanh(obj.position.y, 9f / 4f);
        input_array[input_array_length - 2] = Tanh(velocity.x, max_v.x / 2f);
        input_array[input_array_length - 1] = Tanh(velocity.y, max_v.y / 2f);

        R2Tensor finproc = brain.ForwardPropagation(R2Tensor.ToMatrix(input_array, "col"));
        float[]  thought = R2Tensor.ToVector(finproc);

        if (networkvisual != null)
        {
            if (networkvisual.activeSelf & prisoner_number == best_n - 1)
            {
                inputactivation.text  = PrintNeuron(R2Tensor.ToMatrix(input_array, "col"));
                hiddenactivation.text = PrintNeuron(brain.ForwardPropagation(R2Tensor.ToMatrix(input_array, "col"), false));
                outputactivation.text = PrintNeuron(finproc);
            }
        }

        //R2Tensor.ToMatrix(thought, "row").PrintMatrix();
        int vert = 0;
        int hori = 0;
        switch (output)
        {
        case "Basisdirection":
            if (thought[0] > 0.5f)
            {
                hori = 1;
            }
            if (thought[0] < -0.5f)
            {
                hori = -1;
            }
            if (thought[1] > 0.5f)
            {
                vert = 1;
            }
            if (thought[1] < -0.5f)
            {
                vert = -1;
            }
            break;

        case "Direction":
            if (thought[0] == 1 | thought[4] == 1 | thought[5] == 1)
            {
                vert = 1;
            }
            if (thought[1] == 1 | thought[6] == 1 | thought[7] == 1)
            {
                vert = -1;
            }
            if (thought[3] == 1 | thought[5] == 1 | thought[7] == 1)
            {
                hori = 1;
            }
            if (thought[2] == 1 | thought[4] == 1 | thought[6] == 1)
            {
                hori = -1;
            }
            break;

        case "Keystroke":
            if (thought[0] == 1)
            {
                vert += 1;
            }
            if (thought[1] == 1)
            {
                vert -= 1;
            }
            if (thought[2] == 1)
            {
                hori -= 1;
            }
            if (thought[3] == 1)
            {
                hori += 1;
            }
            break;
        }
        #endregion
        #region Translation
        if (firstbump_h & Mathf.Abs(obj.position.x) > 8.25f)
        {
            velocity    = new Vector2(0, velocity.y);
            firstbump_h = false;
        }
        if (!firstbump_h & Mathf.Abs(obj.position.x) < 8.25f)
        {
            firstbump_h = true;
        }
        if (firstbump_v & Mathf.Abs(obj.position.y) > 4.37f)
        {
            velocity    = new Vector2(velocity.x, 0);
            firstbump_v = false;
        }
        if (!firstbump_v & Mathf.Abs(obj.position.y) < 4.37f)
        {
            firstbump_v = true;
        }

        if ((hori == -1 & obj.position.x > -8.25f) | (hori == 1 & obj.position.x < 8.25f))
        {
            if (hori * velocity.x < max_v.x)
            {
                if (hori != 0)
                {
                    velocity += new Vector2(hori * acceleration * Time.deltaTime * speedup, 0);
                }
            }
        }
        else
        {
            if (Mathf.Abs(velocity.x) < 0.001)
            {
                velocity = new Vector2(0, velocity.y);
            }
            else
            {
                velocity -= new Vector2(dampspeed * velocity.x * Time.deltaTime * speedup, 0);
            }
        }
        if ((vert == 1 & obj.position.y < 4.37f) | (vert == -1 & obj.position.y > -4.37f))
        {
            if (vert * velocity.y < max_v.y)
            {
                if (vert != 0)
                {
                    velocity += new Vector2(0, vert * acceleration * Time.deltaTime * speedup);
                }
            }
        }
        else
        {
            if (Mathf.Abs(velocity.y) < 0.001)
            {
                velocity = new Vector2(velocity.x, 0);
            }
            else
            {
                velocity -= new Vector2(0, dampspeed * velocity.y * Time.deltaTime * speedup);
            }
        }

        obj.position += new Vector3(velocity.x * speedup, velocity.y * speedup, 0);
        if (obj.position.x < -8.25f)
        {
            obj.position = new Vector3(-8.25f, obj.position.y, 0); velocity.x = 0;
        }
        if (obj.position.x > 8.25f)
        {
            obj.position = new Vector3(8.25f, obj.position.y, 0); velocity.x = 0;
        }
        if (obj.position.y > 4.37f)
        {
            obj.position = new Vector3(obj.position.x, 4.37f, 0); velocity.y = 0;
        }
        if (obj.position.y < -4.37f)
        {
            obj.position = new Vector3(obj.position.x, -4.37f, 0); velocity.y = 0;
        }
        #endregion
        #region Rotation
        float anglef = ((Mathf.Atan2(velocity.y, velocity.x) * 180 / Mathf.PI + 270) % 360);
        if (velocity.y != 0 | velocity.x != 0)
        {
            obj.eulerAngles = new Vector3(0, 0, anglef);
        }
        #endregion
    }