public override void InitPlayer()
    {
        if (!isInited)
        {
            id++;
            teamGoally = transform.parent.gameObject.GetComponentInChildren<GoallyPlayer>();
            if (teamGoally.transform.position.x < 0)
            {
                isRedTeam = false;
            }
            else
            {
                isRedTeam = true;
            }

            AttackPlayer[] list = oponentTeam.GetComponentsInChildren<AttackPlayer>();
            foreach (AttackPlayer a in list)
            {
                if (a.NameType == GameConsts.ATTACK_PLAYER)
                {
                    oponentAttacker = a;
                    break;
                }
            }
            rgBody = GetComponent<Rigidbody2D>();
            ballScript = FindObjectOfType<BallScript>();
            brain = new NeuralNetwork(NeuralNetworkConst.DEFENSE_INPUT_COUNT, NeuralNetworkConst.DEFENSE_OUTPUT_COUNT,
                NeuralNetworkConst.DEFENSE_HID_LAYER_COUNT, NeuralNetworkConst.DEFENSE_NEURONS_PER_HID_LAY);
            isInited = true;
        }
    }
    public override void InitPlayer()
    {
        if (!isInited)
        {
            id++;
            teamGoally = transform.parent.gameObject.GetComponentInChildren <GoallyPlayer>();
            if (teamGoally.transform.position.x < 0)
            {
                isRedTeam = false;
            }
            else
            {
                isRedTeam = true;
            }

            AttackPlayer[] list = oponentTeam.GetComponentsInChildren <AttackPlayer>();
            foreach (AttackPlayer a in list)
            {
                if (a.NameType == GameConsts.ATTACK_PLAYER)
                {
                    oponentAttacker = a;
                    break;
                }
            }
            rgBody     = GetComponent <Rigidbody2D>();
            ballScript = FindObjectOfType <BallScript>();
            brain      = new NeuralNetwork(NeuralNetworkConst.DEFENSE_INPUT_COUNT, NeuralNetworkConst.DEFENSE_OUTPUT_COUNT,
                                           NeuralNetworkConst.DEFENSE_HID_LAYER_COUNT, NeuralNetworkConst.DEFENSE_NEURONS_PER_HID_LAY);
            isInited = true;
        }
    }
예제 #3
0
    private void FillTeamWithDummyPlayers()
    {
        /* DEFENSE PLAYERS */
        while (defensePlayers.Count < GameConsts.DEFENSE_PLAYER_COUNT)
        {
            var gO = Instantiate(dummyDefensePlayer) as GameObject;
            gO.transform.parent   = transform;
            gO.transform.position = new Vector2(defenseExample.transform.position.x, defenseExample.transform.position.y);
            DefensePlayer defPlayer = gO.GetComponent <DefensePlayer>();
            defPlayer.oponentTeam    = defenseExample.oponentTeam;
            defPlayer.oponentGoal    = defenseExample.oponentGoal;
            defPlayer.homeGoal       = defenseExample.homeGoal;
            defPlayer.attackerPlayer = attackExample;
            defPlayer.InitPlayer();
            defPlayer.TeamGoally       = goallyExample;
            defPlayer.OponentsAttacker = defenseExample.OponentsAttacker;
            defensePlayers.Add(defPlayer);
        }

        /* ATTACK PLAYERS */
        while (attackPlayers.Count < GameConsts.ATTACK_PLAYER_COUNT)
        {
            var gO = Instantiate(dummyAttacker) as GameObject;
            gO.transform.parent   = transform;
            gO.transform.position = new Vector2(attackExample.transform.position.x, attackExample.transform.position.x);
            AttackPlayer attPlayer = gO.GetComponent <AttackPlayer>();
            attPlayer.oponentGoal = attackExample.oponentGoal;
            attPlayer.oponentTeam = attackExample.oponentTeam;
            attPlayer.InitPlayer();
            attackPlayers.Add(attPlayer);
        }

        /* GOALY PLAYERS */
        while (goalyPlayers.Count < GameConsts.GOALLY_PLAYER_COUNT)
        {
            var gO = Instantiate(dummyGoaly) as GameObject;
            gO.transform.parent   = transform;
            gO.transform.position = new Vector2(goallyExample.transform.position.x, goallyExample.transform.position.y);
            GoallyPlayer goaly = gO.GetComponent <GoallyPlayer>();
            goaly.oponentGoal  = goallyExample.oponentGoal;
            goaly.oponentTeam  = goallyExample.oponentTeam;
            goaly.goalToSave   = goallyExample.goalToSave;
            goaly.TeamAttacker = goallyExample.TeamAttacker;
            goaly.InitPlayer();
            goalyPlayers.Add(goaly);
        }
    }
예제 #4
0
    void Start()
    {
        if (gameObject.name.StartsWith("Red"))
        {
            teamName = "Red";
        }
        else
        {
            teamName = "Blue";
        }
        var att = GetComponentsInChildren <AttackPlayer>();

        foreach (AttackPlayer a in att)
        {
            if (a.NameType == GameConsts.ATTACK_PLAYER)
            {
                attackExample = a;
                break;
            }
        }
        defenseExample = GetComponentInChildren <DefensePlayer>();
        goallyExample  = GetComponentInChildren <GoallyPlayer>();

        try
        {
            LoadStats();
        }
        catch (Exception e)
        {
            InitMainTeam();
            FillTeamWithDummyPlayers();
            InitGeneticAlgorithms();
        }
        InitStartingPositionForReset();
        WarmUp();
    }
    void Start()
    {
        if (gameObject.name.StartsWith("Red"))
        {
            teamName = "Red";
        }
        else
        {
            teamName = "Blue";
        }
        var att = GetComponentsInChildren<AttackPlayer>();
        foreach (AttackPlayer a in att)
        {
            if (a.NameType == GameConsts.ATTACK_PLAYER)
            {
                attackExample = a;
                break;
            }
        }
        defenseExample = GetComponentInChildren<DefensePlayer>();
        goallyExample = GetComponentInChildren<GoallyPlayer>();

        try
        {
            LoadStats();
        }
        catch (Exception e)
        {
            InitMainTeam();
            FillTeamWithDummyPlayers();
            InitGeneticAlgorithms();

        }
        InitStartingPositionForReset();
        WarmUp();
    }