中国DOS联盟论坛

中国DOS联盟

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

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

游客:  注册 | 登录 | 命令行 | 会员 | 搜索 | 上传 | 帮助 »
中国DOS联盟论坛 » DOS开发编程 & 发展交流 (开发室) » 一个bc 3 下的AI程序,不过运行不了,请帮忙
作者:
标题: 一个bc 3 下的AI程序,不过运行不了,请帮忙 上一主题 | 下一主题
yangwenli
初级用户




积分 149
发帖 13
注册 2003-11-27
状态 离线
『楼 主』:  一个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[MAX][80];
char token[80];
char *p_pos;
int res=0;
int head=0;
int tail=0;

/* creat the doctor's response */
respond (char *s)
{
    char t[80];
    int loc;
    if (strlen(s)SHORT) assert_topic(s);
    do {
       get_token();
       loc=lookup(token);
       if (loc!=-1)  {
          printf ("%s\n",trans[loc+1]);
          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[t])  {
          if (!strcmp (trans[t],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[head],t);
    head++;
}

/* retrieve a topic  */
find_topic (char *t)
{
    if (tail!=head)  {
       strcpy(t,topics[tail]);
       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[t]))  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[80];
     printf ("%s\n",response[res++]);
     do {
        printf (":";
        p_pos=s;
        gets (s);
        respond (s);
     } while (strcmp(s,"bye");
}

2003-11-29 00:00
查看资料  发送邮件  发短消息 网志   编辑帖子  回复  引用回复
yangwenli
初级用户




积分 149
发帖 13
注册 2003-11-27
状态 离线
『第 2 楼』:  

对不起,搞错了,这是TC版的,而且,可以运行的

2003-11-29 00:00
查看资料  发送邮件  发短消息 网志   编辑帖子  回复  引用回复

请注意:您目前尚未注册或登录,请您注册登录以使用论坛的各项功能,例如发表和回复帖子等。


可打印版本 | 推荐给朋友 | 订阅主题 | 收藏主题



论坛跳转: