中国DOS联盟论坛

中国DOS联盟

-- 联合DOS 推动DOS 发展DOS --
联盟域名:www.cn-dos.net 论坛域名:www.cn-dos.net/forum
游客 | 登录 | 注册 | 会员 | 搜索 | 中国DOS联盟
中国DOS联盟论坛
现在时间是 2026-09-15 04:56
47,812 主题排行 / 349,917 发帖 / 今日 0 篇 / 48,268 会员排行
DOS开发编程 & 发展交流 (开发室) » 一个bc 3 下的AI程序,不过运行不了,请帮忙
可打印版本  871 / 1
第1楼 yangwenli 发表于 2003-11-29 00:00
初级用户 发帖 13 积分 149
一个bc 3 下的AI程序,不过运行不了,请帮忙
#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楼 yangwenli 发表于 2003-11-29 00:00
初级用户 发帖 13 积分 149
对不起,搞错了,这是TC版的,而且,可以运行的
[ 联系联盟系统管理团队 - 中国DOS联盟 - 标准版 ]
Sponsored by ifanr Inc | © 2001–2023