Ejemplo 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);
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// <paramref name="srcSquare"/>の駒を<paramref name="dstSquare"/>
        /// に動かすことが可能な指し手をすべて列挙します。
        /// </summary>
        private IEnumerable<BoardMove> GetAvailableMove(BWType bwType,
                                                        Square srcSquare,
                                                        Square dstSquare)
        {
            var piece = this[srcSquare];
            if (piece == null || piece.BWType != bwType)
            {
                yield break;
            }

            var move = new BoardMove()
            {
                DstSquare = dstSquare,
                SrcSquare = srcSquare,
                MovePiece = piece.Piece,
                BWType = bwType,
            };

            // 成り駒でなければ、成る可能性があります。
            if (!piece.IsPromoted)
            {
                move.IsPromote = true;
                if (CanMove(move, MoveFlags.CheckOnly))
                {
                    // yield returnなのでCloneしないとまずい。
                    yield return move.Clone();
                }
            }

            move.IsPromote = false;
            if (CanMove(move, MoveFlags.CheckOnly))
            {
                yield return move;
            }
        }
Ejemplo n.º 3
0
 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;
 }
Ejemplo n.º 4
0
        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);
                }
            }
        }