Beispiel #1
0
    private void _ThrowingManagment()
    {
        if (_thrower.IsReady())
        {
            List <TrajectoryData> collectedData = _thrower.CollectTrajecoryData();

            if (collectedData.Count > 0)
            {
                float throwDistance;
                var   directionToLern = dataProcessor.findOptimalThrowDirection(collectedData, target, LastThrowDirection, out throwDistance);

                _deviationFactor = (float)Sigmoid.Output((double)throwDistance * 0.5 - 2) * 0.4f;

                var ppDirToLern = (directionToLern + Vector3.one) * 0.5f;

                if (!_first)
                {
                    neuralService.NetAdaptation(_lastThrowPosition, target.GetTargetCords(), ppDirToLern);
                }
            }
            var throwPosition       = _thrower.GetThrowPosition();
            var calcualtedDirection = neuralService.CalculateThrowDirection(throwPosition, target.GetTargetCords());
            var ppDir = calcualtedDirection * 2 - Vector3.one;

            _thrower.DataGatteringThrow(ppDir, _deviationFactor);

            LastThrowDirection = ppDir;
            _lastThrowPosition = throwPosition;
            _first             = false;
        }
    }
Beispiel #2
0
    public Vector3 findOptimalThrowDirection(List <TrajectoryData> trajectoryList, BallTarget target, Vector3 throwDirection, out float throwDistance)
    {
        Vector3 targetPosition   = target.GetTargetCords();
        Vector3 optimalDirection = Vector3.zero;

        throwDistance = 0;
        bool first = true;

        foreach (var trajectory in trajectoryList)
        {
            float performanceIndex = 0;
            float minialDistance   = 1000;

            trajectory.trajectoryPoints.ForEach(p =>
            {
                var distToTarget  = Vector3.Distance(p, targetPosition);
                minialDistance    = Mathf.Min(distToTarget, minialDistance);
                performanceIndex += distToTarget * Time.fixedDeltaTime;
            });

            if (trajectory.direction == throwDirection)
            {
                throwPerformanceIndex = performanceIndex;
                throwDistance         = minialDistance;
                continue;
            }

            if (first)
            {
                first = false;
                theHighestPerformanceIndex = performanceIndex;
                theLowestPerformanceIndex  = performanceIndex;
                continue;
            }

            if (performanceIndex < theHighestPerformanceIndex)
            {
                theHighestPerformanceIndex = performanceIndex;
                theNearestBasketDistance   = minialDistance;
                optimalDirection           = trajectory.direction;
            }

            if (performanceIndex > theLowestPerformanceIndex)
            {
                theLowestPerformanceIndex = performanceIndex;
            }
        }

        Debug.Log($"{theHighestPerformanceIndex}, {theNearestBasketDistance}");
        if (theHighestPerformanceIndex < theHighestPerformaceAchived)
        {
            theHighestPerformaceAchived = theHighestPerformanceIndex;
            ultimateDirection           = optimalDirection;
        }

        return(ultimateDirection);
    }