Class: Puzzle

Puzzle

Puzzle class.

Constructor

new Puzzle() → {Puzzle}

The Puzzle class is the base class for all puzzle modules.
Version:
  • 2017-03-27
Author:
Source:
Returns:
Puzzle.
Type
Puzzle

Members

answer

Puzzle answer.
Source:

facts

Array of facts.
Source:

isValid

Puzzle validation flag. Set to true in the validation method.
Source:
Array of links.
Source:

marks

Array of marks.
Source:

maxFacts

Maximum number of facts.
Source:

maxGrids

Maximum number of grids.
Source:
Maximum number of links.
Source:

maxMarks

Maximum number of marks.
Source:

maxNouns

Maximum number of nouns per type. This must be the same for all noun types.
Source:

maxNounTypes

Maximum number of noun types.
Source:

maxPairs

Maximum number of pairs.
Source:

maxRules

Maximum number of rules
Source:

myName

Name of the puzzle module.
Source:

myTitle

Title of the puzzle.
Source:

nounTypes

Array of noun types.
Source:

numFactHits

Number of times any fact has been referenced by the Solver.
Source:

numFacts

Number of facts examined by the Solver.
Source:

numGuesses

Number of assumptions made by the Solver.
Source:

numMarks

Number of marks entered by the Solver.
Source:

numPairs

Number of positive marks entered by the Solver.
Source:

numRuleHits

Number of times any rule has been referenced by the Solver.
Source:

numRules

Number of rules examined by the Solver.
Source:

rules

Array of rules.
Source:

verbs

Array of verbs. There must always be three verbs.
Source:

(inner) grids

Array of grids.
Source:

(inner) solver

Solver object. Instantiated on the WW thread.
Source:

(inner) viewer

Viewer object. Instantiated on the UI thread.
Source:

Methods

(static) getPairNoun(noun1, nounType2) → {Noun|null}

Returns noun 2 if noun 1 is with a noun of noun type 2, or null. Called by Puzzle.isPair, maybeRelated, canBeWith.
Parameters:
Name Type Description
noun1 Noun Noun 1.
nounType2 NounType Noun type 2.
Source:
Returns:
Noun, or null.
Type
Noun | null

(static) getPairNounNum(noun1, nounType2) → {number}

Returns the one-based number of noun 2 if noun 1 is with a noun of noun type 2, otherwise 0. Called by Helper.getChartAsHtml
Parameters:
Name Type Description
noun1 Noun Noun 1.
nounType2 NounType Noun type 2.
Source:
Returns:
One-based number of noun 2.
Type
number

(static) isPair(noun1, noun2) → {boolean}

Determines if noun 1 is with noun 2. NOT USED
Parameters:
Name Type Description
noun1 Noun Noun 1.
noun2 Noun Noun 2.
Source:
Returns:
True if noun 1 is with noun 2, otherwise false.
Type
boolean

addFact(clueNum, nounA, verb, link, nounB, name, initEnabled) → {Fact}

Creates and appends the new fact to the facts array. Overloads: nounA and/or nounB can be one noun or a list of nouns.
Parameters:
Name Type Description
clueNum string Clue number.
nounA Noun Noun A.
verb Verb Verb.
link Link Link.
nounB Noun Noun B.
name string | null Name of the fact, or null.
initEnabled boolean True if fact should be initially enabled, otherwise false.
Source:
Returns:
Fact object.
Type
Fact

addFacts1(clueNum, nouns, verb, link, name, initEnabled) → {Fact}

Creates and appends the new fact to the facts array. Note: If I define this function as local and use "self" to call addFact, then the parent's sayFact is used!
Parameters:
Name Type Description
clueNum string Clue number.
nouns Array Array of nouns.
verb Verb Verb.
link Link Link.
name string | null Name of the fact(s), or null.
initEnabled boolean True if fact should be initially enabled, otherwise false.
Source:
Returns:
Fact object.
Type
Fact

addFacts2(clueNum, nounA, verb, link, nounB, name, initEnabled) → {Fact}

