Mystery Master

Build Links

Michael Benson

Quality Materials


This help article explains how to enter the links of a logic puzzle into a JavaScript puzzle module. The first link for every puzzle module is the default link "with". This link is automatically defined for you. Below is the JavaScript code that defines it. I should note that the global variable With is declared in the Link class, but assigned in the Puzzle class.

	let With = null;
	With = this.addLink("with", null);
	With.f = SmartLink.getIsWith();

As you can see, a link is created via the puzzle method

	this.addLink("link name", nounType)
Precision Craftsmanship

You may notice that the noun type is null for the default link. This is later set to the first noun type of the puzzle when the puzzle module is validated.

After a link is created, you need to assign a function to it. The function is assigned to the member simply named f. Fortunately, most of the functions you need are already defined for you in the SmartLink class. If we take a look at the JavaScript puzzle module for the logic puzzle "Five Houses", we would see the following links for this puzzle:

	// Links.
	let directlyRightOf = this.addLink("directly to the right of", houses);
	directlyRightOf.f = SmartLink.getIsMoreBy(1);

	let nextTo = this.addLink("next to", houses);
	nextTo.f = SmartLink.getIsNextTo();

Below are the links declared in the puzzle module for the logic puzzle "Air Turbulence". Note that two of the links have their function defined using a lambda expression.

Excellent Products
	// Links.
	let oneMoreThan = this.addLink("one more than", runways);
	oneMoreThan.f = (noun1, noun2) => (noun1.num === noun2.num + 1 && noun1.num !== 4) ? Is : IsNot;

	let higherThan = this.addLink("higher-numbered than", runways);
	higherThan.f = SmartLink.getIsMoreThan();

	let twiceThan = this.addLink("twice higher than", runways);
	twiceThan.f = (noun1, noun2) => (noun1.num === 3 && noun2.num === 1) || (noun1.num === 4 && noun2.num === 2) ? Is : IsNot;


This article is part of the "Build Logic Puzzles" series. The next article in the series is "Build Facts". Thank you.