中国DOS联盟

-- 联合DOS 推动DOS 发展DOS --

联盟域名:www.cn-dos.net 论坛域名:www.cn-dos.net/forum
DOS,代表着自由开放与发展,我们努力起来,学习FreeDOS和Linux的自由开放与GNU精神,共同创造和发展美好的自由与GNU GPL世界吧!

中国DOS联盟论坛
现在时间是 2026-08-01 03:34
中国DOS联盟论坛 » DOS开发编程 & 发展交流 (开发室) » 一个bc 3 下的AI程序,不过运行不了,请帮忙 查看 773 回复 1
楼 主 一个bc 3 下的AI程序,不过运行不了,请帮忙 发表于 2003-11-29 00:00 ·  中国 香港 亚太环通(Pacnet)有限公司
初级用户
积分 149
发帖 13
注册 2003-11-27 00:00
22年会员
UID 13458
性别 男
状态 离线
#include
#define MAX 100
#define SHORT 10
#define VERYSHORT 2
char *response= {
"How are you this beautiful day ?",
"Did you have a happy childhood ?",
"Did you hate your father ?",
"Did you have a good friend ?",
"Did you like your friend ?",
"What do you think about your friendship ?",
"I'm not sure I understand .",
""
};
char *trans={
"no","Tell me more about the detail .",
"yes","Tell me more about the detail .",
"fuck","Don't be so rude again !",
"shet","Don't be so rude again !",
"you","Let't not talk about me .",
"think","Why do you think that ?",
"hate","So you hate something -- tell me more .",
"what","Why do you ask ?",
"want","Why do you want that ?",
"need","We all need many things -- is this special ?",
"why","Remember,therapy is good for you .",
"know","How do you know that ?",
"bye","Your bill will be mailed to you .",
"murder","I don't like killing .",
"kill","It is wrong to kill .",
"jerk","Don't ever call me a jerk !",
"can't","Don't be negative -- be positive .",
"failure","Strive for success .",
"never","Don't be negative -- be positive .",
"unhappy","Why are you unhappy ?",
"beautiful","I'm sure you like her,don't you ?",
"like","Why do you like that?",
"love","Remember,love everthing what you love .",
""
};
char topics;
char token;
char *p_pos;
int res=0;
int head=0;
int tail=0;

/* creat the doctor's response */
respond (char *s)
{
char t;
int loc;
if (strlen(s)SHORT) assert_topic(s);
do {
get_token();
loc=lookup(token);
if (loc!=-1) {
printf ("%s\n",trans);
return ;
}
} while (*token);
/* comment of last resort */
if (strlen(s)>SHORT)
printf ("It's seem intersting , tell me more ...\n";
else printf ("Tell me more ...\n";
}

/* Lookup a keyword in translation table */
lookup (char *token)
{
int t;
t=0;
while (*trans) {
if (!strcmp (trans,token)) return t ;
t++;
}
return -1;
}

/* place a topic into the topics database */
assert_topic (char *t)
{
if (head==MAX) head=0; /* wrap around */
strcpy(topics,t);
head++;
}

/* retrieve a topic */
find_topic (char *t)
{
if (tail!=head) {
strcpy(t,topics);
tail++;
/* wrap around if necessary */
if (tail==MAX) tail=0;
return 1;
}
return 0;
}

/* see if in topics queue */
in_topics (char *s)
{
int t;
for (t=0;t<MAX;t++)
if (!strcmp(s,topics)) return 1;
return 0;
}

/* return a token from the input stream */
get_token ()
{
char *p;
p=token;
/* skip spaces */
while (*p_pos==' ' p_pos++;

if (*p_pos=='\0' { /*is end of input*/
*p++='\0 ';
return;
}
if (is_in(*p_pos,".!?") {
*p=*p_pos;
p++,p_pos++;
*p='\0';
return ;
}

/*read word until*/
while(*p_pos!=' '&&!is_in(*p_pos,".,;?!"&&*p_pos) {
*p=tolower(*p_pos++);
p++;
}
*p='\0';
}

is_in(char c,char *s)
{
while(*s) {
if(c==*s) return 1;
s++;
}
return 0;
}

main ()
{
char s;
printf ("%s\n",response);
do {
printf (":";
p_pos=s;
gets (s);
respond (s);
} while (strcmp(s,"bye");
}
2 发表于 2003-11-29 00:00 ·  中国 香港 亚太环通(Pacnet)有限公司
初级用户
积分 149
发帖 13
注册 2003-11-27 00:00
22年会员
UID 13458
性别 男
状态 离线
对不起,搞错了,这是TC版的,而且,可以运行的
论坛跳转: