Esempio n. 1
0
    public void HandleBots()
    {
        //Remove bots if there are more than there should be.
        if (NumBots > _cfg.GetNumTotalBots())
        {
            Console.WriteLine($"Bot count {NumBots} > {_cfg.GetNumTotalBots()}. Removing bots.");
            RemoveBotsIfAny();
        }

        //Remove bots if many players
        int humanCount = _observation.GetPlayerCount() - NumBots;

        if (humanCount >= _cfg.NumberPlayersWhenBotsAreRemoved && NumBots > 0)
        {
            Console.WriteLine($"Human count {humanCount} >= {_cfg.NumberPlayersWhenBotsAreRemoved}. Removing bots.");
            RemoveBotsIfAny();
        }

        //Add bots if few players
        if (humanCount < _cfg.NumberPlayersWhenBotsAreRemoved &&
            NumBots < _cfg.GetNumTotalBots() &&
            _observation.GetTeamsAreBalanced())
        {
            Console.WriteLine($"Human count {humanCount} < {_cfg.NumberPlayersWhenBotsAreRemoved} and BotCount {NumBots} < 4. Adding bots.");
            foreach (var bot in _cfg.Bots)
            {
                _ai.AddAI(bot.Item1, bot.Item2, Team.Blue, 1);
                _ai.AddAI(bot.Item1, bot.Item2, Team.Red, 1);
            }
            NumBots += _cfg.GetNumTotalBots();
        }
        _resetter.Reset();
    }
Esempio n. 2
0
    public void SwapToBalance()
    {
        int blueTeamSizeAdvantage = _observation.GetBlueTeamSizeAdvantage();

        if (!_observation.GetTeamsAreBalanced())
        {
            List <int> slots;

            Team emptyTeam;
            if (blueTeamSizeAdvantage > 0)
            {
                slots     = _observation.GetBlueSlots();
                emptyTeam = Team.Red;
            }
            else
            {
                slots     = _observation.GetRedSlots();
                emptyTeam = Team.Blue;
            }

            Random rnd        = new Random();
            int    randomSlot = slots[rnd.Next(slots.Count)];
            SwapWithEmpty(randomSlot, emptyTeam);
        }
    }
Esempio n. 3
0
    public void HandleAutoBalance()
    {
//        _prevBlueTeamSizeAdvantage = _blueTeamSizeAdvantage;
        _blueTeamSizeAdvantage = _observation.GetBlueTeamSizeAdvantage();
        if (_observation.GetTeamsAreBalanced())
        {
            EndAutoBalance();
        }
        else if (_observation.GetImbalanceAmount() == 2)
        {
            Console.WriteLine($"blue team size advantage {_cg.BlueCount} vs {_cg.RedCount}");
            BeginAutoBalance();
        }
        else if (_observation.GetImbalanceAmount() >= 3 || _cg.BlueCount == 0 || _cg.RedCount == 0)
        {
            Console.WriteLine($"blue team size advantage {_cg.BlueCount} vs {_cg.RedCount}");
            BeginAutoBalance();
        }
    }