private void Die() { //Instantiate(playerExplosion, transform.position, transform.rotation); //Debug.Log("Player has died"); //FindObjectOfType<LevelController>().LoadGameOver(); // when player dies, the game over screen is loaded //Destroy(gameObject); agent.SetReward(-1f); agent.EndEpisode(); }
private void Die() { Debug.Log("Enemy has died"); //FindObjectOfType<LevelController>().LoadWinGame(); agent.SetReward(1.0f); agent.EndEpisode(); Destroy(gameObject); //Instantiate(explosion, transform.position, transform.rotation); }
private void CheckForWinner() { _availableSlots--; GetBoardState(); if (_availableSlots > 0 && _boardState == BoardState.Draw) { ChangeTurn(); return; } // Reward 1, and -1 for winner and loser respectively if (_boardState == BoardState.X) { player1.SetReward(1f); player2.SetReward(-1f); } else if (_boardState == BoardState.O) { player1.SetReward(-1f); player2.SetReward(1f); } // Reward the 2nd player in case it is a draw and penalize the 1st player else if (_boardState == BoardState.Draw) { if (slotsO > slotsX) { player1.SetReward(.25f); player2.SetReward(-.25f); } else { player1.SetReward(-.25f); player2.SetReward(.25f); } } player1.EndEpisode(); player2.EndEpisode(); if (!AIOnly) { MatchFinished(); return; } ResetBoard(); }
// Fixed update is called in sync with physics private void FixedUpdate() { // read inputs // Create a parent gameObject that is the Agent. // Move these into the Agent's Heuristic(). // Create a public variable for forward and sideways in this script // Reference it in the Agent script: userControl = GetComponentInChildren<ThirdPersonUserControl>(); // And set the vaule of it in OnActionReceived() { // userControl.verticalInput = vectorAction[0]; // userControl.horizontalInput = vectorAction[1]; } // // float h = horizontalInput; float v = verticalInput; bool crouch = Input.GetKey(KeyCode.C); // calculate move direction to pass to character if (m_Cam != null) { // calculate camera relative direction to move: m_CamForward = Vector3.Scale(m_Cam.forward, new Vector3(1, 0, 1)).normalized; m_Move = v * m_CamForward + h * m_Cam.right; } else { // we use world-relative directions in the case of no main camera m_Move = v * Vector3.forward + h * Vector3.right; } #if !MOBILE_INPUT // walk speed multiplier if (Input.GetKey(KeyCode.LeftShift)) { m_Move *= 0.5f; } #endif // pass all parameters to the character control script m_Character.Move(m_Move, crouch, m_Jump); m_Jump = false; if (transform.position.y < -5) { playerAgent.EndEpisode(); } }