// (c) MIT 2003.  All rights reserved.

// $Id: RandomReasoner.java,v 1.4 2003/03/06 00:40:48 moltmans Exp $
// Time-stamp: <2000-03-11 18:54:47 moltmans>
package rec.core.reasoners;



import java.io.*;
import java.util.*;
import rec.util.*;
import rec.sys.*;

public class RandomReasoner //extends Reasoner 
{
  public RandomReasoner()
  {
    super();
  }


  //////////////////////////////////////////////////////////////////////////////

  /**
   * Called by Surface on each relevant Recognizer.
   *
   * @param w   The last thing added to the Surface, the root Widget
   *     which caused recognition to begin again.
   *
   * 
   */
  public void reason( Surface s, Widget w )
  {
    //Console.writeln( "Begin totally random Reasoning on: " + w );
    Collection c = w.getChildren();
 
    if ( c.isEmpty() ) {
      //strengthen( s, w, 1.0 );
    }
    else {
      VectorSet all = new VectorSet( c );
      //all.add( w );
      FamilyMember chosen = (FamilyMember)all.getRandomElement();
      if ( chosen instanceof Widget ) {
	reason( s, (Widget)chosen );
      }
      else {
	Iterator it = chosen.getChildrenIterator();
	while ( it.hasNext() ) {
	  reason( s, (Widget)it.next() );
	}
      }
    }
  }


}