Creates and appends the new fact to the facts array. Overload: nounA and nounB can each be one noun or a list of nouns. Note: If I define this function as local and use "self" to call addFact, then the parent's sayFact is used!
Parameters:
Name Type Description
clueNum string Clue number.
nounA Noun Noun A.
verb Verb Verb.
link Link Link.
nounB Noun Noun B.
name string | null Name of the fact(s), or null.
initEnabled boolean True if fact should be initially enabled, otherwise false.
Source:
Returns:
Fact object.
Type
Fact

addFactsInSequence(clueNum, nouns, verb, link, name, initEnabled)

Creates and appends new facts to the facts array.
Parameters:
Name Type Description
clueNum string Clue number.
nouns Array Array of nouns.
verb Verb Verb.
link Link Link.
name string | null Name of the fact(s), or null.
initEnabled boolean True if fact should be initially enabled, otherwise false.
Source:

addFactsIsNotFirstChar(clueNum, nounType1, nounType2, flag, name, initEnabled)

Creates and appends new facts to the facts array.
Parameters:
Name Type Description
clueNum string Clue number.
nounType1 NounType Noun type 1.
nounType2 NounType Noun type 2.
flag boolean Flag.
name string | null Name of the fact(s), or null.
initEnabled boolean True if fact should be initially enabled, otherwise false.
Source:

addFactsNotConsecutive(clueNum, nouns, link, name, initEnabled)

Creates and appends new facts to the facts array.
Parameters:
Name Type Description
clueNum string Clue number.
nouns Array Array of nouns.
link Link Link.
name string | null Name of the fact(s), or null.
initEnabled boolean True if fact should be initially enabled, otherwise false.
Source:

addFactsOneToOne(clueNum, nounA, verb, link, nounB, name, initEnabled)

Creates and appends new facts to the facts array. Overload: nounA and nounB can each be a list of nouns or a noun type.
Parameters:
Name Type Description
clueNum string Clue number.
nounA Noun Noun A.
verb Verb Verb.
link Link Link.
nounB Noun Noun B.
name string | null Name of the fact(s), or null.
initEnabled boolean True if fact should be initially enabled, otherwise false.
Source:

addFactsStartsWith(clueNum, noun1, nounType2, flag, ch, name, initEnabled)

Creates and appends new facts to the facts array.
Parameters:
Name Type Description
clueNum string Clue number.
noun1 Noun Noun 1.
nounType2 NounType Noun type 2.
flag boolean Flag.
ch char Character.
name string | null Name of the fact(s), or null.
initEnabled boolean True if fact should be initially enabled, otherwise false.
Source:
Creates and appends the new link to the links array.
Parameters:
Name Type Description
name string Name of the link.
nounType NounType Noun Type.
Source:
Returns:
Link object.
Type
Link

addMark(levelNum, levelSub, markType, refNum, refChar, noun1, verb, noun2, reason, facts, lonerNum, refMark, disabledFacts) → {Mark}

Updates the mark in the array. Called by addMarkByUser, addMarkByRule, finder.addMark, lawyer.addMark.
Parameters:
Name Type Description
levelNum number Level number.
levelSub string Level character.
markType Mark.Type Mark type.
refNum number Reference number.
refChar string Reference character.
noun1 Noun Noun 1.
verb Verb Verb.
noun2 Noun Noun 2.
reason string Reason.
facts Array | null Array of facts, or null
lonerNum number Zero-based Loner number.
refMark Mark | null Reference mark, or null.
disabledFacts Array | null Array of facts, or null.
Source:
Returns:
Mark object.
Type
Mark

addMarkByObjLit(obj)

Calls the addMark method with information from the object literal.
Parameters:
Name Type Description
obj object Object literal.
Source:

addNounType(name) → {NounType}

Creates and appends the new noun type to the nounTypes array.
Parameters:
Name Type Description
name string Name of the noun type.
Source:
Returns:
Noun Type object.
Type
NounType

addOneFact(clueNum, noun1, verb, link, noun2, name, initEnabled) → {Fact}

