示例#1
0
 public BucketActionStep(string strategyName, Bucket actedOn, BucketActions actionTaken, int stepNumber, int amount, string description, ProblemState state)
 {
     StrategyName = strategyName;
     ActedOn = actedOn;
     ActionTaken = actionTaken;
     StepNumber = stepNumber;
     Amount = amount;
     Description = description;
     EndingState = state;
 }
示例#2
0
 public bool SameBucketState(ProblemState other)
 {
     var states = (from b in BucketState
                   join bo in other.BucketState on new { b.Name, b.Capacity } equals new { bo.Name, bo.Capacity } into otherStates
                   from o in otherStates.DefaultIfEmpty()
                   select new { mine = b, theirs = o })
                  .Union(
                   from o in other.BucketState
                   join bm in BucketState on new { o.Name, o.Capacity } equals new { bm.Name, bm.Capacity } into myStates
                   from b in myStates.DefaultIfEmpty()
                   select new { mine = b, theirs = o }
                  );
     foreach (var compare in states)
     {
         if ((compare.mine == null) || (compare.theirs == null))
             return false;
         if (compare.mine.CurrentFill != compare.theirs.CurrentFill)
             return false;
     }
     return true;
 }
示例#3
0
 public static ProblemState GetFromBytes(byte[] data, ref int offset, Encoding textEncoding = null)
 {
     ProblemState ps = new ProblemState();
     offset = ps.FromBytes(data, offset, textEncoding);
     return ps;
 }
 public override BucketActionStep TakeAction()
 {
     int amountInAction = 0;
     _state = null;
     _stepsTaken++;
     if (To.IsFull)
     {
         amountInAction = To.Empty(WaterSource);
         return new BucketActionStep(this.StrategyName, To, BucketActions.Empty, _stepsTaken, amountInAction, "Empty " + To.Name + " of " + amountInAction, CurrentProblemState);
     }
     else if (From.IsEmpty)
     {
         amountInAction = From.Fill(WaterSource);
         return new BucketActionStep(this.StrategyName, From, BucketActions.Fill, _stepsTaken, amountInAction, "Fill " + From.Name + " with " + amountInAction, CurrentProblemState);
     }
     amountInAction = From.TransferTo(To);
     return new BucketActionStep(this.StrategyName, From, BucketActions.Transfer, _stepsTaken, amountInAction, "Transfer " + amountInAction + " from " + From.Name + " to " + To.Name, CurrentProblemState);
 }