public void Update_UpdatesSpecifiedCoordinate() { var puzzle = new PuzzleWithPossibleValues(new int?[][] { new int?[] { 1, null /* 4 */, null /* 3 */, 2 }, new int?[] { null /* 2 */, null /* 3 */, 1, null /* 4 */ }, new int?[] { null /* 4 */, null /* 1 */, null /* 2 */, null /* 3 */ }, new int?[] { 3, 2, 4, 1 } }); var rule = new StandardRules(); Assert.True(rule.TryInit(puzzle, puzzle.UniquePossibleValues)); var coordTracker = new CoordinateTracker(puzzle.Size); var coord = new Coordinate(1, 1); int val = 3; rule.Update(coord, val, coordTracker); Assert.Equal( new HashSet <Coordinate> { new Coordinate(1, 0), new Coordinate(1, 3), new Coordinate(0, 1), new Coordinate(2, 1) }, new HashSet <Coordinate>(coordTracker.TrackedCoords.ToArray())); Assert.Equal(new BitVector(0b10000), rule.GetPossibleValues(new Coordinate(0, 1))); Assert.Equal(new BitVector(0b10100), rule.GetPossibleValues(new Coordinate(1, 0))); Assert.Equal(new BitVector(0b10000), rule.GetPossibleValues(new Coordinate(1, 3))); Assert.Equal(new BitVector(0b10010), rule.GetPossibleValues(new Coordinate(2, 1))); }
// If no business rules are specified by the user we default to the standard rules public string GetSummaryReport() { var values = FlightParameterCalculator.GetFlightParameterValues(ScheduledFlightDetails); var businessRules = new StandardRules(values); return(GetSummaryReport(businessRules)); }
public void Revert_RevertsSpecifiedCoordinate() { var puzzle = new Puzzle(new int?[, ] { { 1, null /* 4 */, null /* 3 */, 2 }, { null /* 2 */, null /* 3 */, 1, null /* 4 */ }, { null /* 4 */, null /* 1 */, null /* 2 */, null /* 3 */ }, { 3, 2, 4, 1 } }); var rule = new StandardRules(puzzle, _GetAllPossibleValues(puzzle.Size)); BitVector[,] initialPossibleValues = _GetPossibleValues(puzzle.Size, rule); var updatedCoordTracker = new CoordinateTracker(puzzle.Size); var coord = new Coordinate(1, 1); int val = 3; rule.Update(coord, val, updatedCoordTracker); var revertedCoordTracker = new CoordinateTracker(puzzle.Size); rule.Revert(coord, val, revertedCoordTracker); Assert.Equal( updatedCoordTracker.GetTrackedCoords().ToArray(), revertedCoordTracker.GetTrackedCoords().ToArray()); for (int row = 0; row < puzzle.Size; row++) { for (int column = 0; column < puzzle.Size; column++) { Assert.Equal( initialPossibleValues[row, column], rule.GetPossibleValues(new Coordinate(row, column))); } } }
internal bool IsWhitelistedLandblock(ushort landblock) { if (StandardRules.GetProperty(RealmPropertyBool.IsDuelingRealm)) { return(RealmConstants.DuelLandblocks.Contains(landblock)); } return(true); }
internal uint GetDefaultInstanceID(Player player) { if (RealmManager.TryParseReservedRealm(Realm.Id, out var r)) { switch (r) { default: return(ACE.Entity.Position.InstanceIDFromVars(Realm.Id, (ushort)player.Account.AccountId, false)); } } return(StandardRules.GetDefaultInstanceID()); }
public void TryInitFor_WithDuplicateValueInRow_Fails() { var puzzle = new PuzzleWithPossibleValues(new int?[][] { new int?[] { 1, null /* 4 */, null /* 3 */, 2 }, new int?[] { null /* 2 */, 3, 3, null /* 4 */ }, new int?[] { null /* 4 */, null /* 1 */, null /* 2 */, null /* 3 */ }, new int?[] { 3, 2, 4, 1 } }); var rule = new StandardRules(); Assert.False(rule.TryInit(puzzle, puzzle.UniquePossibleValues)); }
public bool SudokuSpiceDynamicSingle(PuzzleSample puzzle) { var p = new PuzzleWithPossibleValues(puzzle.NullableJaggedMatrix); var standardRules = new StandardRules(); var ruleKeeper = new DynamicRuleKeeper( new IRule[] { standardRules }); var heuristic = new StandardHeuristic( standardRules, standardRules, standardRules); var solver = new RuleBased.PuzzleSolver <PuzzleWithPossibleValues>(ruleKeeper, heuristic); var result = solver.Solve(p, randomizeGuesses: true); return(result.NumEmptySquares == 0); }
private BitVector[,] _GetPossibleValues(int puzzleSize, StandardRules rule) { var possibleValues = new BitVector[puzzleSize, puzzleSize]; for (int row = 0; row < puzzleSize; row++) { for (int column = 0; column < puzzleSize; column++) { possibleValues[row, column] = rule.GetPossibleValues(new Coordinate(row, column)); } } return(possibleValues); }
internal Position DefaultStartingLocation(Player player) { if (StandardRules.GetProperty(RealmPropertyBool.IsDuelingRealm)) { //Adventurer's Haven //0x01AC0118[29.684622 - 30.072382 0.010000] - 0.027857 0.999612 0.000000 0.000000 return(DuelRealmHelpers.GetDuelingAreaDrop(this)); } else { //Holtburg return(new Position(0xA9B40019, 84f, 7.1f, 94.005005f, 0f, 0f, -0.078459f, 0.996917f, GetDefaultInstanceID(player))); } }
public void Setup() { _board = new Mock<IBasicBoard>(); //0000000 //0111110 //0121210 //0111110 //0121110 //0111110 //0000000 var testBoard = new List<IBasicPolygon>(); for (int x = 0; x < 7; x++) { for (int y = 0; y < 7; y++) { if (y == 0 || y == 6 || x == 0 || x == 6) { var solid = new BasicPolygon(); solid.State = PolygonState.Solid; solid.Coordintes = new Point3d() { X = x, Y = y }; testBoard.Add(solid); } else { var empty = new BasicPolygon(); empty.State = PolygonState.Empty; empty.Coordintes = new Point3d() { X = x, Y = y }; testBoard.Add(empty); } } } var cellToFill = testBoard.Where(c => c.Coordintes.X == 2 && c.Coordintes.Y == 2).First(); cellToFill.State = PolygonState.Filled; cellToFill = testBoard.Where(c => c.Coordintes.X == 4 && c.Coordintes.Y == 4).First(); cellToFill.State = PolygonState.Filled; cellToFill = testBoard.Where(c => c.Coordintes.X == 2 && c.Coordintes.Y == 4).First(); cellToFill.State = PolygonState.Filled; _board.SetupGet(b => b.Cells).Returns(testBoard); _game = new Mock<ILonerGame>(); _game.SetupGet(g => g.Board).Returns(_board.Object); _rules = new StandardRules(); _rules.Game = _game.Object; }
public void Rules_WhenAccessed_ReturnsObjectPassedToConstructor() { // arrange var rules = new StandardRules(); var game = new TestGame(rules); // act var property = game.Rules; // assert Assert.AreSame( expected: rules, actual: property, message: "Wrong rules reference returned by property."); }
public void Constructor_WithDuplicateValueInRow_Throws() { ArgumentException ex = Assert.Throws <ArgumentException>(() => { var rule = new StandardRules( new Puzzle(new int?[, ] { { 1, null /* 4 */, null /* 3 */, 2 }, { null /* 2 */, 3, 3, null /* 4 */ }, { null /* 4 */, null /* 1 */, null /* 2 */, null /* 3 */ }, { 3, 2, 4, 1 } }), BitVector.CreateWithSize(4)); }); Assert.Contains("Puzzle does not satisfy rule", ex.Message); }
public bool SudokuSpiceDynamicSingle(PuzzleSample puzzle) { var p = new Puzzle(puzzle.NullableMatrix); var possibleValues = new PossibleValues(p); var standardRules = new StandardRules(p, possibleValues.AllPossible); var ruleKeeper = new DynamicRuleKeeper( p, possibleValues, new List <ISudokuRule> { standardRules }); var heuristic = new StandardHeuristic( p, possibleValues, standardRules, standardRules, standardRules); var solver = new PuzzleSolver(p, possibleValues, ruleKeeper, heuristic); solver.SolveRandomly(); return(p.NumEmptySquares == 0); }
/// <summary> /// Builds a new rule object. /// </summary> /// <param name="ruleType">The type of rules to build.</param> /// <returns>A newly instantiated rule.</returns> public static RulesBase Build(Rule ruleType) { RulesBase rules = null; switch (ruleType) { case Rule.Sierpinskish: rules = new SierpinskishRules(); break; default: rules = new StandardRules(); break; } return(rules); }
public void Constructor_FiltersCorrectly() { var puzzle = new Puzzle(new int?[, ] { { 1, null /* 4 */, null /* 3 */, 2 }, { null /* 2 */, null /* 3 */, 1, null /* 4 */ }, { null /* 4 */, null /* 1 */, null /* 2 */, null /* 3 */ }, { 3, 2, 4, 1 } }); var rule = new StandardRules(puzzle, _GetAllPossibleValues(puzzle.Size)); Assert.Equal(new BitVector(0b11000), rule.GetPossibleValues(new Coordinate(0, 1))); Assert.Equal(new BitVector(0b01000), rule.GetPossibleValues(new Coordinate(0, 2))); Assert.Equal(new BitVector(0b10100), rule.GetPossibleValues(new Coordinate(1, 0))); Assert.Equal(new BitVector(0b11000), rule.GetPossibleValues(new Coordinate(1, 1))); Assert.Equal(new BitVector(0b11000), rule.GetPossibleValues(new Coordinate(1, 3))); Assert.Equal(new BitVector(0b10000), rule.GetPossibleValues(new Coordinate(2, 0))); Assert.Equal(new BitVector(0b10010), rule.GetPossibleValues(new Coordinate(2, 1))); Assert.Equal(new BitVector(0b01100), rule.GetPossibleValues(new Coordinate(2, 2))); Assert.Equal(new BitVector(0b01000), rule.GetPossibleValues(new Coordinate(2, 3))); }
public void CopyWithNewReference_CreatesDeepCopy() { var puzzle = new PuzzleWithPossibleValues(new int?[][] { new int?[] { 1, null /* 4 */, null /* 3 */, 2 }, new int?[] { null /* 2 */, null /* 3 */, 1, null /* 4 */ }, new int?[] { null /* 4 */, null /* 1 */, null /* 2 */, null /* 3 */ }, new int?[] { 3, 2, 4, 1 } }); var rule = new StandardRules(); Assert.True(rule.TryInit(puzzle, puzzle.UniquePossibleValues)); var puzzleCopy = new PuzzleWithPossibleValues(puzzle); IRule ruleCopy = rule.CopyWithNewReference(puzzleCopy); int val = 3; var coord = new Coordinate(1, 1); ruleCopy.Update(coord, val, new CoordinateTracker(puzzle.Size)); Assert.NotEqual(rule.GetPossibleValues(coord), ruleCopy.GetPossibleValues(coord)); puzzleCopy[coord] = val; var secondCoord = new Coordinate(0, 1); int secondVal = 4; var coordTracker = new CoordinateTracker(puzzle.Size); ruleCopy.Update(secondCoord, secondVal, coordTracker); var originalCoordTracker = new CoordinateTracker(puzzle.Size); rule.Update(secondCoord, secondVal, originalCoordTracker); Assert.Equal( new HashSet <Coordinate> { new Coordinate(0, 2), new Coordinate(2, 1), new Coordinate(1, 0) }, new HashSet <Coordinate>(coordTracker.TrackedCoords.ToArray())); Assert.Equal( new HashSet <Coordinate> { new Coordinate(0, 2), new Coordinate(1, 1), new Coordinate(2, 1), new Coordinate(1, 0) }, new HashSet <Coordinate>(originalCoordTracker.TrackedCoords.ToArray())); }
public void TryInitFor_FiltersCorrectly() { var puzzle = new PuzzleWithPossibleValues(new int?[][] { new int?[] { 1, null /* 4 */, null /* 3 */, 2 }, new int?[] { null /* 2 */, null /* 3 */, 1, null /* 4 */ }, new int?[] { null /* 4 */, null /* 1 */, null /* 2 */, null /* 3 */ }, new int?[] { 3, 2, 4, 1 }, }); var rule = new StandardRules(); Assert.True(rule.TryInit(puzzle, puzzle.UniquePossibleValues)); Assert.Equal(new BitVector(0b11000), rule.GetPossibleValues(new Coordinate(0, 1))); Assert.Equal(new BitVector(0b01000), rule.GetPossibleValues(new Coordinate(0, 2))); Assert.Equal(new BitVector(0b10100), rule.GetPossibleValues(new Coordinate(1, 0))); Assert.Equal(new BitVector(0b11000), rule.GetPossibleValues(new Coordinate(1, 1))); Assert.Equal(new BitVector(0b11000), rule.GetPossibleValues(new Coordinate(1, 3))); Assert.Equal(new BitVector(0b10000), rule.GetPossibleValues(new Coordinate(2, 0))); Assert.Equal(new BitVector(0b10010), rule.GetPossibleValues(new Coordinate(2, 1))); Assert.Equal(new BitVector(0b01100), rule.GetPossibleValues(new Coordinate(2, 2))); Assert.Equal(new BitVector(0b01000), rule.GetPossibleValues(new Coordinate(2, 3))); }
private DeckValidationResult ValidateBasicRules(Deck deck) { var standardRules = new StandardRules(); var result = new DeckValidationResult(); var requiredPlots = validators.SingleOrDefault(v => v.RequiredPlots.HasValue)?.RequiredPlots ?? standardRules.RequiredPlots; var requiredDraw = validators.SingleOrDefault(v => v.RequiredDraw.HasValue)?.RequiredDraw ?? standardRules.RequiredDraw; var maxDoublePlots = validators.SingleOrDefault(v => v.MaxDoublePlots.HasValue)?.MaxDoublePlots ?? standardRules.MaxDoublePlots; var plotCount = deck.CountCards(DeckCardType.Normal, card => card.IsPlotCard()); var drawCount = deck.CountCards(DeckCardType.Normal, card => card.IsDrawCard()); if (plotCount < requiredPlots) { result.AddError("Too few plot cards"); } else if (plotCount > requiredPlots) { result.AddError("Too many plot cards"); } if (drawCount < requiredDraw) { result.AddError("Too few draw cards"); } if (deck.GetNormalCards().Count(dc => dc.Card.IsPlotCard() && dc.Count == 2) > maxDoublePlots) { result.AddError($"Maximum allowed number of doubled plots: {maxDoublePlots}"); } result.PlotCount = plotCount; result.DrawCount = drawCount; result.BasicRules = true; return(result); }
public void Setup() { rules = new StandardRules(); }