示例#1
0
        private static Map CreateGraph(Dictionary <string, List <string> > adjacencyDict)
        {
            var graph = new Map();

            foreach (var kvp in adjacencyDict)
            {
                foreach (string targetNodeName in kvp.Value)
                {
                    var source = MapNodes.Get(kvp.Key);
                    var dest   = MapNodes.Get(targetNodeName);
                    if (!graph.ContainsVertex(source))
                    {
                        graph.AddVertex(source);
                    }
                    if (!graph.ContainsVertex(dest))
                    {
                        graph.AddVertex(dest);
                    }
                    if (!graph.ContainsEdge(source, dest))
                    {
                        graph.AddEdge(new UndirectedEdge <MapNode>(source, dest));
                    }
                }
            }

            return(graph);
        }
示例#2
0
        public static IEnumerable <UnitMove> GetWinterUnitMoves(Board board)
        {
            List <UnitMove> allMoves = new List <UnitMove>();
            PowersDictionary <IEnumerable <MapNode> > buildMapNodes = board.GetBuildMapNodes();
            PowersDictionary <int> differences = board.GetSupplyCenterToUnitDifferences();

            // get empty home centers owned by the home power
            foreach (var kvp in differences)
            {
                if (kvp.Key == Powers.None)
                {
                    continue;
                }
                if (kvp.Value > 0)
                {
                    // build
                    foreach (var mn in buildMapNodes[kvp.Key])
                    {
                        if (Fleet.Get(kvp.Key).TerritoryCompatible(mn.Territory) && Maps.Fleet.Vertices.Contains(mn))
                        {
                            allMoves.Add(new UnitMove(Fleet.Get(kvp.Key), new UndirectedEdge <MapNode>(MapNodes.Get("build"), mn)));
                        }
                        if (Army.Get(kvp.Key).TerritoryCompatible(mn.Territory) && Maps.Army.Vertices.Contains(mn))
                        {
                            allMoves.Add(new UnitMove(Army.Get(kvp.Key), new UndirectedEdge <MapNode>(MapNodes.Get("build"), mn)));
                        }
                    }
                }
                else if (kvp.Value < 0)
                {
                    // disband
                    foreach (var disbandKvp in board.OccupiedMapNodes.Where(p => p.Value.Power == kvp.Key))
                    {
                        allMoves.Add(new UnitMove(disbandKvp.Value, new UndirectedEdge <MapNode>(disbandKvp.Key, null)));
                    }
                }
            }
            return(allMoves);
        }