public void PopulationWithOccurences() { const int numRooms = 5; ConstraintThingySolver solver = new ConstraintThingySolver(); // this the finite domain variables to be expanded first -- we test without this below solver.ExpansionOrder = ExpansionOrder.Deterministic; FiniteDomain <String> finiteDomain = new FiniteDomain <string>("enemy", "health-pack", "ammo", "boss", "puzzle"); FiniteDomainVariable <String>[] roomTypes = new FiniteDomainVariable <string> [numRooms]; for (int i = 0; i < numRooms; i++) { roomTypes[i] = solver.CreateFiniteDomainVariable(finiteDomain, "enemy", "health-pack", "ammo", "boss", "puzzle"); } // exactly 1 boss in the level Constraint.RequireOccurences("boss", 1, roomTypes); // at most 1 puzzle in the level Constraint.MaximumOccurences("puzzle", 1, roomTypes); RealVariable[] roomScores = new RealVariable[numRooms]; var scoreMapping = new ScoreMapping <String>(finiteDomain, "enemy".PairedWith(new Interval(-3, -3)), "health-pack".PairedWith(new Interval(2, 2)), "ammo".PairedWith(new Interval(2, 2)), "boss".PairedWith(new Interval(-6, -6)), "puzzle".PairedWith(new Interval(0, 0))); for (int i = 0; i < numRooms; i++) { roomScores[i] = Constraint.ScoreVariable(roomTypes[i], scoreMapping); } var sum = roomScores.Aggregate((a, b) => { var result = Constraint.Add(a, b); Constraint.GreaterThanOrEqual(result, 0); return(result); }); Constraint.InRange(sum, 0, 10); foreach (var solution in solver.Solutions.FirstElements(10)) { AssertIntersect(new Interval(0, 10), sum.UniqueValue); } }
private static void PlayabilityExperiment(int numRooms, int randomSeed) { ConstraintThingySolver solver = new ConstraintThingySolver(randomSeed); FiniteDomain <String> finiteDomain = new FiniteDomain <string>("enemy", "health-pack", "ammo", "boss", "puzzle"); FiniteDomainVariable <String>[] roomTypes = new FiniteDomainVariable <string> [numRooms]; for (int i = 0; i < numRooms; i++) { roomTypes[i] = solver.CreateFiniteDomainVariable(finiteDomain, "enemy", "health-pack", "ammo", "boss", "puzzle"); } // exactly 1 boss in the level Constraint.RequireOccurences("boss", 1, roomTypes); // exactly 1 puzzle in the level Constraint.RequireOccurences("puzzle", 1, roomTypes); RealVariable[] roomScores = new RealVariable[numRooms]; var scoreMapping = new ScoreMapping <String>(finiteDomain, "enemy".PairedWith(new Interval(-3, -3)), "health-pack".PairedWith(new Interval(2, 2)), "ammo".PairedWith(new Interval(2, 2)), "boss".PairedWith(new Interval(-6, -6)), "puzzle".PairedWith(new Interval(0, 0))); for (int i = 0; i < numRooms; i++) { roomScores[i] = Constraint.ScoreVariable(roomTypes[i], scoreMapping); } var sum = roomScores.Aggregate((a, b) => { var result = Constraint.Add(a, b); Constraint.GreaterThanOrEqual(result, 0); return(result); }); Constraint.InRange(sum, 0, 10); foreach (var solution in solver.Solutions.FirstElements(10)) { AssertIntersect(new Interval(0, 10), sum.UniqueValue); Assert.AreEqual(1, roomTypes.Count(room => room.UniqueValue == "puzzle")); Assert.AreEqual(1, roomTypes.Count(room => room.UniqueValue == "boss")); } }
protected override void InitializeConstraintSystem(ConstraintThingySolver solver) { const int numRooms = 5; FiniteDomain <string> finiteDomain = new FiniteDomain <string>("enemy", "health-pack", "ammo", "boss", "puzzle"); FiniteDomainVariable <string>[] roomTypes = new FiniteDomainVariable <string> [numRooms]; for (int i = 0; i < numRooms; i++) { roomTypes[i] = solver.CreateFiniteDomainVariable(finiteDomain, "enemy", "health-pack", "ammo", "boss", "puzzle"); } // exactly 1 boss in the level Constraint.RequireOccurences("boss", 1, roomTypes); // exactly 1 puzzle in the level Constraint.RequireOccurences("puzzle", 1, roomTypes); RealVariable[] roomScores = new RealVariable[numRooms]; var scoreMapping = new ScoreMapping <string>(finiteDomain, "enemy".PairedWith(new Interval(-3, -3)), "health-pack".PairedWith(new Interval(2, 2)), "ammo".PairedWith(new Interval(2, 2)), "boss".PairedWith(new Interval(-6, -6)), "puzzle".PairedWith(new Interval(0, 0))); for (int i = 0; i < numRooms; i++) { roomScores[i] = Constraint.ScoreVariable(roomTypes[i], scoreMapping); } var sum = roomScores.Aggregate((a, b) => { var result = Constraint.Add((RealVariable)a, b); Constraint.GreaterThanOrEqual(result, 0); return(result); }); Constraint.InRange(sum, 0, 10); }