|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.dolben.MarkN.Generator
org.dolben.MarkX.MonitorsGenerator
class MonitorsGenerator
This class contains the guts of the N digit number game guess generator, particularly, the "Monitors algorithm" for generating guesses.
Each time a guess is generated, it is a number which could have produced the scores of the previous guesses.
There is a Monitor for each (digit, place) containing the requirements created by the guesses made before and their scores. To generate the digit in each place of the next guess, find a digit that, according to the Monitor for that digit and place, satisfies the requirements. When there is no digit that satisfies the requirements at some place in the guess, backtrack and try a different digit in the previous place (a recursive operation).
A requirement says that some number of digits must be included in the guess from a given set. When a guess is scored with the number of placed digits and the number of misplaced digits, first, two sets of digits are created: the digits in the guess, and the digits not in the guess. Then, three requirements are created and added to the Monitors:
Constructor Summary | |
---|---|
MonitorsGenerator()
makes one Monitor for each digit in each place and sets that the next guess is the first one |
Method Summary | |
---|---|
static void |
main(java.lang.String[] arg)
tests the class |
boolean |
nextGuess(Numbah guess)
generates the next guess |
void |
retractScore()
backs up to state before last nextGuess() |
void |
tellScore(Score score)
is given a score for the last guess |
java.lang.String |
toString()
makes a string made of the strings of all the monitors |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Constructor Detail |
---|
MonitorsGenerator()
Method Detail |
---|
public void tellScore(Score score)
tellScore
in class Generator
score
- the score for the last guesspublic boolean nextGuess(Numbah guess)
nextGuess
in class Generator
guess
- the next generated guess
public void retractScore()
retractScore
in class Generator
public java.lang.String toString()
toString
in class java.lang.Object
public static void main(java.lang.String[] arg) throws java.lang.Exception
arg
- ignored
java.lang.Exception
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |