static protected bool Fight(UnitAgent attacker, UnitAgent defender)
 {
     if (attacker.team == defender.team)
     {
         attacker.AddReward(-0.05f);
         return(false);
     }
     else if (attacker.attack >= defender.attack && attacker.attack > 0)
     {
         defender.SetReward(-.1f);
         defender.Dead();
         defender.Done();
         attacker.SetReward(1f);
         attacker.Done();
         Debug.Log("Attacker Beat Defender");
         return(true);
     }
     else
     {
         attacker.SetReward(-.1f);
         attacker.Dead();
         attacker.Done();
         Debug.Log("Defender Beat Attacker");
         return(false);
     }
 }
    public void SetEnvironment()
    {
        gameState.EmptyHexes();

        controller.InitMap();

        for (int i = 0; i < teams.Count; i++)
        {
            List <GameObject> team = teams[i];

            Hex  teamLoc;
            bool validLoc = false;

            int x;
            int y;

            int count = 0;

            do
            {
                count++;

                x = Random.Range(-maxRange, maxRange);
                y = Random.Range(-maxRange, maxRange);

                if (Mathf.Abs(x + y) == Mathf.Abs(x) + Mathf.Abs(y))
                {
                    y = y - x;
                }

                x += gameState.centerX;
                y += gameState.centerY;

                Coordinates2D coords = new Coordinates2D(x, y);

                teamLoc = gameState.GetHex(coords).GetComponent <Hex>();

                if (teamLoc.getType() != GameState.HexTypes.Mountain &&
                    teamLoc.getType() != GameState.HexTypes.Water &&
                    teamLoc.unitInHex == null)
                {
                    validLoc = true;
                }
            } while (!validLoc && count < 50);

            if (!validLoc)
            {
                Debug.Log("Failed to find valid tiles.");
                SetEnvironment();
                return;
            }

            foreach (GameObject member in team)
            {
                UnitAgent unit = member.GetComponent <UnitAgent>();
                unit.homeX = x;
                unit.homeY = y;
                unit.Dead();
            }

            castles[i].transform.position = teamLoc.transform.position;
        }

        timer = -1;
    }