internal override void MeasureBoard(Board board, FeatureMeasurementCollection result)
 {
     foreach (var g in board.OccupiedMapNodes.Where(kvp => edgeTerritories.Contains(kvp.Key.Territory)).GroupBy(kvp => kvp.Value.Power))
     {
         result.Add(new FeatureMeasurement(nameof(MapEdgesControlled), g.Key, null, null, g.Count()));
     }
 }
Exemple #2
0
        internal override void MeasureBoard(Board board, FeatureMeasurementCollection result)
        {
            double total = board.OccupiedMapNodes.Count();

            foreach (var g in board.OccupiedMapNodes.GroupBy(kvp => kvp.Value.Power))
            {
                result.Add(new FeatureMeasurement(nameof(UnitCountPercentage), g.Key, null, null, g.Count() / total));
            }
        }
        internal override void MeasureBoard(Board board, FeatureMeasurementCollection result)
        {
            double total = Maps.Full.Vertices.Count(mn => mn.Territory.IsSupplyCenter);

            foreach (var g in board.OwnedSupplyCenters)
            {
                result.Add(new FeatureMeasurement(nameof(OwnedSupplyCentersPercentage), g.Key, null, null, g.Value.Count() / total));
            }
        }
        internal override void MeasureBoard(Board board, FeatureMeasurementCollection result)
        {
            IEnumerable <UnitMove> unitMoves = board.GetUnitMoves();

            _territoryStrengths.Clear();
            foreach (UnitMove move in unitMoves)
            {
                if (move.IsDisband)
                {
                    continue;
                }
                if (!_territoryStrengths.ContainsKey(move.Edge.Target.Territory))
                {
                    _territoryStrengths.Add(move.Edge.Target.Territory, new PowersDictionary <int>()
                    {
                        { move.Unit.Power, 1 }
                    });
                }
                else
                {
                    if (!_territoryStrengths[move.Edge.Target.Territory].ContainsKey(move.Unit.Power))
                    {
                        _territoryStrengths[move.Edge.Target.Territory].Add(move.Unit.Power, 1);
                    }
                    else
                    {
                        _territoryStrengths[move.Edge.Target.Territory][move.Unit.Power]++;
                    }
                }
            }

            foreach (var territoryStrength in _territoryStrengths)
            {
                foreach (KeyValuePair <Powers, int> t in territoryStrength.Value)
                {
                    //result.Add(new FeatureMeasurement("RawTerritoryStrength", t.Key, null, territoryStrength.Key, t.Value));
                    int adjustedStrength = t.Value - territoryStrength.Value.Where(kvp => kvp.Key != t.Key)?.Sum(kvp => kvp.Value) ?? 0;
                    //todo adjust for units cutting support
                    result.Add(new FeatureMeasurement(nameof(RelativeTerritoryStrengths), t.Key, null, territoryStrength.Key, adjustedStrength));
                }
            }
        }
        internal override void MeasureBoard(Board board, FeatureMeasurementCollection result)
        {
            IEnumerable <UnitMove> unitMoves = board.GetUnitMoves();

            _totalStrengths.Clear();
            _totalStrengths.Init(0d);
            foreach (UnitMove move in unitMoves)
            {
                if (move.IsDisband)
                {
                    continue;
                }
                _totalStrengths[move.Unit.Power]++;
            }
            double totalBoardThreats = _totalStrengths.Values.Sum();

            foreach (var kvp in _totalStrengths)
            {
                result.Add(new FeatureMeasurement(nameof(TerritoryThreatPercentage), kvp.Key, null, null, kvp.Value / totalBoardThreats));
            }
        }