private IEnumerator Eval(PlayerAgent agent)
    {
        for (int i = 0; i < 5; i++)
        {
            yield return(new WaitForFixedUpdate());
        }

        PlayerAgent other = agent.Controller.Arena.Players.First(p => p != agent.Controller).PlayerAgent;

        if (other.Controller.StateMachine.CurrentState is PlayerDeadState)
        {
            agent.SetReward(DrawReward);
            other.SetReward(DrawReward);
            agent.Done();
            other.Done();
        }
        else
        {
            agent.SetReward(-1.0f);
            other.SetReward(1.0f);
            agent.Done();
            other.Done();
        }
        yield return(new WaitForFixedUpdate());

        ResetEnv(agent.Controller.Arena);
    }
Пример #2
0
 public void RedScores()
 {
     UIManager.instance.RedScorePlus();
     redPlayerScript.SetReward(1f);
     greenPlayerScript.Done();
     redPlayerScript.Done();
     Reset();
 }
    private IEnumerator Eval(Arena arena)
    {
        for (int i = 0; i < 5; i++)
        {
            yield return(new WaitForFixedUpdate());
        }

        PlayerAgent first  = arena.Players[0].PlayerAgent;
        PlayerAgent second = arena.Players[1].PlayerAgent;

        if (first.Controller.StateMachine.CurrentState is PlayerDeadState && second.Controller.StateMachine.CurrentState is PlayerDeadState)
        {
            first.SetReward(DrawReward);
            second.SetReward(DrawReward);
            first.Done();
            second.Done();
        }
        else if (first.Controller.StateMachine.CurrentState is PlayerDeadState)
        {
            // Suicide
            if (first.Controller.Team == first.Controller.LastKilledBy.Team)
            {
                first.SetReward(-1.0f);
                second.SetReward(1.0f);
            }
            // Kill
            else
            {
                first.SetReward(-1.0f);
                second.SetReward(1.0f);
            }
            first.Done();
            second.Done();
        }
        else
        {
            // Suicide
            if (second.Controller.Team == second.Controller.LastKilledBy.Team)
            {
                first.SetReward(1.0f);
                second.SetReward(-1.0f);
            }
            // Kill
            else
            {
                first.SetReward(1.0f);
                second.SetReward(-1.0f);
            }
            first.Done();
            second.Done();
        }
        yield return(new WaitForFixedUpdate());

        ResetEnv(arena);
    }
Пример #4
0
 private void OnTriggerEnter(Collider other)
 {
     if (other.CompareTag("Player"))
     {
         playerAgent.SetReward(+1.0f);
         rewardDone = true;
         playerAgent.Done();
     }
 }
Пример #5
0
    private void OnCollisionEnter(Collision collision)
    {
        if (collision.gameObject.CompareTag("goal"))
        {
            if (collision.gameObject.name == "Goal1")
            {
                if (lastAgentHit == 0)
                {
                    agentA.AddReward(-0.01f);
                    agentB.SetReward(0);
                    agentB.score += 1;
                    Debug.Log("Score Incremented");
                }
                else
                {
                    agentA.SetReward(0);
                    agentB.AddReward(-0.01f);
                    agentA.score += 1;
                    Debug.Log("Score Incremented");
                }
            }
            else if (collision.gameObject.name == "Goal2")
            {
                if (lastAgentHit == 0)
                {
                    agentA.AddReward(-0.01f);
                    agentB.SetReward(0);
                    agentB.score += 1;
                    Debug.Log("Score Incremented");
                }
                else
                {
                    agentA.SetReward(0);
                    agentB.AddReward(-0.01f);
                    agentA.score += 1;
                    Debug.Log("Score Incremented");
                }
            }


            agentA.Done();
            agentB.Done();
            region.MatchReset();
            Debug.Log(agentA.score);
        }

        if (collision.gameObject.CompareTag("Player"))
        {
            lastAgentHit = collision.gameObject.name == "Player1" ? 0 : 1;
        }
    }
    private IEnumerator Draw(Arena arena)
    {
        PlayerAgent first  = arena.Players[0].PlayerAgent;
        PlayerAgent second = arena.Players[1].PlayerAgent;

        first.SetReward(DrawReward);
        second.SetReward(DrawReward);
        first.Done();
        second.Done();

        yield return(new WaitForFixedUpdate());

        ResetEnv(arena);
    }
    // Update is called once per frame
    void Update()
    {
        uiComponent.UpdateUI(p.stats.currHealth, p.stats.lives, p.stats.score, getGameTime());

        updateObservableEnemies();
        updateObservableBullets();
        updateObservableScoreObjects();

        if (Input.GetKeyDown(KeyCode.Space))
        {
            Stop();
            pa.Done();
        }
    }
 public void GameOver()
 {
     // Added: Game Over text only for human players
     if (playerAgent.brain is PlayerBrain)
     {
         gameOver          = true;
         gameOverText.text = "Game Over!";
     }
     else
     {
         // Added: notify player agent with big penalty and done()
         // Size of reward chosen in relation to score to what would be a "good game".
         playerAgent.SetReward(-100);
         playerAgent.Done();
         //Debug.Log("Average AI score after " + ++numGames + " games:" + ((overallScore += score) / numGames));
         // Immediate restart - no actual destroy.
         Restart();
     }
 }
