Ejemplo n.º 1
0
        private static void SetMartianBowlingFrameConstraints(Bowling martianBowling)
        {
            Constraint upToThreeRollsUnlessDropTenEarlier =
                x => ((x.Rolls.Count == 3 && x.Rolls.Sum() <= 10) || (x.Rolls.Count < 3 && x.Rolls.Sum() == 10));

            ConstraintAndDescription upToThreeRollsUnlessDropTenEarlierD =
                new ConstraintAndDescription("up to three rolls unless drop ten earlier",upToThreeRollsUnlessDropTenEarlier);

            martianBowling.SetConstraintForFrame(upToThreeRollsUnlessDropTenEarlierD,0);
            martianBowling.SetConstraintForFrame(upToThreeRollsUnlessDropTenEarlierD,1);
            martianBowling.SetConstraintForFrame(upToThreeRollsUnlessDropTenEarlierD,2);
        }
 public GeometricConstraintChecker(ConstraintAndDescription constToAdd)
 {
     this._constToAdd = constToAdd;
 }
Ejemplo n.º 3
0
        private static void SetTerrestrialBowlingFrameConstraints(Bowling terrestrialBowling)
        {
            Constraint sumOfAllRollMustbeLessThanTen = (x => x.Rolls.Sum() <= 10);
            Constraint ifFirstRollIsTenThanTheFrameIsOver = (x => (!(x.Rolls[0] == 10) || x.Rolls.Count == 1));
            Constraint ifFirstRollIsLessThanTenThenThereIsAnotherRollInTheFrame =
                (x => (!(x.Rolls[0] < 10) || x.Rolls.Count == 2));

            Constraint plainFrameConstraint =
                            (x =>
                             (sumOfAllRollMustbeLessThanTen(x) &&
                              (ifFirstRollIsTenThanTheFrameIsOver(x) &&
                              ifFirstRollIsLessThanTenThenThereIsAnotherRollInTheFrame(x))));

            ConstraintAndDescription plainFrameConstraintD =
                new ConstraintAndDescription("sum of all roll must be less or equals to ten AND "+
                    "(frame with strike has only one roll OR frame with no strike has two rolls)", plainFrameConstraint);

            for (int i = 0; i < 9; i++)
            {
                terrestrialBowling.SetConstraintForFrame(plainFrameConstraintD,i);
            }

            Constraint sumRollsNoHigherThanThirty = x => x.Rolls.Sum() <= 30;
            Constraint ifFirstRollIsTenThanThereIsAtLeastAnotherRoll = x => !(x.Rolls[0]==10)||x.Rolls.Count > 1;

            Constraint ifSecondRollIsTenThenThereIsAnotherRoll =
                x => (!(x.Rolls.Count > 1 && x.Rolls[1] == 10) || x.Rolls.Count == 3);

            Constraint noHigherThanThirtyAndAllowMoreRollsIfNoStrike =
                x => (sumRollsNoHigherThanThirty(x) &&
                    ifFirstRollIsTenThanThereIsAtLeastAnotherRoll(x)&&
                    ifSecondRollIsTenThenThereIsAnotherRoll(x));

            ConstraintAndDescription noHigherThanThirtyAndAllowMoreRollsIfNoStrikeD = new ConstraintAndDescription("noHigherThanThirtyAndAllowMoreRollsIfNoStrike", noHigherThanThirtyAndAllowMoreRollsIfNoStrike);

            terrestrialBowling.SetConstraintForFrame(noHigherThanThirtyAndAllowMoreRollsIfNoStrikeD,9);
        }
Ejemplo n.º 4
0
 public void SetConstraintForFrame(ConstraintAndDescription constraint, int frameIndex)
 {
     indexConstraintForFrame.Add(frameIndex,constraint);
 }
Ejemplo n.º 5
0
 public void SetUp()
 {
     geometricBowling = new Bowling();
     Constraint geometricConstraint = x => geoConstraint(x);
     ConstraintAndDescription frameOver = new ConstraintAndDescription("over", geometricConstraint);
     geometricBowling.SetConstraintForFrame(frameOver,0);
     geometricBowling.SetConstraintChecker(new GeometricConstraintChecker(frameOver));
 }