public void DisbandWinterUnitMoves() { Board board = Board.GetInitialBoard(); BoardMove moves = new BoardMove(); moves.Add(board.GetMove("tri", "ven")); moves.Add(board.GetMove("ven", "pie")); moves.FillHolds(board); board.ApplyMoves(moves); board.EndTurn(); moves.Clear(); moves.FillHolds(board); board.ApplyMoves(moves); board.EndTurn(); Assert.AreEqual(2, board.OwnedSupplyCenters[Powers.Italy].Count); Assert.AreEqual(4, board.OwnedSupplyCenters[Powers.Austria].Count); Assert.AreEqual(22, board.OwnedSupplyCenters.Where(kvp => kvp.Key != Powers.None).SelectMany(kvp => kvp.Value).Count()); var unitMoves = board.GetUnitMoves(); Assert.AreEqual(2, unitMoves.Count(um => um.IsBuild)); Assert.AreEqual(3, unitMoves.Count(um => um.IsDisband)); }
public void OwnedSupplyCentersOwnershipSwitch() { Board board = Board.GetInitialBoard(); BoardMove moves = new BoardMove(); moves.Add(board.GetMove("par", "pic")); moves.Add(board.GetMove("mun", "bur")); moves.FillHolds(board); board.ApplyMoves(moves); Assert.AreEqual(3, board.OwnedSupplyCenters[Powers.Germany].Count); Assert.AreEqual(3, board.OwnedSupplyCenters[Powers.France].Count); board.EndTurn(); Assert.AreEqual(3, board.OwnedSupplyCenters[Powers.Germany].Count); Assert.AreEqual(3, board.OwnedSupplyCenters[Powers.France].Count); moves.Clear(); moves.Add(board.GetMove("bur", "par")); moves.FillHolds(board); board.ApplyMoves(moves); Assert.AreEqual(3, board.OwnedSupplyCenters[Powers.Germany].Count); Assert.AreEqual(3, board.OwnedSupplyCenters[Powers.France].Count); board.EndTurn(); Assert.AreEqual(4, board.OwnedSupplyCenters[Powers.Germany].Count); Assert.AreEqual(2, board.OwnedSupplyCenters[Powers.France].Count); Assert.AreEqual(22, board.OwnedSupplyCenters.Where(kvp => kvp.Key != Powers.None).SelectMany(kvp => kvp.Value).Count()); }
public void BoardCloneTest() { Board board = Board.GetInitialBoard(); Board clone = board.Clone(); Assert.AreEqual(clone.OwnedSupplyCenters[Powers.Germany].Count, board.OwnedSupplyCenters[Powers.Germany].Count); BoardMove moves = new BoardMove(); moves.Add(clone.GetMove("kie", "den")); moves.Add(clone.GetMove("ber", "kie")); moves.FillHolds(clone); clone.ApplyMoves(moves); clone.EndTurn(); Assert.AreNotEqual(clone.Turn, board.Turn); moves.Clear(); moves.Add(clone.GetMove("kie", "hol")); moves.FillHolds(clone); clone.ApplyMoves(moves); clone.EndTurn(); Assert.AreNotEqual(clone.OwnedSupplyCenters[Powers.Germany].Count, board.OwnedSupplyCenters[Powers.Germany].Count); }
public void BuildUnitMoves() { Board board = Board.GetInitialBoard(); BoardMove moves = new BoardMove(); moves.Add(board.GetMove("kie", "den")); moves.Add(board.GetMove("ber", "kie")); moves.FillHolds(board); board.ApplyMoves(moves); Assert.AreEqual(3, board.OwnedSupplyCenters[Powers.Germany].Count); board.EndTurn(); Assert.AreEqual(3, board.OwnedSupplyCenters[Powers.Germany].Count); moves.Clear(); moves.Add(board.GetMove("kie", "hol")); moves.FillHolds(board); board.ApplyMoves(moves); Assert.AreEqual(3, board.OwnedSupplyCenters[Powers.Germany].Count); board.EndTurn(); Assert.AreEqual(5, board.OwnedSupplyCenters[Powers.Germany].Count); Assert.AreEqual(24, board.OwnedSupplyCenters.Where(kvp => kvp.Key != Powers.None).SelectMany(kvp => kvp.Value).Count()); var unitMoves = board.GetUnitMoves(); Assert.AreEqual(4, unitMoves.Count(um => um.IsBuild)); }
public void DisbandUnitMoveCount() { Board board = Board.GetInitialBoard(); BoardMove moves1 = new BoardMove(); moves1.Add(board.GetMove("ven", "tyr")); moves1.Add(board.GetMove("vie", "boh")); moves1.FillHolds(board); board.ApplyMoves(moves1); var moves = BoardFutures.GetFallSpringUnitMoves(board); Assert.AreEqual(3, moves.Count(m => m.IsDisband)); }
public void ConvoyUnitMoveCount() { Board board = Board.GetInitialBoard(); BoardMove moves1 = new BoardMove(); moves1.Add(board.GetMove("edi", "nwg")); moves1.Add(board.GetMove("lon", "nth")); moves1.Add(board.GetMove("lvp", "yor")); moves1.FillHolds(board); board.ApplyMoves(moves1); var moves = BoardFutures.GetFallSpringUnitMoves(board); Assert.AreEqual(9, moves.Count(m => m.IsConvoy)); }
private static void GetWinterBoardMovesDisbandsOnlyRecursive(Board originalBoard, BoardMove workingBoardMove, IEnumerable <UnitMove> availableMoves, HashSet <BoardMove> completedBoardMoves, PowersDictionary <int> buildDisbandCounts, int minMoves) { if (workingBoardMove.Count == minMoves) { completedBoardMoves.Add(workingBoardMove.Clone()); return; } var moveGrouping = availableMoves.ToLookup(um => um.Unit.Power); Powers power = availableMoves.First().Unit.Power; IEnumerable <UnitMove> remainingMoves; foreach (UnitMove unitMove in moveGrouping[power]) { if (workingBoardMove.Count(um => um.Unit.Power == power) == Math.Abs(buildDisbandCounts[power])) { remainingMoves = availableMoves.Where(um => um.Unit.Power != power); } else { remainingMoves = availableMoves.Where(um => um != unitMove); } BoardMove newBoardMove = workingBoardMove.Clone(); newBoardMove.Add(unitMove); GetWinterBoardMovesDisbandsOnlyRecursive(originalBoard, newBoardMove, remainingMoves, completedBoardMoves, buildDisbandCounts, minMoves); } }
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); }
private static void GetWinterBoardMovesFullBuildsOnly(IEnumerable <UnitMove> availableMoves, List <BoardMove> buildBoardMoves, PowersDictionary <int> buildDisbandCounts) { var allPowersMoveCombos = new List <List <UnitMove> >(); int powerCount = 0; foreach (Powers currentPower in buildDisbandCounts.Where(kvp => kvp.Value > 0).Select(kvp => kvp.Key)) { powerCount++; int buildMovesForPower = buildDisbandCounts[currentPower]; int territoryBuildCount = availableMoves.Where(um => um.Unit.Power == currentPower).GroupBy(um => um.Edge.Target.Territory).Count(); int buildCount = Math.Min(buildMovesForPower, territoryBuildCount); List <List <UnitMove> > singlePowerMoveCombos; Helpers.GetAllCombinations(availableMoves.Where(um => um.Unit.Power == currentPower).ToList(), buildCount, out singlePowerMoveCombos); singlePowerMoveCombos.RemoveAll(ul => ul.GroupBy(um => um.Edge.Target.Territory).Count() != buildCount); allPowersMoveCombos.AddRange(singlePowerMoveCombos); } var boardMoveLists = new List <List <List <UnitMove> > >(); Helpers.GetAllCombinations(allPowersMoveCombos, powerCount, out boardMoveLists); boardMoveLists.RemoveAll(ll => ll.GroupBy(l2 => l2.First().Unit.Power).Count() < powerCount); foreach (List <List <UnitMove> > ll in boardMoveLists) { BoardMove workingBoardMove = new BoardMove(); foreach (UnitMove move in ll.SelectMany(l => l)) { if (!workingBoardMove.CurrentlyAllowsWinter(move, buildDisbandCounts[move.Unit.Power])) { throw new Exception($"Bad combination when building winter board move: {move}. {move.Unit.Power} allowed {buildDisbandCounts[move.Unit.Power]}"); } workingBoardMove.Add(move); } buildBoardMoves.Add(workingBoardMove); } }
public static IEnumerable <BoardMove> GetBoardMovesFallSpring(Board board, IEnumerable <MapNode> mapNodeSources) { if (board.Season is Winter) { throw new Exception($"Bad season {board.Season}"); } List <UnitMove> allUnitMoves = board.GetUnitMoves(); ILookup <MapNode, UnitMove> sourceNodeGroups = allUnitMoves.Where(um => mapNodeSources.Contains(um.Edge.Source)).ToLookup(um => um.Edge.Source); List <BoardMove> completedBoardMoves = new List <BoardMove>(); int depth = 0; foreach (UnitMove move in sourceNodeGroups.First()) { if (move.IsConvoy || move.IsDisband) { continue; } BoardMove workingBoardMove = new BoardMove(); workingBoardMove.Add(move); GetBoardMovesFallSpringRecursive(board, workingBoardMove, sourceNodeGroups, completedBoardMoves, depth + 1); } return(completedBoardMoves); }
public void ErrorNoUnit() { Board board = Board.GetInitialBoard(); BoardMove moves = new BoardMove(); // there is no unit in yor Helpers.AssertThrows <ArgumentException>(() => moves.Add(board.GetMove("yor", "nth"))); }
public void ErrorBadMapNode() { Board board = Board.GetInitialBoard(); BoardMove moves = new BoardMove(); // edu is not a mapnode Helpers.AssertThrows <ArgumentException>(() => moves.Add(board.GetMove("edu", "nth"))); }
public void ErrorBadPath() { Board board = Board.GetInitialBoard(); BoardMove moves = new BoardMove(); // edi <-> bla does not exist Helpers.AssertThrows <ArgumentException>(() => moves.Add(board.GetMove("edi", "bla"))); }
public void NoTerritorySwappingAllowed() { Board board = Board.GetInitialBoard(); BoardMove moves = new BoardMove(); UnitMove move1 = board.GetMove("tri", "ven"); UnitMove move2 = board.GetMove("ven", "tri"); Assert.IsTrue(moves.CurrentlyAllowsFallSpring(move1)); moves.Add(move1); Assert.IsFalse(moves.CurrentlyAllowsFallSpring(move2)); }
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 void PreConvoyUnitMove() { Board board = Board.GetInitialBoard(); BoardMove moves = new BoardMove(); moves.Add(board.GetMove("edi", "nth")); moves.FillHolds(board); board.ApplyMoves(moves); Map map = board.GetCurrentConvoyMap(); Assert.AreEqual(7, map.EdgeCount); Assert.AreEqual(94 - 18, map.VertexCount); }
public void BuildUnitMovesArmyNoNcSc() { 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 unitMoves = BoardFutures.GetWinterUnitMoves(board); Assert.IsFalse(unitMoves.Any(um => um.IsBuild && um.Unit.UnitType == UnitType.Army && um.Edge.Target.ShortName.Contains("_nc"))); }
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); }
public void GenerateWinterMovesAustriaOut1902() { Board board = Board.GetInitialBoard(); BoardMove moves = new BoardMove(); moves.Add(board.GetMove("mun", "boh")); moves.Add(board.GetMove("ven", "tri")); moves.Add(board.GetMove("vie", "tyr")); moves.Add(board.GetMove("bud", "gal")); moves.Add(board.GetMove("tri", "alb")); moves.Add(board.GetMove("rom", "ven")); moves.FillHolds(board); board.ApplyMoves(moves); board.EndTurn(); moves.Clear(); moves.Add(board.GetMove("ven", "tri")); moves.Add(board.GetMove("tri", "bud")); moves.Add(board.GetMove("boh", "vie")); moves.FillHolds(board); board.ApplyMoves(moves); board.EndTurn(); Assert.AreEqual(4, board.OwnedSupplyCenters[Powers.Germany].Count); Assert.AreEqual(4, board.OwnedSupplyCenters[Powers.Russia].Count); Assert.AreEqual(5, board.OwnedSupplyCenters[Powers.Italy].Count); Assert.AreEqual(0, board.OwnedSupplyCenters[Powers.Austria].Count); Assert.AreEqual(3, board.OwnedSupplyCenters[Powers.Turkey].Count); Assert.AreEqual(3, board.OwnedSupplyCenters[Powers.England].Count); Assert.AreEqual(3, board.OwnedSupplyCenters[Powers.France].Count); var boardMoves = BoardFutures.GetAllBoardMovesWinter(board); Assert.IsTrue(boardMoves.All(bm => null != bm.FirstOrDefault(um => um.Edge.Target == MapNodes.Get("mun")))); Assert.IsTrue(boardMoves.All(bm => bm.Where(um => um.Unit.Power == Powers.Austria).All(um => um.IsDisband))); Assert.AreEqual(4, boardMoves.Count()); }
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; }
private static void GetBoardMovesFallSpringRecursive(Board originalBoard, BoardMove workingBoardMove, ILookup <MapNode, UnitMove> sourceNodeGroups, List <BoardMove> completedBoardMoves, int depth) { if (workingBoardMove.Count == sourceNodeGroups.Count) { completedBoardMoves.Add(workingBoardMove.Clone()); return; } MapNode node = sourceNodeGroups.First(n => !workingBoardMove.Sources.Contains(n.Key)).Key; foreach (UnitMove move in sourceNodeGroups[node]) { if (workingBoardMove.CurrentlyAllowsFallSpring(move)) { workingBoardMove.Add(move); GetBoardMovesFallSpringRecursive(originalBoard, workingBoardMove, sourceNodeGroups, completedBoardMoves, depth + 1); workingBoardMove.Remove(move); } } }
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 }); }
private void SetupBoard() { initialBoard = Board.GetInitialBoard(); //1901 Spring BoardMove moves = new BoardMove(); moves.Add(initialBoard.GetMove("bud", "ser")); moves.Add(initialBoard.GetMove("edi", "nth")); moves.Add(initialBoard.GetMove("lvp", "wal")); moves.Add(initialBoard.GetMove("mar", "spa")); moves.Add(initialBoard.GetMove("par", "bur")); moves.Add(initialBoard.GetMove("ber", "kie")); moves.Add(initialBoard.GetMove("kie", "den")); moves.Add(initialBoard.GetMove("mun", "ruh")); moves.Add(initialBoard.GetMove("nap", "ion")); moves.Add(initialBoard.GetMove("rom", "apu")); //A Ven H ? SUCCEEDS moves.Add(initialBoard.GetMove("mos", "stp")); moves.Add(initialBoard.GetMove("sev", "rum")); moves.Add(initialBoard.GetMove("stp_sc", "fin")); moves.Add(initialBoard.GetMove("war", "lvn")); moves.Add(initialBoard.GetMove("ank", "con")); moves.Add(initialBoard.GetMove("con", "bul")); //A Smy H ? SUCCEEDS moves.FillHolds(initialBoard); initialBoard.ApplyMoves(moves, true); initialBoard.EndTurn(); //1901 Fall moves = new BoardMove(); moves.Add(initialBoard.GetMove("bul", "gre")); moves.Add(initialBoard.GetMove("tri", "adr")); moves.Add(initialBoard.GetMove("vie", "tri")); moves.Add(initialBoard.GetMove("lon", "nth")); moves.Add(initialBoard.GetMove("nth", "nwg")); moves.Add(initialBoard.GetMove("wal", "yor")); moves.Add(initialBoard.GetMove("bre", "mao")); moves.Add(initialBoard.GetMove("bur", "bel")); //A Spa H ? SUCCEEDS moves.Add(initialBoard.GetMove("den", "swe")); moves.Add(initialBoard.GetMove("kie", "mun")); moves.Add(initialBoard.GetMove("ruh", "hol")); moves.Add(initialBoard.GetConvoyMove("apu", "tun", "ion")); //A Ven H ? SUCCEEDS moves.Add(initialBoard.GetMove("fin", "bot")); //A Lvn H ? SUCCEEDS //F Rum H ? SUCCEEDS moves.Add(initialBoard.GetMove("stp", "nwy")); moves.Add(initialBoard.GetMove("con", "bul_sc")); moves.Add(initialBoard.GetMove("smy", "ank")); moves.FillHolds(initialBoard); initialBoard.ApplyMoves(moves, true); initialBoard.EndTurn(); // 1901 Winter moves = new BoardMove(); moves.Add(initialBoard.GetBuildMove("vie", UnitType.Army)); moves.Add(initialBoard.GetBuildMove("bre", UnitType.Fleet)); moves.Add(initialBoard.GetBuildMove("mar", UnitType.Fleet)); moves.Add(initialBoard.GetBuildMove("ber", UnitType.Fleet)); moves.Add(initialBoard.GetBuildMove("kie", UnitType.Fleet)); moves.Add(initialBoard.GetBuildMove("nap", UnitType.Fleet)); moves.Add(initialBoard.GetBuildMove("mos", UnitType.Army)); moves.Add(initialBoard.GetBuildMove("stp_nc", UnitType.Fleet)); moves.Add(initialBoard.GetBuildMove("smy", UnitType.Fleet)); moves.Add(initialBoard.GetBuildMove("con", UnitType.Fleet)); moves.FillHolds(initialBoard); initialBoard.ApplyMoves(moves, true); initialBoard.EndTurn(); }
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); }
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 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); }
public void GenerateWinterMovesCorrectNumberOfBuildsPerPower() { 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(); Assert.AreEqual(6, board.OwnedSupplyCenters[Powers.Germany].Count); Assert.AreEqual(6, board.OwnedSupplyCenters[Powers.Russia].Count); Assert.AreEqual(4, board.OwnedSupplyCenters[Powers.Italy].Count); Assert.AreEqual(5, board.OwnedSupplyCenters[Powers.Austria].Count); Assert.AreEqual(5, board.OwnedSupplyCenters[Powers.Turkey].Count); Assert.AreEqual(3, board.OwnedSupplyCenters[Powers.England].Count); Assert.AreEqual(5, board.OwnedSupplyCenters[Powers.France].Count); var boardMoves = BoardFutures.GetAllBoardMovesWinter(board); Assert.IsTrue(boardMoves.All(bm => bm.Count(um => um.Unit.Power == Powers.Germany) == 6)); Assert.IsTrue(boardMoves.All(bm => bm.Count(um => um.Unit.Power == Powers.Russia) == 6)); Assert.IsTrue(boardMoves.All(bm => bm.Count(um => um.Unit.Power == Powers.Italy) == 4)); Assert.IsTrue(boardMoves.All(bm => bm.Count(um => um.Unit.Power == Powers.Austria) == 5)); Assert.IsTrue(boardMoves.All(bm => bm.Count(um => um.Unit.Power == Powers.Turkey) == 5)); Assert.IsTrue(boardMoves.All(bm => bm.Count(um => um.Unit.Power == Powers.England) == 3)); Assert.IsTrue(boardMoves.All(bm => bm.Count(um => um.Unit.Power == Powers.France) == 5)); //this is the total for when empty builds are included //Assert.AreEqual(1944, boardMoves.Count()); }