Пример #9
0
 void ResetGame()
 {
     scores[0] = 0;
     scores[1] = 0;
     scores[2] = 0;
     scores[3] = 0;
     foreach (GameObject player in players)
     {
         PlayerControl agent = player.GetComponent <PlayerControl>();
         agent.PlayerReset();
         if (agent.isAgent)
         {
             PlayerAgent pa = player.GetComponent <PlayerAgent>();
             pa.Done();
         }
     }
     Debug.Log("Restarted Game");
     gameTime = 0f;
 }
Пример #10
0
    // Update is called once per frame
    void Update()
    {
        if (stats.lives >= 1 && stats.currHealth <= 0)
        {
            stats.lives     -= 1;
            stats.currHealth = stats.maxHealth;

            Gamemaster.Instance.Stop();
            pa.Done();

            if (stats.lives == 0)
            {
#if !UNITY_EDITOR
                Destroy(gameObject);
                SceneManager.LoadScene(2);
#else
                stats.lives = 3;
#endif
            }
        }
    }
Пример #11
0
    // Update is called once per frame
    void FixedUpdate()
    {
        if (reloading && Time.time > lastReloadTime + reloadTime[(int)currentWeapon])
        {
            ammo      = maxAmmo[(int)currentWeapon];
            reloading = false;
        }

        if (health <= 0)
        {
            battleArea.addAliveTimeStat(gameObject.name, aliveTime);
            if (battleArea.kdStatText)
            {
                if (gameObject.name.StartsWith("MLAgent"))
                {
                    battleArea.kdStatText.GetComponent <StatsCounter>().addMLSurviveTime(aliveTime);
                }
                else if (gameObject.name.StartsWith("MLDisAgent"))
                {
                    battleArea.kdStatText.GetComponent <StatsCounter>().addMLDisSurviveTime(aliveTime);
                }
                else if (gameObject.name.StartsWith("RBSAgent"))
                {
                    battleArea.kdStatText.GetComponent <StatsCounter>().addRBSSurviveTime(aliveTime);
                }
                else if (gameObject.name.StartsWith("Human"))
                {
                    battleArea.kdStatText.GetComponent <StatsCounter>().addHumanSurviveTime(aliveTime);
                }
            }

            if (agent.brain)
            {
                agent.AddReward(-1f);
                agent.Done();
                //gameObject.SetActive(false);
            }
            else
            {
                if (destroyOnDied)
                {
                    battleArea.players.Remove(gameObject);
                    Destroy(statusBar);
                    Destroy(gameObject);
                }
            }
        }
        else
        {
            aliveTime += Time.deltaTime;
        }

        if (statusBar)
        {
            //uiText.GetComponent<Text>().text = "Health: " + health + "\nAmmo: " + ((reloading) ? "RE.." : ammo.ToString()) + "\n" + agent.GetReward().ToString("0.000");
            statusBar.GetComponent <StatusBar>().updateBar(health, ammo, maxAmmo[(int)currentWeapon], reloading);
            // Offset position above object bbox (in world space)
            float offsetPosX = transform.position.x + 0.75f;

            // Final position of marker above GO in world space
            Vector3 offsetPos = new Vector3(offsetPosX, transform.position.y, transform.position.z);

            // Calculate *screen* position (note, not a canvas/recttransform position)
            Vector2 canvasPos;
            Vector2 screenPoint = Camera.main.WorldToScreenPoint(offsetPos);

            // Convert screen position to Canvas / RectTransform space <- leave camera null if Screen Space Overlay
            RectTransformUtility.ScreenPointToLocalPointInRectangle(canvasRect, screenPoint, null, out canvasPos);

            // Set
            statusBar.transform.localPosition = canvasPos;
        }
    }