示例#1
0
 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()));
     }
 }
示例#2
0
        public void Populate(Board board, FeatureMeasurementCollection featureMeasurementCollection)
        {
            foreach (var edge in Maps.Full.Edges)
            {
                Unit         unit1            = board.OccupiedMapNodes.FirstOrDefault(kvp => kvp.Key.Territory.ShortName == edge.Source.ShortName).Value;
                Powers       owningPower1     = board.OwnedSupplyCenters.Where(kvp => kvp.Value.Any(t => t.ShortName == edge.Source.Territory.ShortName)).FirstOrDefault().Key;
                DrawnMapNode from             = GetDrawnMapNode(edge.Source, unit1, owningPower1);
                Unit         unit2            = board.OccupiedMapNodes.FirstOrDefault(kvp => kvp.Key.Territory.ShortName == edge.Target.ShortName).Value;
                Powers       owningPower2     = board.OwnedSupplyCenters.Where(kvp => kvp.Value.Any(t => t.ShortName == edge.Target.Territory.ShortName)).FirstOrDefault().Key;
                DrawnMapNode to               = GetDrawnMapNode(edge.Target, unit2, owningPower2);
                DrawnMapEdge drawnEdge        = new DrawnMapEdge(from, to);
                DrawnMapEdge drawnEdgeInverse = new DrawnMapEdge(to, from);

                if (!ContainsVertex(from))
                {
                    AddVertex(from);
                    AddFeatureValueText(from, featureMeasurementCollection);
                }

                if (!ContainsVertex(to))
                {
                    AddVertex(to);
                    AddFeatureValueText(to, featureMeasurementCollection);
                }

                if (!ContainsEdge(drawnEdge) && !ContainsEdge(drawnEdgeInverse))
                {
                    AddEdge(drawnEdge);
                }
            }
        }
示例#3
0
 internal void GetMeasurements(FeatureTool tool, FeatureMeasurementCollection result)
 {
     if (result == null)
     {
         throw new ArgumentNullException("result");
     }
     tool.MeasureGame(this, result);
 }
示例#4
0
        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));
            }
        }
示例#5
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));
            }
        }
示例#6
0
        public void TerritoryThreatPercentageStart()
        {
            Board board = Board.GetInitialBoard();

            FeatureToolCollection toolCollection = new FeatureToolCollection();

            toolCollection.Add(new TerritoryThreatPercentage());
            FeatureMeasurementCollection measurements = toolCollection.GetMeasurements(board);

            Assert.AreEqual(7, measurements.Count);
        }
示例#7
0
 private void AddFeatureValueText(DrawnMapNode drawnMapNode, FeatureMeasurementCollection featureMeasurementCollection)
 {
     if (null == featureMeasurementCollection)
     {
         return;
     }
     foreach (var feature in featureMeasurementCollection.ByTerritory(drawnMapNode.MapNode.Territory))
     {
         drawnMapNode.FeatureValueText += $"{feature.Power}: {feature.Value}\n";
     }
 }
示例#8
0
        public void MapNodeStrengthsAtStart()
        {
            Board board = Board.GetInitialBoard();

            FeatureToolCollection toolCollection = new FeatureToolCollection();

            toolCollection.Add(new RelativeTerritoryStrengths());
            FeatureMeasurementCollection measurements = toolCollection.GetMeasurements(board);

            //todo finish me
        }
示例#9
0
        public void MapEdgesAtStart()
        {
            Board board = Board.GetInitialBoard();

            FeatureToolCollection toolCollection = new FeatureToolCollection();

            toolCollection.Add(new MapEdgesControlled());
            FeatureMeasurementCollection measurements = toolCollection.GetMeasurements(board);

            Assert.AreEqual(1, measurements.Count);
            Assert.AreEqual(3, measurements.Where(m => m.Power == Powers.Russia).Single().Value);
        }
示例#10
0
        public void UnitCountStart()
        {
            Board board = Board.GetInitialBoard();

            FeatureToolCollection toolCollection = new FeatureToolCollection();

            toolCollection.Add(new UnitCountPercentage());
            FeatureMeasurementCollection measurements = toolCollection.GetMeasurements(board);

            Assert.AreEqual(7, measurements.Count);
            // terrible
            Assert.AreEqual(4d / 22d, measurements.Where(m => m.Power == Powers.Russia).Single().Value);
            Assert.AreEqual(Math.Round(18d / 22d, 5), Math.Round(measurements.Where(m => m.Power != Powers.Russia).Sum(m => m.Value), 5));
        }
示例#11
0
        public void OwnedSupplyCentersStart()
        {
            Board board = Board.GetInitialBoard();

            FeatureToolCollection toolCollection = new FeatureToolCollection();

            toolCollection.Add(new OwnedSupplyCentersPercentage());
            FeatureMeasurementCollection measurements = toolCollection.GetMeasurements(board);

            Assert.AreEqual(8, measurements.Count);
            // terrible
            Assert.AreEqual(1, Math.Round(measurements.Sum(v => v.Value)));
            Assert.AreEqual(18d / 34d, measurements.Where(m => m.Power != Powers.Russia && m.Power != Powers.None).Sum(m => m.Value));
            Assert.AreEqual(13d / 34d, measurements.Where(m => m.Power == Powers.None).Single().Value);
        }
        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));
                }
            }
        }
示例#13
0
        public void Draw(Board board, FeatureMeasurementCollection featureMeasurementCollection = null)
        {
            try
            {
                _executing = true;
                DrawnMap drawnMap = new DrawnMap();
                drawnMap.Populate(board, featureMeasurementCollection);

                var logicCore = new DiplomacyGXLogicCore();
                logicCore.Graph = drawnMap;
                logicCore.ExternalLayoutAlgorithm = new AbsoluteLayoutAlgorithm(drawnMap);

                ////Setup optional params
                logicCore.DefaultOverlapRemovalAlgorithmParams =
                    logicCore.AlgorithmFactory.CreateOverlapRemovalParameters(OverlapRemovalAlgorithmTypeEnum.FSA);
                ((OverlapRemovalParameters)logicCore.DefaultOverlapRemovalAlgorithmParams).HorizontalGap = 50;
                ((OverlapRemovalParameters)logicCore.DefaultOverlapRemovalAlgorithmParams).VerticalGap   = 50;

                //This property sets edge routing algorithm that is used to build route paths according to algorithm logic.
                //For ex., SimpleER algorithm will try to set edge paths around vertices so no edge will intersect any vertex.
                logicCore.DefaultEdgeRoutingAlgorithm = EdgeRoutingAlgorithmTypeEnum.SimpleER;
                //This property sets async algorithms computation so methods like: Area.RelayoutGraph() and Area.GenerateGraph()
                //will run async with the UI thread. Completion of the specified methods can be catched by corresponding events:
                //Area.RelayoutFinished and Area.GenerateGraphFinished.
                logicCore.AsyncAlgorithmCompute = false;

                logicCore.EdgeCurvingEnabled  = true;
                logicCore.EnableParallelEdges = false;

                //Finally assign logic core to GraphArea object
                GraphArea.LogicCore = logicCore;
                GraphArea.SetVerticesDrag(true);
                GraphArea.GenerateGraph();

                ZoomControl.ZoomToFill();
            }
            finally
            {
                _executing = false;
            }
        }
        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));
            }
        }
示例#15
0
 internal virtual void MeasureBoard(Board board, FeatureMeasurementCollection result)
 {
 }
示例#16
0
 internal virtual void MeasureGame(Game game, FeatureMeasurementCollection result)
 {
 }
