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; }
int main() { #ifdef _DEBUG // When we have a memory leak, set this variable to // the allocation number (e.g. 122) and then we'll break // when that allocation occurs. //_crtBreakAlloc = 17366 ; _CrtSetDbgFlag ( _CRTDBG_ALLOC_MEM_DF | _CRTDBG_LEAK_CHECK_DF ); #endif // _DEBUG { // create local scope to allow for local memory cleanup before we check at end // // create the test data // DataList* dataList = CreateEventTestData(); // // set up Soar // Kernel* kernel = Kernel::CreateKernelInNewThread(); Agent* agent = kernel->CreateAgent("Soar1"); RegisterForEvents(kernel, agent, dataList); // Load up TOH as a base set of rules. // Comment this out if we don't want any initial set of rules. //cout << kernel->ExecuteCommandLine("source ..\\..\\SoarLibrary\\Demos\\towers-of-hanoi\\towers-of-hanoi.soar", agent->GetAgentName()) << endl ; // // let the user do whatever they want // string command; do { cout << agent->GetAgentName() << "> "; getline(cin, command); // check for special commands if(command == "reset") { ResetEventCounts(dataList); cout << "counts reset" << endl; } else if(!command.compare(0, 6, "counts")) { string type = ""; if(command != "counts") { type = command.substr(7,command.length()-7); } PrintEventData(dataList, type); } else { cout << kernel->ExecuteCommandLine(command.c_str(), agent->GetAgentName()) << endl; } } while( (command != "quit") && (command != "exit") ); kernel->Shutdown(); delete kernel; // // Show results // PrintEventData(dataList); //string dummy; //cout << endl << endl << "Press any key and enter to continue"; //cin >> dummy; // // clean up // for(DataList::iterator i = dataList->begin(); i != dataList->end(); i++) { delete (*i); } delete dataList; } // end local scope return 0; }