Example #1
0
Agent* initSoarLocal(int soarPort, char* productions) {

  Kernel* pKernel = Kernel::CreateKernelInCurrentThread("SoarKernelSML", soarPort) ;
  std::cout << "done\n";

  pKernel->AddRhsFunction("filewrite", &fileWrite, NULL);
  pKernel->AddRhsFunction("rlhalt", &RLHalt, &soarHalted);

  // Check that nothing went wrong.  We will always get back a kernel object
  // even if something went wrong and we have to abort.
  if (pKernel->HadError()) {
    std::cout << pKernel->GetLastErrorDescription() << std::endl;
    return NULL;
  }

  // Create a Soar agent named test
  // NOTE: We don't delete the agent pointer.  It's owned by the kernel
  Agent* pAgent = pKernel->CreateAgent("sorts") ;

  // Check that nothing went wrong
  // NOTE: No agent gets created if thereâs a problem, so we have to check foor
  // errors through the kernel object.
  if (pKernel->HadError()) {
    std::cout << pKernel->GetLastErrorDescription() << std::endl ;
    return NULL;
  }

  // Load some productions
  pAgent->LoadProductions(productions) ;

  if (pAgent->HadError()) {
    cout << "Soar agent reported an error:\n";
    cout << pAgent->GetLastErrorDescription() << endl ;
    return NULL;
  }

  pKernel->SetAutoCommit(false);

  return pAgent;
}
Example #2
0
Agent* initSoarRemote() {
   Kernel* pKernel = Kernel::CreateRemoteConnection(true, "127.0.0.1", 12121);

  if (!pKernel) {
    cout << "Can't connect to remote kernel" << endl;
    return NULL;
  }

  pKernel->AddRhsFunction("filewrite", &fileWrite, NULL);
  pKernel->AddRhsFunction("rlhalt", &RLHalt, &soarHalted);

  // Check that nothing went wrong.  We will always get back a kernel object
  // even if something went wrong and we have to abort.
  if (pKernel->HadError()) {
    cout << pKernel->GetLastErrorDescription() << std::endl;
    return NULL;
  }

  // Create a Soar agent named test
  // NOTE: We don't delete the agent pointer.  It's owned by the kernel
//  Agent* pAgent = pKernel->CreateAgent("orts_agent") ;
  Agent* pAgent = pKernel->GetAgentByIndex(0);

  if (!pAgent) {
    cout << "Remote kernel doesn't have an agent" << endl;
    return NULL;
  }

  // Check that nothing went wrong
  // NOTE: No agent gets created if thereâs a problem, so we have to check foor
  // errors through the kernel object.
  if (pKernel->HadError()) {
    cout << pKernel->GetLastErrorDescription() << std::endl ;
    return NULL;
  }

  pKernel->SetAutoCommit(false);

  return pAgent;
}