private void SetupAllianceScenario() { allianceScenario = new AllianceScenario(); allianceScenario.AddRelationship(Powers.Germany, Powers.Russia, .7d, .6d); allianceScenario.AddRelationship(Powers.Germany, Powers.Austria, .5d, .5d); allianceScenario.AddRelationship(Powers.Germany, Powers.England, .6d, .5d); allianceScenario.AddRelationship(Powers.Germany, Powers.France, .3d, .3d); allianceScenario.AddRelationship(Powers.Germany, Powers.Turkey, .5d, .5d); allianceScenario.AddRelationship(Powers.Germany, Powers.Italy, .5d, .5d); allianceScenario.AddRelationship(Powers.Russia, Powers.Austria, .5d, .5d); allianceScenario.AddRelationship(Powers.Russia, Powers.England, .7d, .7d); allianceScenario.AddRelationship(Powers.Russia, Powers.France, .5d, .5d); allianceScenario.AddRelationship(Powers.Russia, Powers.Turkey, .3d, .3d); allianceScenario.AddRelationship(Powers.Russia, Powers.Italy, .6d, .6d); allianceScenario.AddRelationship(Powers.Austria, Powers.England, .5d, .5d); allianceScenario.AddRelationship(Powers.Austria, Powers.France, .5d, .5d); allianceScenario.AddRelationship(Powers.Austria, Powers.Turkey, .5d, .6d); allianceScenario.AddRelationship(Powers.Austria, Powers.Italy, .5d, .5d); allianceScenario.AddRelationship(Powers.England, Powers.France, .6d, .6d); allianceScenario.AddRelationship(Powers.England, Powers.Turkey, .5d, .5d); allianceScenario.AddRelationship(Powers.England, Powers.Italy, .5d, .5d); allianceScenario.AddRelationship(Powers.France, Powers.Turkey, .5d, .5d); allianceScenario.AddRelationship(Powers.France, Powers.Italy, .5d, .5d); allianceScenario.AddRelationship(Powers.Turkey, Powers.Italy, .6d, .6d); }
public void GenerateAllInitialMoves() { Board board = Board.GetInitialBoard(); AllianceScenario allianceScenario = AllianceScenario.GetRandomAllianceScenario(); ProbabilisticFuturesAlgorithm futuresAlgorithm = new ProbabilisticFuturesAlgorithm(); IEnumerable <Board> allFutureBoards = board.GetFutures(allianceScenario, futuresAlgorithm); }
public IEnumerable <BoardMove> GetBoardMovesFallSpring(Board board, AllianceScenario allianceScenario) { HashSet <BoardMove> completedBoardMoves = new HashSet <BoardMove>(); if (board.Season is Winter) { throw new Exception($"Bad season {board.Season}"); } foreach (var kvp in board.OccupiedMapNodes) { BoardMove workingBoardMove = new BoardMove(); List <MapNode> path; UnitMove currentMove; if (_targeter.TryGetMoveTargetValidateWithBoardMove(board, kvp.Key, allianceScenario, workingBoardMove, out path, out currentMove)) { workingBoardMove.Add(currentMove); } else { throw new Exception("Failed to add the very first move? Really!?"); } GetFallSpringMovesRemaining(board, allianceScenario, _targeter, workingBoardMove, completedBoardMoves); } return(completedBoardMoves); }
public void Populate(AllianceScenario allianceScenario) { IEnumerable <AllianceEdge> edges; if (FocusPower == Powers.None) { edges = allianceScenario.Edges; } else { edges = allianceScenario.Edges.Where(e => e.Source == FocusPower || e.Target == FocusPower); } foreach (var edge in edges) { DrawnPowerNode from = new DrawnPowerNode(edge.Source); DrawnPowerNode to = new DrawnPowerNode(edge.Target); DrawnAnimosityEdge drawnEdge = new DrawnAnimosityEdge(from, to, edge.Animosity); if (!ContainsVertex(from)) { AddVertex(from); } if (!ContainsVertex(to)) { AddVertex(to); } if (!ContainsEdge(drawnEdge)) { AddEdge(drawnEdge); } } }
public MainWindow() { InitializeComponent(); AllianceScenario allianceScenario = AllianceScenario.GetRandomAllianceScenario(); AllianceScenarioGraphControl.Draw(allianceScenario, DiplomacyLib.Models.Powers.Italy); }
public void AllianceScenarioInit() { AllianceScenario allianceScenario = AllianceScenario.GetRandomAllianceScenario(); Assert.AreEqual(42, allianceScenario.EdgeCount); Assert.AreEqual(7, allianceScenario.VertexCount); }
static void Main(string[] args) { AllianceScenario allianceScenario = AllianceScenario.GetRandomAllianceScenario(); Board board = Board.GetInitialBoard(); BoardMove moves = new BoardMove(); moves.Add(board.GetMove("ber", "kie")); moves.Add(board.GetMove("bud", "rum")); moves.Add(board.GetMove("con", "bul")); moves.Add(board.GetMove("lvp", "edi")); moves.Add(board.GetMove("mar", "pie")); moves.Add(board.GetMove("mos", "stp")); moves.Add(board.GetMove("mun", "ruh")); moves.Add(board.GetMove("par", "gas")); moves.Add(board.GetMove("rom", "nap")); moves.Add(board.GetMove("ven", "tyr")); moves.Add(board.GetMove("vie", "tri")); moves.Add(board.GetMove("war", "sil")); moves.Add(board.GetMove("ank", "con")); moves.Add(board.GetMove("bre", "mao")); moves.Add(board.GetMove("edi", "nth")); moves.Add(board.GetMove("kie", "den")); moves.Add(board.GetMove("lon", "eng")); moves.Add(board.GetMove("nap", "tys")); moves.Add(board.GetMove("sev", "bla")); moves.Add(board.GetMove("stp_sc", "bot")); moves.Add(board.GetMove("tri", "alb")); moves.FillHolds(board); board.ApplyMoves(moves); board.EndTurn(); moves.Clear(); moves.Add(board.GetMove("bul", "gre")); moves.Add(board.GetMove("gas", "spa")); moves.Add(board.GetMove("kie", "hol")); moves.Add(board.GetMove("ruh", "bel")); moves.Add(board.GetMove("smy", "arm")); moves.Add(board.GetMove("stp", "nwy")); moves.Add(board.GetMove("tri", "ser")); moves.Add(board.GetMove("bot", "swe")); moves.Add(board.GetMove("con", "bul_ec")); moves.Add(board.GetMove("mao", "por")); moves.Add(board.GetMove("tys", "tun")); moves.FillHolds(board); board.ApplyMoves(moves); board.EndTurn(); //var boardMoves = BoardFutures.GetAllBoardMovesWinter(board); var probabilisticFuturesAlgorithm = new ProbabilisticFuturesAlgorithm(); int limit = 20; List <Board> futureBoards = board.GetFutures(allianceScenario, probabilisticFuturesAlgorithm); while (futureBoards.Any() && limit > 0) { limit--; board = futureBoards[0]; futureBoards = board.GetFutures(allianceScenario, probabilisticFuturesAlgorithm); } }
public void Draw(AllianceScenario allianceScenario, Powers focus) { try { _executing = true; var logicCore = new AllianceScenarioGXLogicCore(); var drawnAllianceScenario = new DrawnAllianceScenario(); drawnAllianceScenario.FocusPower = focus; drawnAllianceScenario.Populate(allianceScenario); logicCore.Graph = drawnAllianceScenario; /* * logicCore.DefaultLayoutAlgorithm = LayoutAlgorithmTypeEnum.FR; * logicCore.DefaultLayoutAlgorithmParams = logicCore.AlgorithmFactory.CreateLayoutParameters(LayoutAlgorithmTypeEnum.FR); * ((FreeFRLayoutParameters)logicCore.DefaultLayoutAlgorithmParams).IdealEdgeLength = 100; * ((FreeFRLayoutParameters)logicCore.DefaultLayoutAlgorithmParams).RepulsiveMultiplier = 1.5; * ((FreeFRLayoutParameters)logicCore.DefaultLayoutAlgorithmParams).Seed = 23423423; */ logicCore.DefaultLayoutAlgorithm = LayoutAlgorithmTypeEnum.KK; logicCore.DefaultLayoutAlgorithmParams = logicCore.AlgorithmFactory.CreateLayoutParameters(LayoutAlgorithmTypeEnum.KK); ((KKLayoutParameters)logicCore.DefaultLayoutAlgorithmParams).Width = 1000; ((KKLayoutParameters)logicCore.DefaultLayoutAlgorithmParams).Height = 1000; ((KKLayoutParameters)logicCore.DefaultLayoutAlgorithmParams).AdjustForGravity = true; ////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 = true; logicCore.ParallelEdgeDistance = 50; //Finally assign logic core to GraphArea object GraphArea.LogicCore = logicCore; GraphArea.SetVerticesDrag(true); GraphArea.GenerateGraph(); ZoomControl.ZoomToFill(); } finally { _executing = false; } }
public List <Board> GetFutures(AllianceScenario allianceScenario, IFuturesAlgorithm futuresAlgorithm) { if (_futureBoardsDirty) { _futureBoards = Season.GetFutures(this, allianceScenario, futuresAlgorithm).ToList(); _futureBoardsDirty = false; } return(_futureBoards); }
private void GetFallSpringMovesRemaining(Board board, AllianceScenario allianceScenario, ITargeter unitTargetCalculator, BoardMove workingBoardMove, HashSet <BoardMove> completedBoardMoves) { foreach (var kvp in board.OccupiedMapNodes.Where(kvp2 => !workingBoardMove.Sources.Contains(kvp2.Key))) { List <MapNode> path; UnitMove currentMove; if (unitTargetCalculator.TryGetMoveTargetValidateWithBoardMove(board, kvp.Key, allianceScenario, workingBoardMove, out path, out currentMove)) { workingBoardMove.Add(currentMove); } else { // uh oh, contradiction return; } } completedBoardMoves.Add(workingBoardMove.Clone()); return; }
public IEnumerable <BoardMove> GetBoardMovesWinter(Board board, AllianceScenario allianceScenario) { if (!(board.Season is Winter)) { throw new Exception($"Bad season {board.Season}"); } List <UnitMove> winterUnitMoves = board.GetUnitMoves(); if (!winterUnitMoves.Any()) { return(Enumerable.Empty <BoardMove>()); } var buildDisbandCounts = board.GetBuildAndDisbandCounts(); BoardMove workingMove = new BoardMove(); List <Powers> completedPowers = new List <Powers>(); foreach (UnitMove unitMove in winterUnitMoves.Where(um => !completedPowers.Contains(um.Unit.Power))) { Powers currentPower = unitMove.Unit.Power; if (workingMove.CurrentlyAllowsWinter(unitMove, buildDisbandCounts[currentPower])) { workingMove.Add(unitMove); if (workingMove.Count(um => um.Unit.Power == currentPower) == Math.Abs(buildDisbandCounts[currentPower])) { completedPowers.Add(currentPower); } } } if (buildDisbandCounts.Count(kvp => kvp.Value != 0) != completedPowers.Count) { throw new Exception("Looks like I created an incomplete move"); } workingMove.FillHolds(board); return(new List <BoardMove>() { workingMove }); }
public void PossibleCoalitions() { AllianceScenario allianceScenario = AllianceScenario.GetRandomAllianceScenario(); PowersDictionary <Coalition> possibleCoalitions = allianceScenario.GetPossibleCoalitions(); Assert.AreEqual(7, possibleCoalitions.Count); StringBuilder sb = new StringBuilder(); foreach (KeyValuePair <Powers, Coalition> kvp in possibleCoalitions) { foreach (KeyValuePair <Powers, bool> kvp2 in kvp.Value) { if (kvp.Key == kvp2.Key) { continue; } sb.AppendLine($"allianceScenario.AddRelationship(Powers.{kvp.Key}, Powers.{kvp2.Key}, .6d, .6d);"); } } string s = sb.ToString(); }
public IEnumerable <Board> GetWinterBoardFutures(Board board, AllianceScenario allianceScenario) { List <BoardMove> allBoardMoves = GetBoardMovesWinter(board, allianceScenario).ToList(); return(BoardFutures.ApplyAllBoardMoves(board, allBoardMoves)); }
public override IEnumerable <Board> GetFutures(Board board, AllianceScenario allianceScenario, IFuturesAlgorithm futuresAlgorithm) => futuresAlgorithm.GetWinterBoardFutures(board, allianceScenario);
public abstract IEnumerable <Board> GetFutures(Board board, AllianceScenario allianceScenario, IFuturesAlgorithm futuresAlgorithm);
public bool TryGetMoveTargetValidateWithBoardMove(Board board, MapNode source, AllianceScenario allianceScenario, BoardMove boardMove, out List <MapNode> path, out UnitMove move) { if (!board.OccupiedMapNodes.ContainsKey(source)) { throw new Exception($"No unit occupies {source} in the given board"); } var movesAvailableForSource = boardMove.GetAvailableFallSpringMovesForMapNode(board, source); if (movesAvailableForSource.Count == 0) { // couldn't find anything. // this is caused by picking moves that lead to a contradiction. // Force the caller to deal, perhaps with a hold on all affected... path = null; move = null; return(false); } Unit unit = board.OccupiedMapNodes[source]; Coalition myCoalition = allianceScenario.GetPossibleCoalitions()[unit.Power]; List <KeyValuePair <MapNode, double> > orderedDistances = GetWeightedMapNodeDistances(board, source, allianceScenario) .OrderBy(kvp2 => kvp2.Value).ToList(); // are we sitting on a supplycenter that we want? If so, hold if (source.Territory.IsSupplyCenter && !board.SupplyCenterIsOwnedBy(source.Territory, myCoalition)) { UnitMove holdMove = new UnitMove(unit, source); if (boardMove == null || boardMove.CurrentlyAllowsFallSpring(holdMove)) { path = new List <MapNode>() { source }; move = holdMove; return(true); } } List <Func <MapNode, bool> > predicateList = new List <Func <MapNode, bool> >() { (mn) => { return(mn.Territory.IsSupplyCenter && !board.SupplyCenterIsOwnedBy(mn.Territory, myCoalition)); }, (mn) => { return(mn.Territory != source.Territory); }, (mn) => { return(mn.Territory == source.Territory); }, }; foreach (var predicate in predicateList) { path = GetPath(board, source, boardMove, orderedDistances, predicate); if (path != null) { MapNode moveTarget = path[1]; move = board.GetUnitMoves().FirstOrDefault(um => um.Edge.Source == source && um.Edge.Target == moveTarget); return(true); } } UnitMove lastResort = movesAvailableForSource.First(); path = new List <MapNode>() { lastResort.Edge.Target }; move = lastResort; return(true); }
public bool TryGetMoveTarget(Board board, MapNode source, AllianceScenario allianceScenario, out List <MapNode> path, out UnitMove move) { return(TryGetMoveTargetValidateWithBoardMove(board, source, allianceScenario, null, out path, out move)); }
private Dictionary <MapNode, double> GetWeightedMapNodeDistances(Board board, MapNode source, AllianceScenario allianceScenario) { Unit unit = board.OccupiedMapNodes[source]; TerritoryStrengths territoryStrengths = new TerritoryStrengths(); territoryStrengths.Init(board); Func <UndirectedEdge <MapNode>, double> WeightFunction = (edge) => { double powerCount = territoryStrengths.GetPowerCount(edge.Target.Territory, unit.Power); double totalAnimosity = allianceScenario.OutEdges(unit.Power) .Where(e => territoryStrengths.GetStrength(edge.Target.Territory, e.Target) > 0) .Sum(e => e.Animosity); return(1 + (powerCount - totalAnimosity)); }; var alg = new UndirectedDijkstraShortestPathAlgorithm <MapNode, UndirectedEdge <MapNode> >(unit.MyMap, WeightFunction); alg.SetRootVertex(source); _predecessorObserver.VertexPredecessors.Clear(); using (var foo = _predecessorObserver.Attach(alg)) { alg.Compute(); } return(alg.Distances); }
public IEnumerable <Board> GetFallSpringBoardFutures(Board board, AllianceScenario allianceScenario) { IEnumerable <BoardMove> boardMoves = GetBoardMovesFallSpring(board, allianceScenario); return(BoardFutures.ApplyAllBoardMoves(board, boardMoves)); }