Creates and appends the new fact to the facts array. Note: If "self" was used to call sayFact, then the parent's sayFact is used!
Parameters:
Name Type Description
clueNum string Clue number.
noun1 Noun Noun 1.
verb Verb Verb.
link Link Link.
noun2 Noun Noun 2.
name string | null Name of the fact, or null.
initEnabled boolean True if fact should be initially enabled, otherwise false.
Source:
Returns:
Fact object.
Type
Fact

addRule(clueNum, name, nouns, initEnabled) → {Rule}

Creates and appends the new rule to the rules array.
Parameters:
Name Type Description
clueNum string Clue number.
name string Name of the rule.
nouns Array | null Array of nouns referenced in the rule.
initEnabled boolean True if fact should be initially enabled, otherwise false.
Source:
Returns:
Rule object.
Type
Rule

canBeLinked(noun1, link, slot2, i) → {boolean}

Determines if noun 1 can be related to slot 2 of the link's noun type.
Parameters:
Name Type Description
noun1 Noun Noun 1.
link Link Link.
slot2 Noun Slot 2.
i number Number.
Source:
Returns:
True if noun 1 can be related to slot 2, otherwise false.
Type
boolean

canBeWith(noun1, noun2) → {boolean}

Determines if noun 1 can be with noun 2. Called by canBeLinked, getCommonNoun.
Parameters:
Name Type Description
noun1 Noun Noun 1.
noun2 Noun Noun 2.
Source:
Returns:
True if noun 1 can be with noun 2, otherwise false.
Type
boolean

getArrayExcept(nouns1, nouns2) → {Array}

Returns the nouns in nouns1 that are not in nouns2.
Parameters:
Name Type Description
nouns1 Array Array of nouns.
nouns2 Array Array of nouns.
Source:
Returns:
Array of nouns in nouns1 that are not in nouns2.
Type
Array

getCommonNoun(noun1, noun2, nounType3) → {Noun|null}

Returns the first noun of noun type 3 that noun 1 and noun 2 can be with, otherwise null.
Parameters:
Name Type Description
noun1 Noun Noun 1.
noun2 Noun Noun 2.
nounType3 NounType Noun type 3.
Source:
Returns:
Noun, or null
Type
Noun | null

getGridMark(noun1, noun2) → {Mark|null}

Returns the mark in the grid given by two nouns.
Parameters:
Name Type Description
noun1 Noun Noun 1.
noun2 Noun Noun 2.
Source:
Returns:
Mark object, or null.
Type
Mark | null

getGridMark2(t1, n1, t2, n2) → {Mark|null}

Returns the mark in the grid given by the one-based type number and number for two nouns. Called by getGridMark.
Parameters:
Name Type Description
t1 number One-based number of noun 1's type.
n1 number One-based number of noun 1.
t2 number One-based number of noun 2's type.
n2 number One based number of noun 2.
Source:
Returns:
Mark object, or null.
Type
Mark | null

getGridNum(t1, t2) → {number}

Returns the one-based grid number given the one-based numbers of two noun types. Called by getGridMark2, setGridMark2.
Parameters:
Name Type Description
t1 number One-based number of noun type 1.
t2 number One-based number of noun type 2.
Source:
Returns:
One-based number of the grid.
Type
number

getGridVerb(noun1, noun2) → {Verb}

Returns the verb of the mark given by the two nouns, or the possible verb if the mark is null. Called by maybeRelated, finder, lawyer.
Parameters:
Name Type Description
noun1 Noun Noun 1.
noun2 Noun Noun 2.
Source:
Returns:
Verb object.
Type
Verb

getLastMark() → {Mark|null}

Returns the last mark in the stack, or null.
Source:
Returns:
Mark object, or null.
Type
Mark | null

getLastUserMark() → {Mark|null}

Returns the last mark entered by the user, or null. Called by undoUserMark.
Source:
Returns:
Mark object, or null.
Type
Mark | null

getNoun(typeNum, num) → {Noun}

