Пример #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);
            }
        }
Пример #2
0
 public bool CurrentlyAllowsWinter(UnitMove move, int delta)
 {
     if (move.IsBuild)
     {
         if (TargetTerritories.Contains(move.Edge.Target.Territory))
         {
             return(false);
         }
         if (this.Count(um => um.Unit.Power == move.Unit.Power) == Math.Abs(delta))
         {
             return(false);
         }
         return(true);
     }
     else if (move.IsDisband)
     {
         if (SourceTerritories.Contains(move.Edge.Source.Territory))
         {
             return(false);
         }
         if (this.Count(um => um.Unit.Power == move.Unit.Power) == Math.Abs(delta))
         {
             return(false);
         }
         return(true);
     }
     else
     {
         return(false);
     }
 }