示例#17
0
        public MainWindow()
        {
            InitializeComponent();

            Board board = Board.GetInitialBoard();
            //1901 Spring
            BoardMove moves = new BoardMove();

            moves.Add(board.GetMove("bud", "ser"));
            moves.Add(board.GetMove("edi", "nth"));
            moves.Add(board.GetMove("lvp", "wal"));
            moves.Add(board.GetMove("mar", "spa"));
            moves.Add(board.GetMove("par", "bur"));
            moves.Add(board.GetMove("ber", "kie"));
            moves.Add(board.GetMove("kie", "den"));
            moves.Add(board.GetMove("mun", "ruh"));
            moves.Add(board.GetMove("nap", "ion"));
            moves.Add(board.GetMove("rom", "apu"));
            //A Ven H ? SUCCEEDS
            moves.Add(board.GetMove("mos", "stp"));
            moves.Add(board.GetMove("sev", "rum"));
            moves.Add(board.GetMove("stp_sc", "fin"));
            moves.Add(board.GetMove("war", "lvn"));
            moves.Add(board.GetMove("ank", "con"));
            moves.Add(board.GetMove("con", "bul"));
            //A Smy H ? SUCCEEDS
            moves.FillHolds(board);
            board.ApplyMoves(moves, true);
            board.EndTurn();

            //1901 Fall
            moves = new BoardMove();
            moves.Add(board.GetMove("bul", "gre"));
            moves.Add(board.GetMove("tri", "adr"));
            moves.Add(board.GetMove("vie", "tri"));
            moves.Add(board.GetMove("lon", "nth"));
            moves.Add(board.GetMove("nth", "nwg"));
            moves.Add(board.GetMove("wal", "yor"));
            moves.Add(board.GetMove("bre", "mao"));
            moves.Add(board.GetMove("bur", "bel"));
            //A Spa H ? SUCCEEDS
            moves.Add(board.GetMove("den", "swe"));
            moves.Add(board.GetMove("kie", "mun"));
            moves.Add(board.GetMove("ruh", "hol"));
            moves.Add(board.GetConvoyMove("apu", "tun", "ion"));
            //A Ven H ? SUCCEEDS
            moves.Add(board.GetMove("fin", "bot"));
            //A Lvn H ? SUCCEEDS
            //F Rum H ? SUCCEEDS
            moves.Add(board.GetMove("stp", "nwy"));
            moves.Add(board.GetMove("con", "bul_sc"));
            moves.Add(board.GetMove("smy", "ank"));
            moves.FillHolds(board);
            board.ApplyMoves(moves, true);
            board.EndTurn();

            // 1901 Winter
            moves = new BoardMove();
            moves.Add(board.GetBuildMove("vie", UnitType.Army));
            moves.Add(board.GetBuildMove("bre", UnitType.Fleet));
            moves.Add(board.GetBuildMove("mar", UnitType.Fleet));
            moves.Add(board.GetBuildMove("ber", UnitType.Fleet));
            moves.Add(board.GetBuildMove("kie", UnitType.Fleet));
            moves.Add(board.GetBuildMove("nap", UnitType.Fleet));
            moves.Add(board.GetBuildMove("mos", UnitType.Army));
            moves.Add(board.GetBuildMove("stp_nc", UnitType.Fleet));
            moves.Add(board.GetBuildMove("smy", UnitType.Fleet));
            moves.Add(board.GetBuildMove("con", UnitType.Fleet));
            moves.FillHolds(board);
            board.ApplyMoves(moves, true);
            board.EndTurn();

            //moves.Clear();
            //moves.Add(board.GetMove("bot", "swe"));
            //moves.Add(board.GetMove("kie", "hol"));
            //moves.Add(board.GetMove("ruh", "bel"));
            //moves.FillHolds(board);
            //board.ApplyMoves(moves);
            //board.EndTurn();

            FeatureToolCollection toolCollection = new FeatureToolCollection();

            toolCollection.Add(new RelativeTerritoryStrengths());
            FeatureMeasurementCollection measurements = toolCollection.GetMeasurements(board);

            BoardViewer.Draw(board, measurements);
        }