Esempio n. 1
0
        /// <summary>
        /// Be careful using this constructor, it's intended to be used internally.
        /// </summary>
        /// <param name="parentState"></param>
        /// <param name="actionToTake"></param>
        private StateOfBottles(StateOfBottles parentState, ValidActions actionToTake)
        {
            //TODO: Verify if simply FiveLiterBottle = ParentState.FiveLiterBottle is a copy or a reference
            //For now we play safe and copy manually
            FiveLiterBottle  = new Bottle(parentState.FiveLiterBottle);
            ThreeLiterBottle = new Bottle(parentState.ThreeLiterBottle);

            this.ParentState = parentState;

            ActionTaken = actionToTake;

            ActionsTaken = parentState.ActionsTaken + 1;
            switch (actionToTake)
            {
            case ValidActions.Fill5:
                FiveLiterBottle.Fill();
                break;

            case ValidActions.Fill3:
                ThreeLiterBottle.Fill();
                break;

            case ValidActions.Empty5:
                FiveLiterBottle.Empty();
                break;

            case ValidActions.Empty3:
                ThreeLiterBottle.Empty();
                break;

            case ValidActions.Pour5To3:
                ThreeLiterBottle.AddToVolumeFromThisBottle(FiveLiterBottle);
                break;

            case ValidActions.Pour3To5:
                FiveLiterBottle.AddToVolumeFromThisBottle(ThreeLiterBottle);
                break;

            default:
                throw new ArgumentOutOfRangeException(nameof(actionToTake), actionToTake, null);
            }
        }
Esempio n. 2
0
 public StateOfBottles()
 {
     FiveLiterBottle  = new Bottle(5);
     ThreeLiterBottle = new Bottle(3);
 }