package DialML;

import alice.tuprolog.*;

import java.util.*;

public class World {

  private Vector people;
  private AgentCog master,student,createur;

  public Vector getPeople() {
    return people;
  }

  public World() {
    people=new Vector();
    master=new AgentCog("Violaine",this);
    student=new AgentCog("Mehdi",this);
    createur=new AgentCog("Créateur",this);

    master.setMaster(createur);
    master.setStudent(student);
    student.setMaster(createur);
    educateAgents();

    student.setMaster(master);

    people.addElement(master);
    people.addElement(student);
  }

  public static void main(String[] args) {
    World world = new World();
    world.startsLife();
  }

  private void startsLife() {
    student.start();
    master.start();
  }

  private void educateAgents() {
    try {
      master.learnImplic(new Struct("humain", new Var("X")),
                         new Struct("mortel", new Var("X")));
      master.learnImplic(new Struct("humain", new Var("X")),
                         new Struct("intelligent", new Var("X")));
      master.learnImplic(new Struct("mortel", new Var("X")),
                         new Struct("vivant", new Var("X")));
      master.learnImplic(new Struct("tuable", new Var("X")),
                          new Struct("vivant", new Var("X")));
      master.learnImplic(new Struct("vivant", new Var("X")),
                         new Struct("reproduit", new Var("X")));
//      master.learnImplic(new Struct("humain", new Var("X")),
//                         new Struct("not",new Struct("mortel", new Var("X"))));
      master.learnFact(new Struct("humain", new Struct("socrate")));

      master.learnFact(new Struct("humain", new Struct("jean")));

      master.learnImplic(new Struct("not",new Struct("femme",new Var("X"))),
                         new Struct("humain", new Var("X")));

      master.addImplicToTeach(new Struct("humain", new Var("X")),
                              new Struct("mortel", new Var("X")));

//      master.addImplicToTeach(new Struct("humain", new Var("X")),
//                              new Struct("reproduit", new Var("X")));
      master.addFactToTeach(new Struct("reproduit", new Struct("jean")));

//      master.addImplicToTeach(new Struct("humain", new Var("X")),
//                              new Struct("not",new Struct("reproduit", new Var("X"))));

      student.learnImplic(new Struct("humain", new Var("X")),
                          new Struct("tuable", new Var("X")));
      student.learnImplic(new Struct("tuable", new Var("X")),
                          new Struct("vivant", new Var("X")));
      student.learnImplic(new Struct("vivant", new Var("X")),
                          new Struct("not",new Struct("reproduit", new Var("X"))));
      student.learnFact(new Struct("humain", new Struct("paul")));
      student.learnFact(new Struct("humain", new Struct("jean")));

//      System.out.println(">>>"+VectTheory.getPrologVectData(
//          student.getPath(new Struct("humain", new Var("X")),
//                          new Struct("reproduit", new Var("X"))))+"<<<");
    }
    catch (InvalidVarNameException ivne) {
    }
  }

  // envoie d'un message à un autre agent
  public void sendMsg(AgentCog ac, int info_type, Object o) {
    ac.getData(info_type,o);
  }
}