예제 #1
0
        public bool CurrentlyAllowsFallSpring(UnitMove move)
        {
            // does not check pre-conditions like "is the proper unit in the edge.source"
            // we rely on the UnitMove generator to check these and only generate valid possible moves
            // this is only checking the given move is valid based on all other moves in this set

            if (move.IsHold)
            {
                return(!TargetTerritories.Contains(move.Edge.Source.Territory));
            }
            else if (move.IsDisband)
            {
                bool otherPowerMovingIn = this.Where(u => u.Unit.Power != move.Unit.Power)
                                          .Select(u => u.Edge.Target?.Territory)
                                          .Contains(move.Edge.Source.Territory);
                IEnumerable <MapNode> adjacentMapNodes = move.Unit.MyMap.AdjacentInEdges(move.Edge.Source).Select(e => e.Source);
                bool otherPowerHoldingAdjacent         = Holds.Where(u => u.Unit.Power != move.Unit.Power)
                                                         .Select(u => u.Edge.Source)
                                                         .Intersect(adjacentMapNodes)
                                                         .Any();
                return(otherPowerHoldingAdjacent && otherPowerMovingIn);
            }
            else if (move.IsConvoy)
            {
                bool necessaryFleetsHolding = move.ConvoyRoute.All(mn => Holds.Select(um => um.Edge.Target).Contains(mn));
                bool targetTerritoryEmpty   = !TargetTerritories.Contains(move.Edge.Target.Territory);
                return(necessaryFleetsHolding && targetTerritoryEmpty);
            }
            else
            {
                bool targetTerritoryEmpty = !TargetTerritories.Contains(move.Edge.Target.Territory);
                bool noSwap = !this.Any(um => um.Edge.Source.Territory == move.Edge.Target.Territory && um.Edge.Target.Territory == move.Edge.Source.Territory);
                return(targetTerritoryEmpty && noSwap);
            }
        }
        public IEnumerable <ValidationResult> Validate(ValidationContext validationContext)
        {
            if (string.IsNullOrWhiteSpace(Name))
            {
                yield return(new ValidationResult("Name cannot be empty or whitespace."));
            }

            if (DateSet > DateTimeOffset.Now)
            {
                yield return(new ValidationResult("Date set cannot be in the future."));
            }

            if (TechGradeId == null && BGradeId == null && PoveyGradeId == null && FurlongGradeId == null)
            {
                yield return(new ValidationResult("Must include at least one grade."));
            }

            if (Holds == null || !Holds.Any())
            {
                yield return(new ValidationResult("Must include at least 1 hold."));
            }

            foreach (var error in Holds.SelectMany(hold => hold.Validate(validationContext)))
            {
                yield return(error);
            }

            if (NewRules != null)
            {
                foreach (var error in NewRules.SelectMany(rule => rule.Validate(validationContext)))
                {
                    yield return(error);
                }
            }

            if (ExistingRuleIds?.Any(ruleId => ruleId <= 0) ?? false)
            {
                yield return(new ValidationResult("Existing rule IDs must be positive integers."));
            }

            if (StyleSymbolIds?.Any(styleSymbolId => styleSymbolId <= 0) ?? false)
            {
                yield return(new ValidationResult("Style symbol IDs must be positive integers."));
            }

            if (Holds != null)
            {
                var standingStartHolds = Holds.Where(hold => hold.IsStandingStartHold);
                if (standingStartHolds.Any())
                {
                    bool reachedEndOfStandingStartHolds = false;
                    for (int i = 0; i < Holds.Count(); i++)
                    {
                        var hold = Holds[i];
                        if (hold.IsStandingStartHold)
                        {
                            if (reachedEndOfStandingStartHolds)
                            {
                                yield return(new ValidationResult("Cannot have a standing start hold after a normal hold."));

                                break;
                            }
                        }
                        else
                        {
                            reachedEndOfStandingStartHolds = true;
                        }
                    }
                }
            }
        }