// Start is called before the first frame update
    void Start()
    {
        existentialPenalty = 1f / MaxStep;

        offenseRb = offense.GetComponent <Rigidbody>();
        goalieRb  = goalie.GetComponent <Rigidbody>();
        ballRb    = ball.GetComponent <Rigidbody>();

        oOffenseRb = opponentOffense.GetComponent <Rigidbody>();
        oGoalieRb  = opponentGoalie.GetComponent <Rigidbody>();

        bs = ball.GetComponent <BallScorer>();

        invert = player1 ? 1f : -1f;
    }
    void calcScores()
    {
        float goals    = 0;
        float touches  = 0;
        float scoresum = 0;

        for (int i = 0; i < populationSize / 2; i++)
        {
            BallScorer bs = population[i].transform.GetChild(0).GetComponent <BallScorer>();
            goals    += bs.t1Goals + bs.t2Goals;
            touches  += bs.t1Touches + bs.t2Touches;
            scoresum += 2f * bs.t1Goals + 0.5f * bs.t1Touches - 0.01f * (bs.mint1p1 + bs.mint1p2 + bs.mint1p3) + 2f * bs.t2Goals + 0.5f * bs.t2Touches - 0.01f * (bs.mint2p1 + bs.mint2p2 + bs.mint2p3);

            if (2 * bs.t1Goals + 0.5 * bs.t1Touches - 0.01 * (bs.mint1p1 + bs.mint1p2 + bs.mint1p3) >= 2 * bs.t2Goals + 0.5 * bs.t2Touches - 0.01 * (bs.mint2p1 + bs.mint2p2 + bs.mint2p3))
            {
                winners[i] = 0;
            }
            else
            {
                winners[i] = 1;
            }

            if (i == 0)
            {
                //Debug.Log((bs.mint1p1 + bs.mint1p2 + bs.mint1p3).ToString() + " : " + (bs.mint2p1 + bs.mint2p2 + bs.mint2p3).ToString());
                //Debug.Log((0.01 * (bs.mint1p1 + bs.mint1p2 + bs.mint1p3)).ToString());
                Debug.Log("P1: " + (2 * bs.t1Goals + 0.5 * bs.t1Touches - 0.01 * (bs.mint1p1 + bs.mint1p2 + bs.mint1p3)).ToString());
            }
        }

        goals    /= populationSize;
        touches  /= populationSize;
        scoresum /= populationSize;

        string str = generationNum.ToString() + " : " + goals.ToString() + " : " + touches.ToString() + " : " + scoresum.ToString();

        Debug.Log(generationNum.ToString() + " : " + goals.ToString() + " : " + touches.ToString() + " : " + scoresum.ToString());
        System.IO.StreamWriter file = new System.IO.StreamWriter("Assets/Data/" + "teamTrain.txt", append: true);
        file.WriteLine(str);
        file.Close();


        //for (int i = 0; i < populationSize / 2; i++)
        //{
        //    BallScorer bs = population[i].transform.GetChild(0).GetComponent<BallScorer>();

        //    if (bs.mint1p1 + bs.mint1p2 + bs.mint1p3 <= bs.mint2p1 + bs.mint2p2 + bs.mint2p3)
        //    {
        //        winners[i] = 0;
        //    }
        //    else
        //    {
        //        winners[i] = 1;
        //    }

        //    if(i==0)
        //    {
        //        Debug.Log((bs.mint1p1 + bs.mint1p2 + bs.mint1p3).ToString() + " : " + (bs.mint2p1 + bs.mint2p2 + bs.mint2p3).ToString());
        //    }
        //}
    }