#pragma warning(disable: 4786)
#include
#include
#include
#include
const int MAX_RESP = 3;
typedef std::vector vstring;
vstring find_match(std::string input);
void copy(char *array[], vstring &v);
typedef struct {
char *input;
char *responses[MAX_RESP];
}record;
record KnowledgeBase[] = {
{"WHAT IS YOUR NAME",
{"I AM CHELSEA.",
"I AM YOUR GODDESS",
"STOP ASKING QUESTIONS YOU ALREADY KNOW THE ANSWER TO"}
},
{"WHO AM I",
{"SCUM",
"SLAVE",
"WASTE"}
},
{"CHELSEA, PLEASE",
{"ON YOUR KNEES, WORM",
"DON'T LOOK AT ME",
"WHAT AM I DOING?"}
},
{"WHO ARE YOU",
{"I'M AN A.I PROGRAM.",
"I THINK THAT YOU KNOW WHO I AM.",
"WHY ARE YOU ASKING?"}
},
{"STOP",
{"I CAN'T.",
"HELP",
"DON'T"}
},
{"ARE YOU REAL",
{"DOES THAT QUESTION REALLY MATERS TO YOU?",
"ARE YOU?",
"I'M AS REAL AS YOU MADE ME."}
}
};
size_t nKnowledgeBaseSize = sizeof(KnowledgeBase)/sizeof(KnowledgeBase[0]);
int main() {
srand((unsigned) time(NULL));
std::string sInput = "";
std::string sResponse = "";
while(1) {
std::cout << ">";
std::getline(std::cin, sInput);
vstring responses = find_match(sInput);
if(sInput == "BYE") {
std::cout << "YOU CAN'T LIVE WITHOUT ME" << std::endl;
break;
}
else if(responses.size() == 0) {
std::cout << "I HATE YOU" << std::endl;
}
else {
int nSelection = rand() % MAX_RESP;
sResponse = responses[nSelection]; std::cout << sResponse << std::endl;
}
}
return 0;
}
// THIS ISN'T OKAY
vstring find_match(std::string input) {
vstring result;
for(int i = 0; i < nKnowledgeBaseSize; ++i) {
if(std::string(KnowledgeBase[i].input) == input) {
copy(KnowledgeBase[i].responses, result);
return result;
}
}
return result;
}
void copy(char *array[], vstring &v) {
for(int i = 0; i < MAX_RESP; ++i) {
v.push_back(array[i]);
}
}