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