org.dolben.MarkX
Class MonitorsGenerator

java.lang.Object
  extended by org.dolben.MarkN.Generator
      extended by org.dolben.MarkX.MonitorsGenerator

 class MonitorsGenerator
extends Generator

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

MonitorsGenerator()
makes one Monitor for each digit in each place and sets that the next guess is the first one

Method Detail

tellScore

public void tellScore(Score score)
is given a score for the last guess

Specified by:
tellScore in class Generator
Parameters:
score - the score for the last guess

nextGuess

public boolean nextGuess(Numbah guess)
generates the next guess

Specified by:
nextGuess in class Generator
Parameters:
guess - the next generated guess
Returns:
true iff there is a next guess. (It won't be possible to generate a guess if scores given for the previous guesses are logically inconsistent.)

retractScore

public void retractScore()
backs up to state before last nextGuess()

Specified by:
retractScore in class Generator

toString

public java.lang.String toString()
makes a string made of the strings of all the monitors

Overrides:
toString in class java.lang.Object
Returns:
the string of all the monitors

main

public static void main(java.lang.String[] arg)
                 throws java.lang.Exception
tests the class

Parameters:
arg - ignored
Throws:
java.lang.Exception