Esempio n. 1
0
        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);
            }
        }
Esempio n. 2
0
        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
            });
        }