
*** Modified files in JOE when it aborted on Fri Feb  7 14:46:17 2003
*** JOE was aborted by signal 1

*** File '(Unnamed)'
StringCounter.java

*** File 'Tank.java'
//
// Demo tank bean for Jess
// $Id: Tank.java,v 1.2 2001/09/24 13:48:52 ejfried Exp $
//

package jess.examples.pumps;
import java.beans.*;
import javax.swing.*;
import java.awt.*;
import java.io.Serializable;

public class StringCounter
{
  private int m_level;
  private String cipher_text;
  private JProgressBar m_bar;

  public StringCounter(String str)
  {
    cipher_text = str;
  }

  public String getText() 
  {
    return cipher_text;
  }

  public void addWater(int amt)
  {
    if (amt != 0)
      {
        String name = "level";
        boolean hi = isHigh();
        boolean lo = isLow();
        boolean intact = isIntact();

        int tmp = m_level;
        m_level += amt;

        // Check if any other properties were affected
        if (hi != isHigh() || lo != isLow() || intact != isIntact())
          name = null;

        pcs.firePropertyChange(name, new Integer(tmp),
                               new Integer(m_level));
        // System.out.println("Tank " + getName() + " level now " + m_level);
        m_bar.setValue(m_level);

      }
  }

  public void run()
  {
    while (isIntact())
      {
        addWater(-1);
        try { Thread.sleep(25); } catch (InterruptedException ie) { break; }
      }

    if (m_level >= 1000)
      System.out.println("Tank exploded!");
    else if (m_level <= 0)
      System.out.println("Tank ran dry and caught fire!");
  }


  private PropertyChangeSupport pcs = new PropertyChangeSupport(this);
  public void addPropertyChangeListener(PropertyChangeListener pcl)
  {
    pcs.addPropertyChangeListener(pcl);
  }
  public void removePropertyChangeListener(PropertyChangeListener pcl)
  {
    pcs.removePropertyChangeListener(pcl);
  }

}

*** Modified files in JOE when it aborted on Fri Feb  7 14:51:16 2003
*** JOE was aborted by signal 1

