Mystery Master

Build Rules

Michael Benson


Quality Materials

Introduction

This help article explains how to enter the rules of a logic puzzle into a JavaScript puzzle module. Not every puzzle needs rules, but they are required if the clues have conditional statements such as "Marge wasn't the second of the three women in line.". Rules are like laws, but while laws can be applied to any logic puzzle, rules are specific to one logic puzzle.

The JavaScript puzzle module for the logic puzzle "Five Houses" does not have rules, so let's take a look at the puzzle module for the logic puzzle "All Tired Out". This puzzle has two rules. Here is the JavaScript for its rules.

	// Rules.
	let rule1 = this.addRule("5", "Marge wasn't the second of the three women in line.");
	rule1.f = SmartRule.getIsNotBetween(this, rule1, slots, marge, grace, lisa);

	let rule2 = this.addRule("7", "Grace stood next to at least one man in line.");
	rule2.f = SmartRule.getIsRelated(this, rule2, grace, nextTo, [ethan, jeff]);
	

As you can see, a rule is entered via the puzzle method

Precision Craftsmanship
	this.addRule("clueNum", "Rule name.");
	

This puzzle also takes advantage of the methods in the SmartRule class.

A puzzle that does not take advantage of smart rules is "Ellis Island Idylls". If you look at its puzzle module, you can see that both rules have functions defined within the puzzle module. You can also see that both rules look for violations, and both rules invoke triggers. Here is the JavaScript for entering the two rules.

	// Rules.
	let rule1 = this.addRule("1", "No two boys auditioned for and play the same two roles.");
	let rule2 = this.addRule("10", "The Block youth got the part for which Pete auditioned.", [ block, pete ]);
	

Violations

The main purpose of a rule is to make sure the marks do not violate the rules. This is especially true if somebody wanted to manually solve the puzzle.

For the first rule, if actor 1 auditioned for role A but got role B, and actor 2 auditioned for role B but got role A, then this would be a violation.

Excellent Products

Triggers

A rule can also enter additional marks based on either the current mark, or on several existing marks. A rule that enters marks is called a trigger. It is important to note that having triggers can eliminate the need for assumptions.

For the first rule, if actor 1 auditioned for role A but portrays role B, then we can "trigger" a mark where an actor that auditioned for role B cannot portray role A.

Conclusion

This article is part of the "Build Logic Puzzles" series. Thank you.