Returns the noun give by its one-based type and one-based number.
Parameters:
Name Type Description
typeNum number One-based number of the noun's type.
num number One-based number of the noun.
Source:
Returns:
Noun object.
Type
Noun

getNouns(noun1, nounType2) → {Array}

Returns a list of nouns of noun type 2 that may be with noun 1. Called by ???
Parameters:
Name Type Description
noun1 Noun Noun 1.
nounType2 NounType Noun type 2.
Source:
Returns:
Array of nouns.
Type
Array

getNounType(num) → {NounType}

Returns the noun type given by its one-based number.
Parameters:
Name Type Description
num number One-based number of the noun type.
Source:
Returns:
Noun Type object.
Type
NounType

getVerb(num) → {Verb}

Returns the verb given by its number, either -1, 0, or 1.
Parameters:
Name Type Description
num number Number of the verb.
Source:
Returns:
Verb object.
Type
Verb

isAnswer() → {boolean}

Determines if the current solution is correct.
Source:
Returns:
True if the solution is correct (or the puzzle's answer is null), otherwise false.
Type
boolean

isMark(noun1, verb, noun2) → {Boolean}

Determines if the mark already exists. Called by solver.addMarkByRule, finder, lawyer.
Parameters:
Name Type Description
noun1 Noun Noun 1.
verb Verb Verb.
noun2 Noun Noun 2.
Source:
Returns:
True if the mark already exists, otherwise false.
Type
Boolean

maybeRelated(noun1, link, noun2) → {boolean}

Determines if noun 1 is/maybe related to noun 2. Called by NewSelfImprovement.
Parameters:
Name Type Description
noun1 Noun Noun 1.
link Link Link.
noun2 Noun Noun 2.
Source:
Returns:
True if noun 1 is or may be related to noun 2.
Type
boolean

removeGridMark(mark)

Removes the given mark from the grids. Called by solver.removeMark.
Parameters:
Name Type Description
mark Mark Mark object.
Source:

removeMark(callback) → {mark}

Removes the last mark in the stack, and returns it. Called by undoUserMark, undoAssumption.
Parameters:
Name Type Description
callback function | null Callback function, or null.
Source:
Returns:
Mark.
Type
mark

resetWork()

Resets the puzzle data used for solving a puzzle. Called by validate, viewer.resetWork, solver,resetWork.
Source:

sayFact(noun1, verb, link, noun2) → {string}

Returns "proper English" for the fact. The child class should override this method.
Parameters:
Name Type Description
noun1 Noun Noun 1.
verb Verb Verb.
link Link Link.
noun2 Noun Noun 2.
Source:
Returns:
String.
Type
string

setGridMark(mark)

Enters the given mark into the grids. Called by solver.addMark.
Parameters:
Name Type Description
mark Mark Mark object.
Source:

setGridMark2(t1, n1, t2, n2, mark)

Enters the mark/null into the grids using the one-based numbers of two nouns. Called by setGridMark, removeGridMark.
Parameters:
Name Type Description
t1 number One-based number of noun 1's type.
n1 number One-based number of noun 1.
t2 number One-based number of noun 2's type.
n2 number One-based number of noun 2.
mark Mark | null Mark object, or null.
Source:

undoAssumption(callback)

Removes marks back to and including the last mark entered by the levels.
Parameters:
Name Type Description
callback function | null Callback function, or null.
Source:

undoUserMark(callback)

Removes marks back to and including the last mark entered by the user.
Parameters:
Name Type Description
callback function | null Callback function, or null.
Source:

validate(aviewer, asolver)

Validates the puzzle. If valid, the isValid flag is set to true, otherwise false.
Parameters:
Name Type Description
aviewer Viewer Viewer object.
asolver Solver Solver object.
Source:

(inner) getClueNumMsg(clueNum, name) → {string}

Returns the clue number in parenthesis from the clueNum or the name.
Parameters:
Name Type Description
clueNum string | null Clue number.
name string Name of the fact or rule.
Source:
Returns:
String.
Type
string