private void ExploreNode(Node currentNode) { if (currentNode.CumulativeCost < AP) { foreach (Hex neighbor in BoardManager.GetNeighborsOfHex(currentNode.OwnedHex)) { if (neighbor != null) { if (currentNode.Source != neighbor && !neighbor.isOccupied()) { Node neighborNode = MapNodes.Find(node => node == neighbor); if (neighborNode == null) { Node NodeToAdd = GenerateNode(currentNode, neighbor); if (NodeToAdd != null) { MapNodes.Add(NodeToAdd); } } else { currentNode.Source = CompareSourceNodes(currentNode, currentNode.Source, neighborNode); neighborNode.Source = CompareSourceNodes(neighborNode, neighborNode.Source, currentNode); } } } } } }
public static List <string> GetSystemsXJumpsFrom(List <string> sysList, string start, int X) { if (MapNodes == null || !MapNodes.ContainsKey(start)) { return(sysList); } if (X != 0) { if (!sysList.Contains(start)) { sysList.Add(start); } MapNode mn = MapNodes[start]; foreach (string mm in mn.Connections) { if (!sysList.Contains(mm)) { sysList.Add(mm); } List <string> connected = GetSystemsXJumpsFrom(sysList, mm, X - 1); foreach (string s in connected) { if (!sysList.Contains(s)) { sysList.Add(s); } } } } return(sysList); }
public UnitMove GetBuildMove(string mapNodeName, UnitType unitType) { Unit unit; MapNode mapNode = MapNodes.Get(mapNodeName); OccupiedMapNodes.TryGetValue(mapNode, out unit); if (unit != null) { throw new ArgumentException($"A {unit.Power} {unit.UnitType} unit occupies {mapNodeName} "); } if (!mapNode.Territory.IsSupplyCenter) { throw new ArgumentException($"Can't build in {mapNode.Territory} because it's not a supply center"); } if (!OwnedSupplyCenters.Any(kvp => kvp.Value.Contains(mapNode.Territory))) { throw new ArgumentException($"No power controls {mapNode.Territory}"); } Powers power = OwnedSupplyCenters.Where(kvp => kvp.Value.Contains(mapNode.Territory)).First().Key; var edge = Maps.BuildMap.AdjacentOutEdges(MapNodes.Get("build")).First(e => e.Target == mapNode); if (unitType == UnitType.Army) { unit = Army.Get(power); } else { unit = Fleet.Get(power); } UnitMove uBuild = new UnitMove(unit, edge); return(uBuild); }
public void MapNodeNeighbors() { var edges = Maps.Fleet.AdjacentEdges(MapNodes.Get("nth")); // there are 22 edges, 11 in and 11 out Assert.AreEqual(11, edges.Count(e => e.Source.ToString() == "nth")); Assert.AreEqual(11, edges.Count(e => e.Target.ToString() == "nth")); }
public void DistanceTest() { var alg = new QuickGraph.Algorithms.ShortestPath.UndirectedDijkstraShortestPathAlgorithm <MapNode, UndirectedEdge <MapNode> >(Maps.Fleet, w => 1); alg.SetRootVertex(MapNodes.Get("sev")); alg.Compute(); Assert.AreEqual(6, alg.Distances[MapNodes.Get("ven")]); Assert.AreEqual(13, alg.Distances[MapNodes.Get("stp_sc")]); }
public void GenerateAllInitialMovesSingleUnit() { Board board = Board.GetInitialBoard(); IEnumerable <BoardMove> futureMoves = BoardFutures.GetBoardMovesFallSpring(board, new List <MapNode>() { MapNodes.Get("kie") }); Assert.AreEqual(6, futureMoves.Count()); }
protected void ReplaceNode(Node oldNode, Node newNode) { int index = MapNodes.IndexOf(oldNode); if (index >= 0) { MapNodes[index] = newNode; } oldNode = null; }
public void UnitBuildConstruction() { MapNode munich = MapNodes.Get("mun"); Unit germanUnit = Army.Get(Powers.Germany); var edge = Maps.BuildMap.AdjacentOutEdges(MapNodes.Get("build")).First(e => e.Target == munich); UnitMove uBuild = new UnitMove(germanUnit, edge); Assert.IsTrue(uBuild.IsBuild); }
public void AddNodePair(string a, string b) { if (!MapNodes.ContainsKey(a)) { // need to set things up var nodes = new List <string>(); MapNodes.Add(a, nodes); } MapNodes[a].Add(b); }
public UnitMove GetMove(string sourceMapNodeName, string targetMapNodeName) { Unit unit; OccupiedMapNodes.TryGetValue(MapNodes.Get(sourceMapNodeName), out unit); if (unit == null) { throw new ArgumentException($"No unit occupies {sourceMapNodeName} "); } return(unit.GetMove(sourceMapNodeName, targetMapNodeName)); }
public void UnitMoveConstruction() { MapNode munich = MapNodes.Get("mun"); Unit germanUnit = initialBoard.OccupiedMapNodes[munich]; var edge = Maps.Army.AdjacentOutEdges(munich).First(); UnitMove uMove = new UnitMove(germanUnit, edge); Assert.IsFalse(uMove.IsHold); UnitMove uMove2 = new UnitMove(germanUnit, munich); Assert.IsTrue(uMove2.IsHold); }
public void UnitMove() { Board board = Board.GetInitialBoard(); BoardMove moves = new BoardMove(); Unit fleet = board.OccupiedMapNodes[MapNodes.Get("edi")]; var edge = fleet.MyMap.GetEdge("edi", "nth"); moves.Add(new UnitMove(fleet, edge)); moves.FillHolds(board); board.ApplyMoves(moves); Assert.IsTrue(board.OccupiedMapNodes.ContainsKey(MapNodes.Get("nth"))); Assert.IsFalse(board.OccupiedMapNodes.ContainsKey(MapNodes.Get("edi"))); Assert.AreEqual(board.OccupiedMapNodes.Count, moves.Count); }
internal void UpdateTileContents(int xPos, int yPos) { if (xPos < 0) { xPos = 0; } if (yPos < 0) { yPos = 0; } if (yPos >= MapNodes.GetUpperBound(1)) { return; } if (xPos >= MapNodes.GetUpperBound(0)) { return; } MapNodes[xPos, yPos].Empty(); { if (BaseMap[xPos, yPos] == TileContent.Wall) { MapNodes[xPos, yPos].Add(TileContent.Wall); return; } var objects = GetObjects(this, i => i.X == xPos && i.Y == yPos, Get.Monsters | Get.Mundanes | Get.Aislings); foreach (var obj in objects) { if (MapNodes[xPos, yPos].IsAvailable()) { MapNodes[xPos, yPos].Add(obj.EntityType); } } } }
public void UnitMoveEquality() { List <UnitMove> mv = new List <UnitMove>() { new UnitMove(Army.Get(Powers.Austria), MapNodes.Get("nth")), //0 new UnitMove(Army.Get(Powers.Austria), MapNodes.Get("nth")), //1 new UnitMove(Army.Get(Powers.Austria), MapNodes.Get("edi")), //2 new UnitMove(Army.Get(Powers.Austria), MapNodes.Get("nth"), true), //3 new UnitMove(Army.Get(Powers.Austria), MapNodes.Get("nth"), true), //4 new UnitMove(Army.Get(Powers.England), MapNodes.Get("nth"), true), //5 new UnitMove(Army.Get(Powers.England), new QuickGraph.UndirectedEdge <MapNode>(MapNodes.Get("nth"), MapNodes.Get("yor"))), //6 new UnitMove(Army.Get(Powers.England), new QuickGraph.UndirectedEdge <MapNode>(MapNodes.Get("nth"), MapNodes.Get("yor"))), //7 new UnitMove(Army.Get(Powers.Germany), new QuickGraph.UndirectedEdge <MapNode>(MapNodes.Get("nth"), MapNodes.Get("yor"))), //8 new UnitMove(Army.Get(Powers.Germany), new QuickGraph.UndirectedEdge <MapNode>(MapNodes.Get("yor"), MapNodes.Get("nth"))), //9 new UnitMove(Army.Get(Powers.Germany), new QuickGraph.UndirectedEdge <MapNode>(MapNodes.Get("yor"), MapNodes.Get("nwy")), new List <MapNode> { MapNodes.Get("nth"), MapNodes.Get("nwy"), }), //10 new UnitMove(Army.Get(Powers.Germany), new QuickGraph.UndirectedEdge <MapNode>(MapNodes.Get("yor"), MapNodes.Get("nwy")), new List <MapNode> { MapNodes.Get("nth"), MapNodes.Get("nwy"), }), //11 new UnitMove(Army.Get(Powers.Germany), new QuickGraph.UndirectedEdge <MapNode>(MapNodes.Get("yor"), MapNodes.Get("nwy")), new List <MapNode> { MapNodes.Get("nth"), MapNodes.Get("nwg"), MapNodes.Get("nwy"), }), //12 new UnitMove(Fleet.Get(Powers.England), new QuickGraph.UndirectedEdge <MapNode>(MapNodes.Get("nth"), MapNodes.Get("yor"))), //13 }; Assert.AreEqual(mv[0], mv[1]); Assert.AreEqual(mv[3], mv[4]); Assert.AreEqual(mv[6], mv[7]); Assert.AreEqual(mv[10], mv[11]); Assert.AreNotEqual(mv[1], mv[2]); Assert.AreNotEqual(mv[2], mv[3]); Assert.AreNotEqual(mv[4], mv[5]); Assert.AreNotEqual(mv[7], mv[8]); Assert.AreNotEqual(mv[8], mv[9]); Assert.AreNotEqual(mv[9], mv[10]); Assert.AreNotEqual(mv[10], mv[12]); Assert.AreNotEqual(mv[0], mv[6]); Assert.AreNotEqual(mv[1], mv[3]); Assert.AreNotEqual(mv[3], mv[6]); Assert.AreNotEqual(mv[8], mv[11]); Assert.AreNotEqual(mv[6], mv[13]); }
public static MapNodeRenderStyle Get(string mapNodeShortName, double x, double y) { MapNode node = MapNodes.Get(mapNodeShortName); switch (node.Territory.TerritoryType) { case TerritoryType.Sea: return(new MapNodeRenderStyle(VertexShape.Ellipse, x, y)); case TerritoryType.Coast: return(new MapNodeRenderStyle(VertexShape.Rectangle, x, y)); case TerritoryType.Inland: return(new MapNodeRenderStyle(VertexShape.Rectangle, x, y)); default: throw new Exception($"Unknown TerritoryType: {node.Territory.TerritoryType}"); } }
public override void CreateMap(Hex origin) { EndVisualization(); MapNodes.Clear(); MapNodes.Add(new NavigableNode(origin, null, 0)); int nodesExplored = 0; if (BattleManager.controlledCharacter == Owner) { AP = BattleManager.RemainingAP; } else { AP = Owner.ActionPoints; } while (nodesExplored < MapNodes.Count) { ExploreNode(MapNodes[nodesExplored]); nodesExplored++; } }
public UnitMove GetConvoyMove(string startMapNodeName, string endMapNodeName, params string[] convoyMapNodes) { Unit unit; MapNode startMapNode = MapNodes.Get(startMapNodeName); MapNode endMapNode = MapNodes.Get(endMapNodeName); OccupiedMapNodes.TryGetValue(startMapNode, out unit); if (unit == null) { throw new ArgumentException($"No unit occupies {startMapNodeName} "); } List <MapNode> convoyRoute = new List <MapNode>(); foreach (string convoyMapNode in convoyMapNodes) { convoyRoute.Add(MapNodes.Get(convoyMapNode)); } UnitMove uConvoy = new UnitMove(unit, new UndirectedEdge <MapNode>(startMapNode, endMapNode), convoyRoute); return(uConvoy); }
public void GenerateMap() { MapBox.CreateGraphics().Clear(AppWindow.DefaultBackColor); int w = 0, h = 0; try { w = Convert.ToInt32(TXTWidth.Text); h = Convert.ToInt32(TXTHeight.Text); } catch { Console.WriteLine("Input string is not a sequence of digits or Overflow"); w = 20; h = 20; } paintMap = new Bitmap(MapBox.Size.Width, MapBox.Size.Height); g = Graphics.FromImage(paintMap); nodes = new MapNodes(w + 2, h + 2, MapBox.Size.Height); // + 2 is borders g.DrawRectangles(stdPen, nodes.nodeRect); FillBorderNodes(); GenerateNoise(); MapBox.Image = paintMap; }
public override void CreateMap(Hex origin) { EndVisualization(); MapNodes.Clear(); List <Hex> hexesToCheck = new List <Hex>(); hexesToCheck.AddRange(BoardManager.GetNeighborsOfHex(origin)); int counter = 0; while (counter < hexesToCheck.Count) { Hex testingHex = hexesToCheck[counter]; if (testingHex != null) { int distance = BoardManager.CalculateHexDistance(origin, testingHex); if (distance < associatedWeapon.WeaponRange) { foreach (Hex hex in BoardManager.GetNeighborsOfHex(testingHex)) { if (!hexesToCheck.Contains(hex) && !Contains((hex))) { hexesToCheck.Add(hex); } } } if (associatedWeapon.WeaponRange.IsInRange(distance)) { MapNodes.Add(GenerateNode(null, testingHex)); } } counter++; } }
public static Dictionary <string, int> GetJumpsOfEachSystemInRange(int targetJumps, int currentJump, string location) { var jumpsOfEachSystem = new Dictionary <string, int>(); if (!MapNodes.ContainsKey(location) || currentJump > targetJumps) { return(jumpsOfEachSystem); } var targetSystemNode = MapNodes[location]; jumpsOfEachSystem.Add(location, currentJump); foreach (var connectedNode in targetSystemNode.Connections) { var connectedSystems = GetJumpsOfEachSystemInRange(targetJumps, currentJump + 1, connectedNode); foreach (var connectedSystem in connectedSystems) { if (jumpsOfEachSystem.ContainsKey(connectedSystem.Key)) { var jumpsInCache = jumpsOfEachSystem[connectedSystem.Key]; if (jumpsInCache > connectedSystem.Value) { jumpsOfEachSystem[connectedSystem.Key] = connectedSystem.Value; } } else { jumpsOfEachSystem.Add(connectedSystem.Key, connectedSystem.Value); } } } return(jumpsOfEachSystem); }
public bool Contains(Hex hex) { return(MapNodes.Any(node => node == hex)); }
public void ClearPath() { MapNodes.Clear(); }
public static Board GetInitialBoard() { var board = new Board(); board.Year = 1901; board.Season = new Spring(); board.OccupiedMapNodes = new Dictionary <MapNode, Unit>() { { MapNodes.Get("edi"), Fleet.Get(Powers.England) }, { MapNodes.Get("lon"), Fleet.Get(Powers.England) }, { MapNodes.Get("lvp"), Army.Get(Powers.England) }, { MapNodes.Get("kie"), Fleet.Get(Powers.Germany) }, { MapNodes.Get("ber"), Army.Get(Powers.Germany) }, { MapNodes.Get("mun"), Army.Get(Powers.Germany) }, { MapNodes.Get("bre"), Fleet.Get(Powers.France) }, { MapNodes.Get("par"), Army.Get(Powers.France) }, { MapNodes.Get("mar"), Army.Get(Powers.France) }, { MapNodes.Get("nap"), Fleet.Get(Powers.Italy) }, { MapNodes.Get("rom"), Army.Get(Powers.Italy) }, { MapNodes.Get("ven"), Army.Get(Powers.Italy) }, { MapNodes.Get("tri"), Fleet.Get(Powers.Austria) }, { MapNodes.Get("bud"), Army.Get(Powers.Austria) }, { MapNodes.Get("vie"), Army.Get(Powers.Austria) }, { MapNodes.Get("ank"), Fleet.Get(Powers.Turkey) }, { MapNodes.Get("con"), Army.Get(Powers.Turkey) }, { MapNodes.Get("smy"), Army.Get(Powers.Turkey) }, { MapNodes.Get("stp_sc"), Fleet.Get(Powers.Russia) }, { MapNodes.Get("sev"), Fleet.Get(Powers.Russia) }, { MapNodes.Get("mos"), Army.Get(Powers.Russia) }, { MapNodes.Get("war"), Army.Get(Powers.Russia) }, }; board.OwnedSupplyCenters = new Dictionary <Powers, ISet <Territory> >() { { Powers.England, new HashSet <Territory>() }, { Powers.Germany, new HashSet <Territory>() }, { Powers.France, new HashSet <Territory>() }, { Powers.Italy, new HashSet <Territory>() }, { Powers.Austria, new HashSet <Territory>() }, { Powers.Turkey, new HashSet <Territory>() }, { Powers.Russia, new HashSet <Territory>() }, { Powers.None, new HashSet <Territory>() }, }; board.OccupiedTerritories = new Dictionary <Territory, Unit>(); foreach (var kvp in board.OccupiedMapNodes) { board.OwnedSupplyCenters[kvp.Value.Power].Add(kvp.Key.Territory); board.OccupiedTerritories[kvp.Key.Territory] = kvp.Value; } foreach (var mapNode in Maps.Full.Vertices) { if (board.OccupiedMapNodes.Keys.Contains(mapNode)) { continue; } if (mapNode.Territory.IsSupplyCenter) { board.OwnedSupplyCenters[Powers.None].Add(mapNode.Territory); } } return(board); }
public List <MapNode> NodesWithUnjoinedEntry(Edge edge) { return(MapNodes.FindAll(n => !n.IsEntryJoined(edge))); }
private void QPush(int i, MapNodes.Node n) { mapNodes.nodeGrid[i].parent = n; mapNodes.nodeGrid[i].visited = true; queueNodes.Enqueue(mapNodes.nodeGrid[i]); }
public PathFind(MapNodes m, Rectangle s) { nodeList = new List <MapNodes.Node>(); mapNodes = m; start = s; }
public bool Contains(Node node) { return(MapNodes.Contains(node)); }
public UndirectedEdge <MapNode> GetEdge(string shortNameSource, string shortNameTarget) => GetEdge(MapNodes.Get(shortNameSource), MapNodes.Get(shortNameTarget));
public void GenerateWinterMovesNoEmptyBuilds() { Board board = Board.GetInitialBoard(); BoardMove moves = new BoardMove(); moves.Add(board.GetMove("tri", "ven")); moves.Add(board.GetMove("ven", "pie")); moves.Add(board.GetMove("ber", "kie")); moves.Add(board.GetMove("kie", "den")); moves.Add(board.GetMove("mun", "ruh")); moves.Add(board.GetMove("stp_sc", "bot")); moves.Add(board.GetMove("sev", "rum")); moves.FillHolds(board); board.ApplyMoves(moves); 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(); Assert.AreEqual(6, board.OwnedSupplyCenters[Powers.Germany].Count); Assert.AreEqual(6, board.OwnedSupplyCenters[Powers.Russia].Count); Assert.AreEqual(2, board.OwnedSupplyCenters[Powers.Italy].Count); Assert.AreEqual(4, board.OwnedSupplyCenters[Powers.Austria].Count); var boardMoves = BoardFutures.GetAllBoardMovesWinter(board); Assert.IsTrue(boardMoves.All(bm => null != bm.FirstOrDefault(um => um.Edge.Target == MapNodes.Get("mun")))); Assert.AreEqual(144, boardMoves.Count()); //this is the total for when empty builds are included //Assert.AreEqual(1944, boardMoves.Count()); }
public Node GetNodeForHex(Hex hex) { return(MapNodes.Find(node => node == hex)); }
public PathFind(MapNodes m, Rectangle s) { nodeList = new List<MapNodes.Node>(); mapNodes = m; start = s; }
public void BoardMoveEquality() { List <UnitMove> mv = new List <UnitMove>() { new UnitMove(Fleet.Get(Powers.Austria), MapNodes.Get("nao")), //0 new UnitMove(Fleet.Get(Powers.Austria), MapNodes.Get("nth")), //1 new UnitMove(Army.Get(Powers.Austria), MapNodes.Get("edi")), //2 new UnitMove(Army.Get(Powers.Austria), MapNodes.Get("mun"), true), //3 new UnitMove(Army.Get(Powers.Austria), MapNodes.Get("stp"), true), //4 new UnitMove(Army.Get(Powers.England), MapNodes.Get("eng"), true), //5 new UnitMove(Fleet.Get(Powers.England), new QuickGraph.UndirectedEdge <MapNode>(MapNodes.Get("nwy"), MapNodes.Get("bar"))), //6 new UnitMove(Fleet.Get(Powers.England), new QuickGraph.UndirectedEdge <MapNode>(MapNodes.Get("mao"), MapNodes.Get("wes"))), //7 new UnitMove(Army.Get(Powers.Germany), new QuickGraph.UndirectedEdge <MapNode>(MapNodes.Get("mun"), MapNodes.Get("boh"))), //8 new UnitMove(Army.Get(Powers.Germany), new QuickGraph.UndirectedEdge <MapNode>(MapNodes.Get("sil"), MapNodes.Get("war"))), //9 new UnitMove(Army.Get(Powers.Russia), new QuickGraph.UndirectedEdge <MapNode>(MapNodes.Get("stp"), MapNodes.Get("swe")), new List <MapNode> { MapNodes.Get("bot"), }), //10 new UnitMove(Army.Get(Powers.Russia), new QuickGraph.UndirectedEdge <MapNode>(MapNodes.Get("sev"), MapNodes.Get("ank")), new List <MapNode> { MapNodes.Get("bla"), }), //11 new UnitMove(Army.Get(Powers.France), new QuickGraph.UndirectedEdge <MapNode>(MapNodes.Get("mar"), MapNodes.Get("tus")), new List <MapNode> { MapNodes.Get("lyo"), MapNodes.Get("wes"), MapNodes.Get("tys"), }), //12 }; List <UnitMove> mv2 = new List <UnitMove>() { new UnitMove(Fleet.Get(Powers.Austria), MapNodes.Get("nao")), //0 new UnitMove(Fleet.Get(Powers.Austria), MapNodes.Get("nth")), //1 new UnitMove(Army.Get(Powers.Austria), MapNodes.Get("edi")), //2 new UnitMove(Army.Get(Powers.Austria), MapNodes.Get("mun"), true), //3 new UnitMove(Army.Get(Powers.Austria), MapNodes.Get("stp"), true), //4 new UnitMove(Army.Get(Powers.England), MapNodes.Get("eng"), true), //5 new UnitMove(Fleet.Get(Powers.England), new QuickGraph.UndirectedEdge <MapNode>(MapNodes.Get("nwy"), MapNodes.Get("bar"))), //6 new UnitMove(Fleet.Get(Powers.England), new QuickGraph.UndirectedEdge <MapNode>(MapNodes.Get("mao"), MapNodes.Get("wes"))), //7 new UnitMove(Army.Get(Powers.Germany), new QuickGraph.UndirectedEdge <MapNode>(MapNodes.Get("mun"), MapNodes.Get("boh"))), //8 new UnitMove(Army.Get(Powers.Germany), new QuickGraph.UndirectedEdge <MapNode>(MapNodes.Get("sil"), MapNodes.Get("war"))), //9 new UnitMove(Army.Get(Powers.Russia), new QuickGraph.UndirectedEdge <MapNode>(MapNodes.Get("stp"), MapNodes.Get("swe")), new List <MapNode> { MapNodes.Get("bot"), }), //10 new UnitMove(Army.Get(Powers.Russia), new QuickGraph.UndirectedEdge <MapNode>(MapNodes.Get("sev"), MapNodes.Get("ank")), new List <MapNode> { MapNodes.Get("bla"), }), //11 new UnitMove(Army.Get(Powers.France), new QuickGraph.UndirectedEdge <MapNode>(MapNodes.Get("mar"), MapNodes.Get("tus")), new List <MapNode> { MapNodes.Get("lyo"), MapNodes.Get("wes"), MapNodes.Get("tys"), }), //12 }; BoardMove boardMove1 = new BoardMove(); boardMove1.AddRange(mv); BoardMove boardMove2 = new BoardMove(); boardMove2.AddRange(mv2); BoardMove boardMove3 = new BoardMove(); boardMove3.AddRange(mv.Where(um => um.Unit.UnitType == UnitType.Army)); Assert.AreNotEqual(boardMove1, boardMove3); BoardMove boardMove4 = new BoardMove(); boardMove4.AddRange(mv.Take(12)); boardMove4.Add(new UnitMove(Army.Get(Powers.Germany), new QuickGraph.UndirectedEdge <MapNode>(MapNodes.Get("mar"), MapNodes.Get("tus")), new List <MapNode> { MapNodes.Get("lyo"), MapNodes.Get("wes"), MapNodes.Get("tys"), })); Assert.AreNotEqual(boardMove1, boardMove4); }