*** File '(Unnamed)'
StringCounter.java
*** File 'StringCounter.java'
[B//
// Demo tank bean for Jess
// $Id: Tank.java,v 1.2 2001/09/24 13:48:52 ejfried Exp $
//

package jess.examples.pumps;
import java.beans.*;
import javax.swing.*;
import java.awt.*;
import java.io.Serializable;

public class StringCounter
{
  private int m_level;
  private String cipher_text;
  private JProgressBar m_bar;

  public StringCounter(String str)
  {
    cipher_text = str;
  }

}

*** Modified files in JOE when it aborted on Fri Feb  7 15:43:41 2003
*** JOE was aborted by signal 1

*** File 'pumps-fromjava.clp'
;; -*- clips -*-

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Pumps and Tanks control example, used by the MainInJava class. The
;; simple algrithm coded in this file isn't good enough to control the
;; Pump and the Tank will explode on the first cycle.


;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Register Java classes for matching like deftemplates.
;; Bean-like properties become slots. Classes must support
;; addPropertyChangeListener. First argument is the 'deftemplate name'.

(defclass tank jess.examples.pumps.Tank )
(defclass pump jess.examples.pumps.Pump )

s;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; This fact will be used to sleep when idle

(deffacts idle-fact
  (idle))

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; If tank is low, raise appropriate pump's pumping rate
;; Don't raise it too high!
;; Notice how we can call methods of the objects we match, like Pump.setFlow()

(defrule warn-if-low
  (tank (name ?name) (low TRUE) (intact TRUE))
  (not (warning low ?name))
  =>
  (assert (warning low ?name))
  (printout t "WARNING: TANK " ?name " IS LOW!" crlf)
  )

(defrule raise-rate-if-low
  ?warning <- (warning low ?name)
  (pump (name ?name) (flow ?flow-rate) (OBJECT ?pump))
  (test (< ?flow-rate 25))
  =>
  (retract ?warning)
  (set ?pump flow (+ ?flow-rate 5))
  (printout t "Raised pumping rate of pump " ?name " to "
            (get ?pump flow) crlf))

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; If tank is low, raise appropriate pump's pumping rate
;; Don't lower it too much.

(defrule warn-if-high
  (tank (name ?name) (high TRUE) (intact TRUE))
  (not (warning high ?name))
  =>
  (assert (warning high ?name))
  (printout t "WARNING: TANK " ?name " IS HIGH!" crlf)
  )

(defrule lower-rate-if-high
  ?warning <- (warning high ?name)
  (pump (name ?name) (flow ?flow-rate) (OBJECT ?pump))
  (test (> ?flow-rate 5))
  =>
  (retract ?warning)
  (set ?pump flow (- ?flow-rate 5))
  (printout t "Lowered pumping rate of pump " ?name " to "
            (get ?pump flow) crlf))

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; If tank is ok, sleep for 100 milliseconds
;; Notice outcall to Java static method!

(defrule notify-if-ok
  ?warning <- (warning ? ?name)
  (tank (name ?name) (high FALSE) (low FALSE))
  =>
  (retract ?warning)
  (printout t "Tank " ?name " is now OK." crlf))

(defrule sleep-if-bored
  (declare (salience -100))
  ?idle <- (idle)
  =>
  (retract ?idle)
  (call java.lang.Thread sleep 100)
  (assert (idle)))
  
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; If tank is damaged, report it

(defrule report-fire
  ?t <- (tank (name ?name) (low TRUE) (intact FALSE))
  =>
  (printout t "*********************************************" crlf)
  (printout t "* Tank " ?name " has run dry and caught fire.    " crlf)
  (printout t "*********************************************" crlf)
  (retract ?t)
  (halt))

(defrule report-explosion
  ?t <- (tank (name ?name) (high TRUE) (intact FALSE))
  =>
  (printout t "*********************************************" crlf)
  (printout t "* Tank " ?name " has overfilled and exploded " crlf)
  (printout t "*********************************************" crlf)
  (retract ?t)
  (halt))

;; Actual creation of objects, as well as (reset) and (run) calls,
;; must be made form Java code that runs this batch file.
*** Modified files in JOE when it aborted on Fri Feb  7 15:52:37 2003
*** JOE was aborted by signal 1

*** File 'pumps-java.clp'
;; -*- clips -*-

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Pumps and Tanks control example, used by the MainInJava class. The
;; simple algrithm coded in this file isn't good enough to control the
;; Pump and the Tank will explode on the first cycle.


;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Register Java classes for matching like deftemplates.
;; Bean-like properties become slots. Classes must support
;; addPropertyChangeListener. First argument is the 'deftemplate name'.

(defclass tank jess.examples.pumps.Tank )
(defclass pump jess.examples.pumps.Pump )
(deftemplate machine (slot name) (slot class) (slot OBJECT))

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; This fact will be used to sleep when idle
[A
(deffacts idle-fact
  (idle))

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
[A;; If tank is low, raise appropriate pump's pumping rate
;; Don't raise it too high!
;; Notice how we can call methods of the objects we match, like Pump.setFlow()

(defrule warn-if-low
  (tank (name ?name) (low TRUE) (intact TRUE))
  (not (warning low ?name))
  =>
  (assert (warning low ?name))
  (printout t "WARNING: TANK " ?name " IS LOW!" crlf)
  )

(defrule raise-rate-if-low
  ?warning <- (warning low ?name)
  (pump (name ?name) (flow ?flow-rate) (OBJECT ?pump))
  (test (< ?flow-rate 25))
  =>
  (retract ?warning)
  (set ?pump flow (+ ?flow-rate 5))
  (printout t "Raised pumping rate of pump " ?name " to "
            (get ?pump flow) crlf))

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; If tank is low, raise appropriate pump's pumping rate
;; Don't lower it too much.

(defrule warn-if-high
  (tank (name ?name) (high TRUE) (intact TRUE))
  (not (warning high ?name))
  =>
  (assert (warning high ?name))
  (printout t "WARNING: TANK " ?name " IS HIGH!" crlf)
  )

(defrule lower-rate-if-high
  ?warning <- (warning high ?name)
  (pump (name ?name) (flow ?flow-rate) (OBJECT ?pump))
  (test (> ?flow-rate 5))
  =>
  (retract ?warning)
  (set ?pump flow (- ?flow-rate 5))
  (printout t "Lowered pumping rate of pump " ?name " to "
            (get ?pump flow) crlf))

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; If tank is ok, sleep for 100 milliseconds
;; Notice outcall to Java static method!

(defrule notify-if-ok
  ?warning <- (warning ? ?name)
  (tank (name ?name) (high FALSE) (low FALSE))
  =>
  (retract ?warning)
  (printout t "Tank " ?name " is now OK." crlf))

(defrule sleep-if-bored
  (declare (salience -100))
  ?idle <- (idle)
  =>
  (retract ?idle)
  (call java.lang.Thread sleep 100)
  (assert (idle)))
  
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; If tank is damaged, report it

(defrule report-fire
  ?t <- (tank (name ?name) (low TRUE) (intact FALSE))
  =>
  (printout t "*********************************************" crlf)
  (printout t "* Tank " ?name " has run dry and caught fire.    " crlf)
  (printout t "*********************************************" crlf)
  (retract ?t)
  (halt))

(defrule report-explosion
  ?t <- (tank (name ?name) (high TRUE) (intact FALSE))
  =>
  (printout t "*********************************************" crlf)
  (printout t "* Tank " ?name " has overfilled and exploded " crlf)
  (printout t "*********************************************" crlf)
  (retract ?t)
  (halt))

;; Actual creation of objects, as well as (reset) and (run) calls,
;; must be made form Java code that runs this batch file.
*** Modified files in JOE when it aborted on Sun Feb  9 23:47:24 2003
*** JOE was aborted by signal 1

*** Modified files in JOE when it aborted on Mon Feb 10 10:21:19 2003
*** JOE was aborted by signal 1

*** Modified files in JOE when it aborted on Tue Feb 11 19:31:21 2003
*** JOE was aborted by signal 1

*** File 'pumps2.clp'
;; -*- clips -*-

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Pumps and Tanks control example, used by the MainInJava class. The
;; simple algrithm coded in this file isn't good enough to control the
;; Pump and the Tank will explode on the first cycle.

(import jess.examples.pumps.*)

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Register Java classes for matching like deftemplates.
;; Bean-like properties become slots. Classes must support
;; addPropertyChangeListener. First argument is the 'deftemplate name'.

(defclass stringcounter StringCounter)

;; If tank is low, raise appropriate pump's pumping rate
;; Don't raise it too high!
;; Notice how we can call methods of the objects we match, like Pump.setFlow()

(defrule print_string
  =>
   (printout t "The cipher text is: " crlf)
)

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;Startup creates two instances of stringcounter with the values 'hello' and
;;   'test'.  It does this by binding the object to a global jess variable.
;;   It then calls the methods getLength and getString in the stringcounter
;;   class and binds these values to variables as well.  Lastly it prints
;;   the string and length of each of the two stringcounters.

(defrule startup
  =>
   (definstance stringcounter (bind ?stringcounter (new StringCounter
"hello")))  
   (definstance stringcounter (bind ?s2 (new StringCounter "test")))
   (bind ?len (call ?stringcounter getLength))      
   (printout t ?len crlf)
   (bind ?len (call ?s2 getLength))      
   (printout t "The string " (call ?s2 getString) " has length " ?len crlf)
   (printout t "TEST" crlf)
)

(reset)
(run)



*** Modified files in JOE when it aborted on Fri Feb 14 15:48:14 2003
*** JOE was aborted by signal 1

*** File 'MainTest.java'
package jess.examples.pumps;
import jess.*;

/**
  An example of creating Beans in Java, then telling Jess about them.

  Don't run this from this directory! It expects you to run it from the
  JessXX distribution directory, like this:

    java jess.examples.pumps.MainTest

  */

public class MainTest
{
  public static void main(String[] argv) throws JessException
  {
    Rete rete = new Rete();

    // Read in the rules
    rete.executeCommand("(batch jess/examples/pumps/pumps-java.clp)");
    rete.executeCommand("(reset)");

    //rete.store("IC", "test");
    //rete.store("Freq", "same");
    //rete.run(); 
 
    // Create the Beans
    StringCounter text = new StringCounter(argv[0]);
	System.out.println(text.getString());
      
      Rete r = new Rete();
      r.store("STRINGCOUNTER", text);
      r.executeCommand("(defclass stringcounter [A)");
      r.executeCommand("(definstance dimension (fetch DIMENSION) static)");

      r.executeCommand("(facts)");    
    // Tell Jess about them
    /*Funcall f = new Funcall("definstance", rete);               
    f.add(new Value("stringcounter", RU.ATOM));    //store object
    f.add(new Value(text));
    f.execute(rete.getGlobalContext()); 
    */
    /*while (t.isIntact())*/
      rete.executeCommand("(run)");
  }
}








*** Modified files in JOE when it aborted on Fri Feb 14 15:45:38 2003
*** JOE was aborted by signal 1

*** Modified files in JOE when it aborted on Sun Feb 16 16:51:15 2003
*** JOE was aborted by signal 1

*** File 'MainTest.java'
package jess.examples.pumps;
import jess.*;

/****************************************************************************
  An example of creating Java Objects, then telling Jess about them.
  This is possible using the store anf fetch functions and using retes.

  The program creates a StringCounter object, then stores it in a rete.
  Jess is then called and fetches the object.  It then prints out the value,
    its length and changes it.  The Java program then prints the new value.


  [BDon't run this from this directory! It expects you to run it from the
  JessXX distribution directory, like this:
[B
    java jess.examples.pumps.MainTest

****************************************************************************/

public class MainTest
{
  public static void main(String[] argv) throws JessException
  {
      //create a rete
      Rete r = new Rete();

      //create a stringcounter object suing the value from the command line
      StringCounter str = new StringCounter(argv[0]);

      //store the stringcounter object in the rete
      r.store("citext", str);

    // Read in the rules from Jess
    r.executeCommand("(batch jess/examples/pumps/pumps-java.clp)");
    r.executeCommand("(reset)");

    //print the new string
    System.out.println("The new string from jess is " + str.getString());
 
  }
}





*** Modified files in JOE when it aborted on Mon Feb 24 14:24:07 2003
*** JOE was aborted by signal 1

*** File '(Unnamed)'
ex-java.clp
ex-java.clp
ex-java.clp
ex-java.clp
ex-java.clp
*** File '(Unnamed)'
ex-java.clp
ex-java.clp
ex-java.clp
ex-java.clp

*** File 'ex-java.clp'
;; -*- clips -*-

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; StringCounter control and fetch example, used by the MainTest class.

(import jess.examples.pumps.*)
(import hcrypto.analyzer.*)

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Register Java classes for matching like deftemplates.
;; Bean-like properties become slots. Classes must support
;; addPropertyChangeListener.

(defclass indexofcoincidence IndexOfCoincidence)


;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Binds the stringcoutner object to a jess variable, prints it, 
;;   then changes it.
;; Notice how we can call methods of the objects stored in Java


(defrule startup
  =>
   (bind ?text (fetch ic))
   (bind ?ic (call ?text getIOC))
   (printout t "The index of coincidence is: " ?ic crlf)
;;   (printout t "The length of the text is: " (call ?text getLength) crlf)
;;   (call ?text setString "goodbye")
)

(defrule temp
  (< 1 5
  =>
  (printout t "HERE" crlf)
)

(reset)
(run)

*** Modified files in JOE when it aborted on Mon Feb 24 14:50:12 2003
*** JOE was aborted by signal 1

*** File 'ex-java.clp'
;; -*- clips -*-

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; StringCounter control and fetch example, used by the MainTest class.

(import jess.examples.pumps.*)
(import hcrypto.analyzer.*)

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Register Java classes for matching like deftemplates.
;; Bean-like properties become slots. Classes must support
;; addPropertyChangeListener.

(defclass indexofcoincidence IndexOfCoincidence)


;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Binds the stringcoutner object to a jess variable, prints it, 
;;   then changes it.
;; Notice how we can call methods of the objects stored in Java

(deffunction max (?a ?b)
  (if (> ?a ?b) then
      ?a
   else
      ?b))

(defglobal ?*index* = 0.0+)

(defrule startup
  =>
   (bind ?text (fetch ic))
   (bind ?ic (call ?text getIOC))
   (bind ?*index* ?ic)
   (printout t "The index of coincidence is: " ?ic crlf)
   (printout t "The biggest value is: " (<?ic 2.0) crlf)
;;   (printout t "The length of the text is: " (call ?text getLength) crlf)
;;   (call ?text setString "goodbye")
)

(defrule temp
  =>
  (printout t "The larger value is: " (max 3.0 5.0) crlf)
)

(reset)
(run)

*** Modified files in JOE when it aborted on Wed Mar  5 18:47:15 2003
*** JOE was aborted by signal 1

*** File '(Unnamed)'
cipher2.clp
cipher2.clp
cipher2.clp

*** Modified files in JOE when it aborted on Mon Mar 10 16:29:55 2003
*** JOE was aborted by signal 1

*** File 'Cipher.java'
//
// Demo StringCounter bean for Jess
// $Id: StringCounter.java, 2/11/03
//
//

package jess.examples.pumps;
import java.beans.*;
//import java.io.Serializable;

public class Cipher
{
  //variables
  private String cipher = "";
  

  //default stringcounter constructor(does NOT work)
  public Cipher()
  {  }

  //StringCounter constructor that takes a string value
  public Cipher(String str)
  {
    cipher = str;
  }

  //returns the length of the cipher_text in the stringcounter
  public int getLength()
  {
	return cipher_text.length();
  }

  //returns the string value of the object
  public String getCipher()
  {
	return cipher_text;
  }

  //resets the value of the object with the value given
  public void setCipher(String str)
  {
  	cipher = str;
  }

/*  public void run()
  {
  }


  private PropertyChangeSupport pcs = new PropertyChangeSupport(this);
  public void addPropertyChangeListener(PropertyChangeListener pcl)
  {
    pcs.addPropertyChangeListener(pcl);
  }
  public void removePropertyChangeListener(PropertyChangeListener pcl)
  {
    pcs.removePropertyChangeListener(pcl);
  }
*/
}

*** Modified files in JOE when it aborted on Mon Mar 10 16:29:55 2003
*** JOE was aborted by signal 15

*** File '(Unnamed)'
Cipher.java

*** File 'StringCounter.java'
//
// Demo StringCounter bean for Jess
// $Id: StringCounter.java, 2/11/03
//
//

package jess.examples.pumps;
import java.beans.*;
//import java.io.Serializable;

public class StringCounter
{
  //variables
  private String cipher_text;
  

  //default stringcounter constructor(does NOT work)
  public StringCounter()
  {
      System.out.println("hello stringcounter");
  }

  //StringCounter constructor that takes a string value
  public StringCounter(String str)
  {
    cipher_text = str;
  }

  //returns the length of the cipher_text in the stringcounter
  public int getLength()
  {
	return cipher_text.length();
  }

  //returns the string value of the object
  public String getString()
  {
	return cipher_text;
  }

  //resets the value of the object with the value given
  public void setCipher(String str)
  {
  	cipher_text = str;
  }

/*  public void run()
  {
  }


  private PropertyChangeSupport pcs = new PropertyChangeSupport(this);
  public void addPropertyChangeListener(PropertyChangeListener pcl)
  {
    pcs.addPropertyChangeListener(pcl);
  }
  public void removePropertyChangeListener(PropertyChangeListener pcl)
  {
    pcs.removePropertyChangeListener(pcl);
  }
*/
}

*** Modified files in JOE when it aborted on Wed Mar 12 17:05:45 2003
*** JOE was aborted by signal 1

*** File '(Unnamed)'
MainTest5.java
MainTest5.java

*** Modified files in JOE when it aborted on Mon Mar 31 00:51:26 2003
*** JOE was aborted by signal 1

*** File '(Unnamed)'
MainTest7.java
MainTest7.java
MainTest7.java
MainTest7.java
MainTest7.java

*** Modified files in JOE when it aborted on Mon Mar 31 00:51:27 2003
*** JOE was aborted by signal 1

*** Modified files in JOE when it aborted on Tue Apr  1 12:14:16 2003
*** JOE was aborted by signal 1

*** Modified files in JOE when it aborted on Fri Apr  4 14:14:16 2003
*** JOE was aborted by signal 1

*** File '(Unnamed)'
MainTest8.java
MainTest8.java

*** Modified files in JOE when it aborted on Sun Apr  6 20:33:36 2003
*** JOE was aborted by signal 1

*** File '(Unnamed)'
cipher5.clp

*** Modified files in JOE when it aborted on Tue Apr 15 21:43:54 2003
*** JOE was aborted by signal 1

*** File '(Unnamed)'
cipher7.clp
cipher7.clp
cipher7.clp
cipher7.clp
cipher7.clp
cipher7.clp
cipher7.clp
cipher7.clp
cipher7.clp
cipher7.clp
cipher7.clp
cipher7.clp
cipher7.clp

*** File 'cipher7.clp'


;;;======================================================
;;;   Farmer's Dilemma Problem
;;;
;;;     Another classic AI problem (cannibals and the 
;;;     missionary) in agricultural terms. The point is
;;;     to get the farmer, the fox the cabbage and the
;;;     goat across a stream.
;;;        But the boat only holds 2 items. If left 
;;;     alone with the goat, the fox will eat it. If
;;;     left alone with the cabbage, the goat will eat
;;;     it.
;;;
;;;     CLIPS Version 6.0 Example, modified for Jess
;;;
;;;     To execute, merely load, reset and run.
;;;======================================================


(import jess.examples.pumps.*)
(import hcrypto.analyzer.*)


(defclass indexofcoincidence IndexOfCoincidence)
(defclass jesscipher JessCipher)


;;;*************
;;;* TEMPLATES *
;;;*************

;;; The status facts hold the state  
;;; information of the search tree.

(defglobal ?*index* = (fetch ic))
(defglobal ?*glcipher* = (fetch cipher))

(deftemplate MAIN::status 
   (slot search-depth)
   (slot parent)
   (slot ic (type LONG))
   (slot shift)
   (slot type)
   (slot last-move)	
)
   
;;;*****************
;;;* INITIAL STATE *
;;;*****************

(deffacts MAIN::initial-positions
  (status (search-depth 1)
	   (parent no-parent)
	   (ic (call ?*index* getIOC)) 
           (shift (call ?*glcipher* getShift))
	   (type unknown)
           (last-move no-move))
)

;;;***********************
;;;* GENERATE PATH RULES *
;;;***********************

(defrule MAIN::move-to-transposition
  ?node <- (status (search-depth ?num)
                   (shift ?shift)
                   (ic ?ic)
                   (type unknown))
  (test (= ?num 1))             ;;1st level of tree
  (test (= ?shift 0))
  (test (< .058 ?ic))
  =>
  (duplicate ?node (search-depth (+ 1 ?num))
                   (parent ?node)
                   (type known)
                   (last-move Transposition))
  (printout t crlf ?ic crlf)
)

(defrule MAIN::move-substitution
  ?node <- (status (search-depth ?num) 
                   (shift ?shift)
		   (ic ?ic)
		   (type unknown))
  (test (= ?num 1))		;;1st level of tree
  (test (<> ?shift 0))
  =>
  (duplicate ?node (search-depth (+ 1 ?num))
                   (parent ?node)
                   (type unknown)
                   (last-move Substitution))
  (printout t crlf ?shift ?ic crlf)
)

(defrule MAIN::move-to-simple
  ?node <- (status (search-depth ?num) 
                   (ic ?ic)
 		   (type unknown))
  (test (= ?num 2))		;;2nd level of tree
  (test (< .058 ?ic))
  =>
  (duplicate ?node (search-depth (+ 1 ?num)) 
                   (parent ?node)
                   (type unknown)
                   (last-move Simple-Substitution))
)

(defrule MAIN::move-to-caesar
  ?node <- (status (search-depth ?num) 
                   (shift ?shift)
		   (type unknown))
  (test (= ?num 3))		;;3rd level of tree
  (test (<> ?shift -1))
  =>
  (duplicate ?node (search-depth (+ 1 ?num)) 
                   (parent ?node)
                   (type known)
                   (last-move Caesar))
)

(defrule MAIN::move-to-affine
  ?node <- (status (search-depth ?num)
                   (shift ?shift)
		   (type unknown)
		   (ic ?ic))
  (test (= ?num 3)) 		;;3rd level of tree
  (test (= ?shift -1))
  (test (> ?ic .058))
  =>
  (duplicate ?node (search-depth (+ 1 ?num)) 
                   (parent ?node)
                   (type known)
                   (last-move Affine))
)

(defrule MAIN::move-to-multi
  ?node <- (status (search-depth ?num)
                   (ic ?ic)
		   (type unknown))
  (test (= ?num 2))		;;2nd level of tree
  (test (<= ?ic .058))
  =>
  (duplicate ?node (search-depth (+ 1 ?num)) 
                   (parent ?node)
                   (type unknown)
                   (last-move Multi-Substitution))
)

(defrule MAIN::move-to-playfair
  ?node <- (status (search-depth ?num)
                   (ic ?ic)
		   (type unknown))
  (test (= ?num 3))		;;3rd level of tree
  (test (> ?ic .0455))
  (test (< ?ic .058)) 
 =>
  (duplicate ?node (search-depth (+ 1 ?num)) 
                   (parent ?node)
                   (type known)
                   (last-move Playfair))
)

(defrule MAIN::move-to-vigenere
  ?node <- (status (search-depth ?num)
                   (ic ?ic)
		   (type unknown))
  (test (= ?num 3))		;;3rd level of tree
  (test (<= ?ic .0455))
  =>
  (duplicate ?node (search-depth (+ 1 ?num)) 
                   (parent ?node)
                   (type known)
                   (last-move Vigenere))
)

(defrule MAIN::move-to-transposition
  ?node <- (status (search-depth ?num) 
                   (shift ?shift)
		   (ic ?ic)
		   (type unknown))
  (test (= ?num 1))		;;1st level of tree
  (test (= ?shift 0))
  =>
  (duplicate ?node (search-depth (+ 1 ?num))
                   (parent ?node)
                   (type known)
                   (last-move Transposition))
 ;; (printout t crlf ?ic crlf)
)


;;;*********************************
;;;* FIND AND PRINT SOLUTION RULES *
;;;*********************************

(defmodule SOLUTION)
       
(deftemplate SOLUTION::moves 
   (slot id)
   (multislot moves-list)
)


(defrule SOLUTION::recognize-cipher 
  (declare (auto-focus TRUE))
  ?node <- (status (parent ?parent)
                   (type known) 
                   (last-move ?cipher))
  =>
  (retract ?node)
  (assert (moves (id ?parent) (moves-list ?cipher)))
)


(defrule SOLUTION::further-solution 
  ?node <- (status (parent ?parent)
                   (last-move ?move))
  ?mv <- (moves (id ?node) (moves-list $?rest))
  =>
  (modify ?mv (id ?parent) (moves-list ?move ?rest))
)


(defrule SOLUTION::print-solution 
  ?mv <- (moves (id no-parent) (moves-list no-move $?m))
  =>
  (retract ?mv)
  (printout t crlf "Solution found: " crlf crlf)
  (bind ?length (length$ ?m))
  (bind ?i 1)

  ;;go through each node and print cipher decision
  (while (<= ?i ?length)
     (bind ?thing (nth$ ?i ?m))
	(if (eq ?i ?length)	;;if it is the last node, print and set cipher
	    then (printout t "Cipher is " ?thing " cipher" crlf crlf)
		 (bind ?cipher (fetch cipher))
  		 (call ?cipher setCipher ?thing)
	    else (printout t "Move to " ?thing " ciphers" crlf))
     (bind ?i (+ 1 ?i)))
)

(reset)
(run)
