Example #1
0
        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);
        }
Example #2
0
        public static IEnumerable <BoardMove> GetAllBoardMovesWinter(Board board)
        {
            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 disbandBoardMoves   = new HashSet <BoardMove>();
            var buildBoardMoves     = new List <BoardMove>();
            var completedBoardMoves = new List <BoardMove>();
            PowersDictionary <int> buildDisbandCounts = board.GetSupplyCenterToUnitDifferences();
            int       disbandCount     = buildDisbandCounts.Where(kvp => kvp.Value < 0).Sum(kvp => Math.Abs(kvp.Value));
            int       buildCount       = buildDisbandCounts.Where(kvp => kvp.Value > 0).Sum(kvp => kvp.Value);
            int       maxMoves         = disbandCount + buildCount;
            BoardMove workingBoardMove = new BoardMove();

            if (winterUnitMoves.Any(um => um.IsDisband))
            {
                GetWinterBoardMovesDisbandsOnlyRecursive(board, workingBoardMove, winterUnitMoves.Where(um => um.IsDisband), disbandBoardMoves, buildDisbandCounts, disbandCount);
            }

            if (winterUnitMoves.Any(um => um.IsBuild))
            {
                // this does not enumerate winter moves that refrain from building.
                // But I really don't care that much.  It's very rare to *not* build when one is available
                GetWinterBoardMovesFullBuildsOnly(winterUnitMoves.Where(um => um.IsBuild), buildBoardMoves, buildDisbandCounts);
            }

            if (disbandBoardMoves.Any() && buildBoardMoves.Any())
            {
                foreach (BoardMove disbandBoardMove in disbandBoardMoves)
                {
                    foreach (BoardMove buildBoardMove in buildBoardMoves)
                    {
                        BoardMove combinedMove = buildBoardMove.Clone();
                        combinedMove.AddRange(disbandBoardMove);
                        completedBoardMoves.Add(combinedMove);
                    }
                }
            }
            else
            {
                foreach (BoardMove buildBoardMove in buildBoardMoves)
                {
                    completedBoardMoves.Add(buildBoardMove);
                }
                foreach (BoardMove disbandBoardMove in disbandBoardMoves)
                {
                    completedBoardMoves.Add(disbandBoardMove);
                }
            }

            foreach (BoardMove boardMove in completedBoardMoves)
            {
                boardMove.FillHolds(board);
            }
            return(completedBoardMoves);
        }