public void TestOneMissingWater()
        {
            var game = (new GameFactory()).GenerateEmptyGame(3, 4);

            game.Grid[new GridPoint(2, 3)]            = BimaruValue.SHIP_UNDETERMINED;
            game.TargetNumberOfShipFieldsPerRow[0]    = 2;
            game.TargetNumberOfShipFieldsPerRow[1]    = 2;
            game.TargetNumberOfShipFieldsPerRow[2]    = 3;
            game.TargetNumberOfShipFieldsPerColumn[0] = 0;
            game.TargetNumberOfShipFieldsPerColumn[1] = 3;
            game.TargetNumberOfShipFieldsPerColumn[2] = 3;
            game.TargetNumberOfShipFieldsPerColumn[3] = 1;

            //   0331
            //   ----
            // 3|???S
            // 2|????
            // 2|????
            // => The only row or column with one missing WATER or ship
            //    is row 2 with one missing WATER.

            var rule = new OneMissingShipOrWater(null);

            var changesExpected = new FieldsToChange <BimaruValue>()
            {
                { new GridPoint(2, 0), BimaruValue.WATER },
                { new GridPoint(2, 1), BimaruValue.WATER },
                { new GridPoint(2, 2), BimaruValue.WATER },
            };

            AssertEqualTrialChanges(changesExpected, rule.GetChangeTrials(game));
        }
        public void TestFullyDeterminedWithFallback()
        {
            var game = (new GameFactory()).GenerateEmptyGame(1, 1);

            game.Grid[new GridPoint(0, 0)] = BimaruValue.SHIP_MIDDLE;
            var rule = new OneMissingShipOrWater(new BruteForce());

            Assert.AreEqual(0, rule.GetChangeTrials(game).Count());
        }
        public void TestFullyDeterminedWithoutFallback()
        {
            var game = (new GameFactory()).GenerateEmptyGame(1, 1);

            game.Grid[new GridPoint(0, 0)] = BimaruValue.SHIP_MIDDLE;
            var rule = new OneMissingShipOrWater(null);

            Assert.ThrowsException <InvalidOperationException>(() => rule.GetChangeTrials(game).Count());
        }
Ejemplo n.º 4
0
        private ITrialAndErrorRule GetTrialRule(bool shallCountSolutions)
        {
            ITrialAndErrorRule trialRule;

            if (shallCountSolutions)
            {
                trialRule = new OneMissingShipOrWater(new BruteForce());
            }
            else
            {
                trialRule = new LongestMissingShip();
            }

            return(trialRule);
        }
        public void TestNeverOneMissing()
        {
            var game = (new GameFactory()).GenerateEmptyGame(2, 4);

            game.TargetNumberOfShipFieldsPerRow[0]    = 2;
            game.TargetNumberOfShipFieldsPerRow[1]    = 2;
            game.TargetNumberOfShipFieldsPerColumn[0] = 2;
            game.TargetNumberOfShipFieldsPerColumn[1] = 0;
            game.TargetNumberOfShipFieldsPerColumn[2] = 0;
            game.TargetNumberOfShipFieldsPerColumn[3] = 2;

            //   2002
            //   ----
            // 2|????
            // 2|????
            // => No row or column with one missing WATER or ship.

            var rule = new OneMissingShipOrWater(null);

            // No fall-back rule but fall-back rule is needed.
            Assert.ThrowsException <InvalidOperationException>(() => rule.GetChangeTrials(game));

            // Check fall-back rule is called
            var counter = new CountTrialCalls();

            rule = new OneMissingShipOrWater(counter);

            int numTrials = 0;

            foreach (var changes in rule.GetChangeTrials(game))
            {
                Assert.IsNull(changes);
                numTrials++;
            }

            Assert.AreEqual(1, numTrials);
            Assert.AreEqual(1, counter.NumberOfTrialCalls);
        }