org.dolben.MarkX
Class Requirement

java.lang.Object
  extended by org.dolben.MarkX.Requirement

 class Requirement
extends java.lang.Object

A Requirement, as part of the Monitors algorithm for generating guesses in the N digit number game, keeps track of a set of available digits and the number of digits that must be picked from that set, and provides a check that those constraints are satisfied.


Constructor Summary
Requirement(java.util.BitSet available, int needs)
          constructs a Requirement with a set of available digits and a number of digits from that set that are in the target number
 
Method Summary
 boolean ok(int digit, int left)
          checks that picking some digit with a number of places left in the guess satisfies the constraints
 void pick(int digit)
          tracks the picking of a digit
 java.lang.String toString()
          makes a String of the object
 void unpick(int digit)
          tracks the backtracking of picking a digit
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

Requirement

Requirement(java.util.BitSet available,
            int needs)
constructs a Requirement with a set of available digits and a number of digits from that set that are in the target number

Parameters:
available - the set of digits to track
needs - the number of digits from the set in the target
Method Detail

ok

public boolean ok(int digit,
                  int left)
checks that picking some digit with a number of places left in the guess satisfies the constraints

Parameters:
digit - the digit to check
left - the number of digits left in the guess
Returns:
true iff the digit is in the set and picking it does not preclude getting the needed number of digits from the set; the guess still needs digits from the set, and there are enough digits left to use the rest of the digits needed from the set

pick

public void pick(int digit)
tracks the picking of a digit

Parameters:
digit - the digit picked

unpick

public void unpick(int digit)
tracks the backtracking of picking a digit

Parameters:
digit - the digit which was picked before

toString

public java.lang.String toString()
makes a String of the object

Overrides:
toString in class java.lang.Object
Returns:
the String representing the object