コード例 #1
0
        private IEnumerable <Botlet> _GetAdjacentEnemies(Botlet botlet)
        {
            IEnumerable <char>   enemyBotletIds    = _GetEnemyBotletIds(botlet.botletId);
            IEnumerable <Botlet> EnemyBotlets      = _GetBotlets().Where(b => enemyBotletIds.Contains(b.botletId));
            IEnumerable <int>    adjacentPositions = new SpatialGameState(GameState).AdjacentPositions(botlet.gridPosition);

            return(EnemyBotlets.Where(b => adjacentPositions.Contains(b.gridPosition)));
        }
コード例 #2
0
        private BotPlayer _GetEnergyWinningPlayer(int location)
        {
            List <int> adjacentPositions    = new SpatialGameState(GameState).AdjacentPositions(location).ToList();
            BotPlayer  winningPlayer        = null;
            int        botsAdjacentToEnergy = 0;

            foreach (BotPlayer player in Players)
            {
                int playersBotsAdjacentToEnergy = adjacentPositions.Count(a => GameState.Grid[a] == player.BotletId);
                if (playersBotsAdjacentToEnergy > botsAdjacentToEnergy)
                {
                    winningPlayer = player;
                }
                else if (playersBotsAdjacentToEnergy == botsAdjacentToEnergy)
                {
                    winningPlayer = null;
                }
                botsAdjacentToEnergy = Math.Max(botsAdjacentToEnergy, playersBotsAdjacentToEnergy);
            }

            return(winningPlayer);
        }