Created
December 30, 2025 10:10
-
-
Save nogajun/34b9feaa748de84c67c6005a47e05b00 to your computer and use it in GitHub Desktop.
人工無脳くるみちゃんのソースコード。作者さんがNoteで公開されていますがNoteでは見づらいのでgistに貼ってます https://note.com/dahony/n/n38068f13a218
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /* $/s /0$ */ | |
| /******************************* | |
| * * | |
| * 「くるみちゃん」 Ver1.35 * | |
| * (¥ai¥kurumi3.c)* | |
| * by ********(DAHO)* | |
| * * | |
| * 88/07/08* | |
| ****************************** | |
| */ | |
| #include <dos.h> | |
| #include <stdio.h> | |
| #include <stdlib.h> | |
| #include <time.h> | |
| #include <jctype.h> | |
| #include <jstring.h> | |
| /* 型の定義 */ | |
| typedef struct | |
| { | |
| int first; | |
| int end; | |
| int name; | |
| int gree01; | |
| int gree02; | |
| int gree03; | |
| int touroku; | |
| int totsuzen; | |
| int loop; | |
| int ne; | |
| int otoboke; | |
| int quest[10]; | |
| int dayo; | |
| int gree11; | |
| int gree12; | |
| } posstyp; | |
| /* 関数のプロトタイプ宣言 */ | |
| FILE *file_open(char *file_name,char *type); /* ファイルのオープン(R31) */ | |
| void file_close(FILE *fileptr); /* ファイルのクローズ(R32) */ | |
| void set_poss(posstyp *poss); /* 確率値の設定(R1) */ | |
| void title(void); /* タイトル表示(R2) */ | |
| int seek_name(char *names,posstyp *poss); /* 名前の検索(R3) */ | |
| char *greeting(posstyp *poss); /* あいさつ(R4) */ | |
| int kurumi_thinking(char *answers,char *inputs,posstyp *poss,char *gobi); | |
| /*くるみちゃん思考(R5)*/ | |
| int totsuzen(char *answers,posstyp *poss); /* 突然とぼける(R51) */ | |
| int tango_bunkai(char *tango,char *inputs); /* 単語抽出(R52) */ | |
| int disk_seek(char *answers,char *tango,posstyp *poss); /*単語検索(R53)*/ | |
| int question(char *answers,int loopflg,posstyp *poss); /* 質問変換(R54) */ | |
| int tokusyutango(char *answers,posstyp *poss); /* 特殊単語変換(R55) */ | |
| char *greeting1(posstyp *poss); /* さよなら用あいさつ(R6) */ | |
| int set_color(char *kurucol,char *usercol); | |
| /* カラーコードを辞書から読み込む(R7) */ | |
| int set_name(char *kuruname); /* 名前を辞書から読み込む(R8) */ | |
| main() /* 「くるみちゃん」メイン(R0) */ | |
| { | |
| char names[256]; /* 名前 */ | |
| char inputs[256]; /* 入力文字 */ | |
| char answers[96]; /* くるみちゃんの答え */ | |
| char answers1[96]; /* くるみちゃんの答えから助詞を削除した文字 */ | |
| int firstflg; /* はじめてか?フラグ */ | |
| int endflg = 0; /* 終了か?フラグ */ | |
| posstyp poss; /* 確率の構造体 */ | |
| char kurucol[5] = "36"; /* くるみちゃんの色 */ | |
| char usercol[5] = "37"; /* ゆーざーのいろ */ | |
| char kuruname[16] = "くるみちゃん"; | |
| char gobi[16] = "ね"; | |
| randomize(); /* 乱数の初期化 */ | |
| set_poss(&poss); /* 確率値の設定(R1) */ | |
| title(); /* タイトル表示(R2) */ | |
| set_color(kurucol,usercol); /* カラーコードを辞書から読み込む(R7) */ | |
| set_name(kuruname); /* 名前を辞書から読み込む(R8) */ | |
| set_gobi(gobi); /* 語尾を辞書から読み込む(R9) */ | |
| printf("\x1b[%sm名前は?\x1b[m",kurucol); | |
| gets(names); /* 名前の入力 */ | |
| names[40]=0; | |
| if(names[0]==0) | |
| { | |
| printf("\x1b[%sm%s:ななしの ごんべえさんね\x1b[m\n",kurucol,kuruname); | |
| strcpy(names,"ななしのごんべえ"); | |
| firstflg=0; | |
| } /* then */ | |
| else | |
| { | |
| firstflg=seek_name(names,&poss); /* 名前の検索(R3) */ | |
| } /* if */ | |
| if((firstflg==0) && (random(100)>=poss.first)) | |
| { | |
| printf("\x1b[%sm%s:%s\x1b[m\n",kurucol,kuruname,greeting(&poss)); | |
| /* あいさつ(R4) */ | |
| } /* then */ | |
| else | |
| { | |
| printf("\x1b[%sm%s:はじめまして\x1b[m\n",kurucol,kuruname); | |
| } /* if */ | |
| while(endflg==0) | |
| { | |
| printf("\x1b[%sm%s:",usercol,names); | |
| gets(inputs); /* 文字入力 */ | |
| inputs[92]=0; | |
| kurumi_thinking(answers,inputs,&poss,gobi); /*くるみちゃん思考(R5)*/ | |
| strcpy(answers1,answers); | |
| joshi2(answers1); /* 助詞を削除「文末」(R523) */ | |
| if(strcmp("終了",answers1)==0) | |
| { | |
| if(random(100)<poss.end) | |
| { | |
| endflg=1; | |
| strcpy(answers,greeting1(&poss)); /* さよなら用あいさつ(R6) */ | |
| } /* then1 */ | |
| else | |
| { | |
| strcpy(answers,"やめないでぇ"); | |
| } /* if1 */ | |
| } /* if */ | |
| printf("\x1b[%sm%s:%s\x1b[m\n",kurucol,kuruname,answers); | |
| } /* while */ | |
| puts(" "); | |
| } /* main */ | |
| void set_poss(posstyp *poss) /* 確率値の設定(R1) */ | |
| { | |
| (poss->first) = 10; /* 「はじめまして」と、とぼける確率(R0) */ | |
| (poss->end) = 90; /* 終了できる確率(R0) */ | |
| (poss->name) = 95; /* 名前を登録する確率(R3) */ | |
| (poss->gree01) = 40; /* 「おはよう」確率(R4) */ | |
| (poss->gree02) = 70; /* 「こんにちは」確率(R4) */ | |
| (poss->gree03) = 70; /* 「こんばんは」確率(R4) */ | |
| (poss->touroku) = 80; /* 単語を登録する確率(R5) */ | |
| (poss->totsuzen)= 1; /* 突然とぼける確率(R5) */ | |
| (poss->loop) = 35; /* ループする確率(R5) */ | |
| (poss->ne) = 60; /* ”ね”の率(R5) */ | |
| (poss->otoboke) = 20; /* 知ってる単語をとぼける確率(R53) */ | |
| (poss->quest[0])= 7; /* しつもんの個数(R54) */ | |
| (poss->quest[1])= 30; /* かくしつもんのかくりつ(R54) */ | |
| (poss->quest[2])= 50; | |
| (poss->quest[3])= 60; | |
| (poss->quest[4])= 70; | |
| (poss->quest[5])= 80; | |
| (poss->quest[6])= 90; | |
| (poss->quest[7])=100; | |
| (poss->dayo) = 40; /* 「だよ」の確率(R55) */ | |
| (poss->gree11) = 50; /* 「またねぇ」の確率(R6) */ | |
| (poss->gree12) = 60; /* 「おやすみぃ」の確率(R6) */ | |
| } /* set_poss */ | |
| void title(void) /* タイトル表示(R2) */ | |
| { | |
| puts("\x1b[2J"); | |
| puts("「くるみちゃん」 ばーじょん1.35 \n"); | |
| puts("にゅうりょくは ぜんかくで "); | |
| puts("ぶんせつごとに くぎりを にゅうりょくしてくださいね"); | |
| puts("「ばいばい」と にゅうりょくすれば ぬけられます。\n"); | |
| } /* title */ | |
| int seek_name(char *names,posstyp *poss) /* 名前の検索(R3) */ | |
| { | |
| FILE *fileptr; /* ふぁいるぽいんたぁ */ | |
| char readdta[144]; /* りーど でぇたぁ */ | |
| char id; /* でぇたぁのあいでぃ */ | |
| char *charptr; /* ちゃーぽいんたぁ */ | |
| fileptr=file_open("kurumi3.dic","r+t"); /* ファイルのオープン(R31) */ | |
| while(feof(fileptr)==0) | |
| { | |
| fgets(readdta,142,fileptr); /* でいすくから でぇたぁ にゅうりょく */ | |
| id=readdta[0]; /* でいたあの あいでい (2なら なまえ) */ | |
| if(id=='2') | |
| { | |
| charptr=(char*)strchr(&readdta[2],':'); | |
| if(charptr!=0) | |
| { | |
| *charptr=0; /* ":"のところをnullにしちゃう */ | |
| if(strcmp(&readdta[2],names)==0)/*&readdta[2]はなまえのでぇたをしめす*/ | |
| { | |
| file_close(fileptr); /* ファイルのクローズ(R32) */ | |
| return(0); /* firstflg=false */ | |
| } /* if2 */ | |
| } /* if1 */ | |
| } /* if */ | |
| } /* while */ | |
| if(random(100)<(poss->name)) | |
| { | |
| fprintf(fileptr,"2:%s:0\n\x1a",names); /* なまえのとうろくだよ */ | |
| } /* if */ | |
| file_close(fileptr); /* ファイルのクローズ(R32) */ | |
| return(1); /* firstflg=true */ | |
| } /* seek_name */ | |
| FILE *file_open(char *file_name,char *type) /* ファイルのオープン(R31) */ | |
| { | |
| static FILE *fileptr; | |
| char ch; | |
| if(strcmp(type,"at")==0) | |
| { | |
| printf("\x07\x1b[31mCan not use type\"at\" in open\x1b[m"); | |
| exit(1); /* えらあだぞっと */ | |
| } | |
| if(strcmp(type,"a+t")==0) | |
| { | |
| fileptr=fopen(file_name,"r+t"); | |
| if(fileptr==0) | |
| { | |
| printf("\x07\x1b[31mError in fopen\x1b[m"); | |
| exit(1); /* えらあだよぉ */ | |
| } /* if */ | |
| while(feof(fileptr)==0) | |
| { | |
| fgetc(fileptr); | |
| } /* while */ | |
| } /* then */ | |
| else | |
| { | |
| fileptr=fopen(file_name,type); | |
| if(fileptr==0) | |
| { | |
| printf("\x07\x1b[31mError in fopen\x1b[m"); | |
| exit(1); /* えらあなんだなぁ */ | |
| } /* if */ | |
| } /* if */ | |
| return(fileptr); | |
| } /* file_open */ | |
| void file_close(FILE *fileptr) /* ファイルのクローズ(R32) */ | |
| { | |
| int err; | |
| err=fclose(fileptr); | |
| if(err!=0) | |
| { | |
| printf("\x07\x1b[31mError in fclose\x1b[m"); | |
| exit(1); /* やあい、えらあ えらあ */ | |
| } /* if */ | |
| } /* file_close */ | |
| char *greeting(posstyp *poss) /* あいさつ(R4) */ | |
| { | |
| struct time now; | |
| gettime(&now); /* じこくの よみだし */ | |
| if((now.ti_hour>=5)&&(now.ti_hour<=10)) /* あさ、あさ、あかるいあさ */ | |
| { | |
| if(random(100)<(poss->gree01)) | |
| { | |
| return("おはよう"); | |
| } /* then1 */ | |
| else | |
| { | |
| return("おっはよぉ"); | |
| } /* if1 */ | |
| } /* then */ | |
| else | |
| { | |
| if((now.ti_hour>=11)&&(now.ti_hour<=18)) /* おひる */ | |
| { | |
| if(random(100)<(poss->gree02)) | |
| { | |
| return("こんにちはぁ"); | |
| } /* then2 */ | |
| else | |
| { | |
| return("はろう"); | |
| } /* if2 */ | |
| } /* then1 */ | |
| else | |
| { | |
| if(random(100)<(poss->gree03)) | |
| { | |
| return("こんばんはぁ"); | |
| } /* then2 */ | |
| else | |
| { | |
| return("はろう"); | |
| } /* if2 */ | |
| } /* if1 */ | |
| } /* if */ | |
| } /* greeting */ | |
| char *greeting1(posstyp *poss) /* さよなら用あいさつ(R6) */ | |
| { | |
| struct time now; | |
| gettime(&now); | |
| if((now.ti_hour>=5)&&(now.ti_hour<=21)) /* おひる、おひる */ | |
| { | |
| if(random(100)<(poss->gree11)) /* 「またねぇ」の確率 */ | |
| { | |
| return("またねぇ"); | |
| } /* then1 */ | |
| else | |
| { | |
| return("ばいばぁい"); | |
| } /* if1 */ | |
| } /* then */ | |
| else | |
| { | |
| if(random(100)<(poss->gree12)) /* 「おやすみぃ」の確率 */ | |
| { | |
| return("おやすみぃ"); | |
| } /* then1 */ | |
| else | |
| { | |
| return("ばいばぁい"); | |
| } /* if1 */ | |
| } /* if */ | |
| } /* greeting1 */ | |
| int kurumi_thinking(char *answers,char *inputs,posstyp *poss,char *gobi) | |
| /*くるみちゃん思考(R5)*/ | |
| { | |
| static int tourokuflg = 0; | |
| FILE *fileptr; | |
| int loopflg = 0; | |
| static char tango[40]; | |
| zenkaku(inputs); /* 半角を全角に変換(R56) */ | |
| if((tourokuflg!=0) | |
| &&(random(100)<(poss->touroku)) /* 単語を登録する確率 */ | |
| &&(inputs[0]!=0)) | |
| { | |
| fileptr=file_open("kurumi3.dic","a+t"); /* ファイルのオープン */ | |
| fprintf(fileptr,"1:%s:%s\n\x1a",tango,inputs); /* 単語の登録 */ | |
| file_close(fileptr); /* ファイルのクローズ */ | |
| } /* if */ | |
| tourokuflg=0; | |
| if(random(100)<(poss->totsuzen)) /* 突然とぼける確率 */ | |
| { | |
| totsuzen(answers,poss); /* 突然とぼける(R51) */ | |
| return(0); | |
| } /* if */ | |
| do | |
| { | |
| tango_bunkai(tango,inputs); /* 単語抽出(R52) */ | |
| if(strlen(tango)==0) | |
| { | |
| strcpy(answers,"なんかいってよぉ"); | |
| loopflg=0; | |
| return(0); | |
| } /* then */ | |
| if(strlen(tango)>=32) | |
| { | |
| strcpy(answers,"ぶんせつごとに くぎりを いれてぇ"); | |
| loopflg=0; | |
| return(0); | |
| } /* then1 */ | |
| else | |
| { | |
| disk_seek(answers,tango,poss); /* 単語検索(R53) */ | |
| if(strlen(answers)==0) | |
| { | |
| tourokuflg=1; /* これはねぇ とうろくふらぐが おんなんだよぉ */ | |
| strcpy(answers,tango); | |
| question(answers,loopflg,poss); /* 質問変換(R54) */ | |
| return(0); /* ぬけるぅ */ | |
| } /* then2 */ | |
| else | |
| { | |
| if(random(100)<(poss->loop)) /* ループする確率 */ | |
| { | |
| loopflg=1; | |
| strcpy(inputs,answers); | |
| } /* then3 */ | |
| else | |
| { | |
| loopflg=0; | |
| if((random(100)<(poss->ne)) /* ”ね”の確率 */ | |
| &&(strstr(answers,"?")==0) | |
| &&(strstr(answers,"!")==0) | |
| &&(strcmp(&answers[strlen(answers)-2],"ね")!=0)) | |
| { | |
| strcat(answers,gobi); | |
| } /* if4 */ | |
| } /* if3 */ | |
| } /* if2 */ | |
| } /* if1 */ | |
| } /* do */ | |
| while(loopflg!=0); | |
| tokusyutango(answers,poss); /* 特殊単語変換(R55) */ | |
| } /* kurumi_thinking */ | |
| int totsuzen(char *answers,posstyp *poss) /* 突然とぼける(R51) */ | |
| { | |
| char totsuzen[96] = "とつぜんだけどぉ、"; | |
| switch(random(11)) /* ****くんの あいであだよ */ | |
| { | |
| case 0 : strcpy(answers,"とつぜんだけどぉ、人生ってなんだろう…"); break; | |
| case 1 : strcpy(answers,"とつぜんだけどぉ、むなしい…"); break; | |
| case 2 : strcpy(answers,"ここはどこ? 私はだ~れ?"); break; | |
| case 3 : strcpy(answers,"とつぜんだけどぉ、おなかすいたぁ"); break; | |
| case 4 : strcpy(answers,"とつぜんだけどぉ、のどかわいたぁ"); break; | |
| case 5 : strcpy(answers,"とつぜんだけどぉ、「くるみちゃん」の さくしゃは だほさんでぃす"); break; | |
| case 6 : strcpy(answers,"辞書"); | |
| tokusyutango(answers,poss); /* 特殊単語変換(R55) */ | |
| strcat(totsuzen,answers); | |
| strcpy(answers,totsuzen); | |
| break; | |
| case 7 : strcpy(answers,"時間"); | |
| tokusyutango(answers,poss); /* 特殊単語変換(R55) */ | |
| strcat(totsuzen,answers); | |
| strcpy(answers,totsuzen); | |
| break; | |
| case 8 : strcpy(answers,"挨拶"); | |
| tokusyutango(answers,poss); /* 特殊単語変換(R55) */ | |
| strcat(totsuzen,answers); | |
| strcpy(answers,totsuzen); | |
| break; | |
| case 9 : strcpy(answers,"曜日"); | |
| tokusyutango(answers,poss); /* 特殊単語変換(R55) */ | |
| strcat(totsuzen,answers); | |
| strcpy(answers,totsuzen); | |
| break; | |
| case 10: strcpy(answers,"日付"); | |
| tokusyutango(answers,poss); /* 特殊単語変換(R55) */ | |
| strcat(totsuzen,answers); | |
| strcpy(answers,totsuzen); | |
| break; | |
| } /* switch */ | |
| } /* totsuzen */ | |
| int tango_bunkai(char *tango,char *inputs) /* 単語抽出(R52) */ | |
| { | |
| char tangos[16][64]; /* 入力を文節に分解 */ | |
| int tango_no = 0; /* たんごなんばぁ */ | |
| char *charptr; /* ちゃぁぽいんたぁ(たんごのあたま) */ | |
| char *charptr1; /* ちゃぁぽいんたぁ(たんごのうしろ) */ | |
| int rnd; /* らんすうの あたいだよん */ | |
| strcat(inputs," "); | |
| kuguri(inputs); /* 区切りを入れる(R521) */ | |
| renzokumoji(inputs); /* 連続文字削除”ぁぃぅぇぉっー~”(R522) */ | |
| charptr=inputs; | |
| do | |
| { | |
| charptr1=(char*)strchr(charptr,' '); | |
| *charptr1=0; | |
| strcpy(tangos[tango_no],charptr); | |
| charptr=charptr1+1; | |
| if(strlen(tangos[tango_no])!=0) | |
| { | |
| tango_no++; | |
| } /* if */ | |
| } /* do */ | |
| while((*charptr!=0)&&(tango_no<=16)); | |
| if(tango_no>0) /* たんごすうが0でないなら */ | |
| { | |
| rnd=random(tango_no); | |
| strcpy(tango,tangos[rnd]); /* たんごをらんすうでけってい */ | |
| if(rnd==tango_no-1) | |
| { | |
| joshi2(tango); /* 文末助詞削除(R523) */ | |
| } /* then1 */ | |
| else | |
| { | |
| joshi1(tango); /* 助詞削除(R524) */ | |
| } /* if1 */ | |
| } /* then */ | |
| else | |
| { | |
| tango[0]=0; /* たんごが なんも なかったよ */ | |
| } /* if */ | |
| } /* tango_bunkai */ | |
| int kuguri(char *inputs) /* 区切りを入れる(R521) */ | |
| { | |
| static char kugimoji[30][3] = | |
| { " ","?","!","”","(",")","、",",","。", | |
| ".","・","「","」","『","』","★","☆" | |
| }; /* char kugimoji */ | |
| static int mojisuu = 17; /* 区切り文字数 */ | |
| int count = 0; | |
| char *charptr; /* ちゃあぽいんたあ */ | |
| while(count<mojisuu) | |
| { | |
| while(charptr=(char*)strstr(inputs,kugimoji[count]),charptr!=0) | |
| { | |
| *charptr=' '; | |
| if(strlen(kugimoji[count])==2) | |
| { | |
| *(charptr+1)=' '; | |
| } /* if */ | |
| } /* while1 */ | |
| count++; | |
| } /* while */ | |
| } /* kugiri */ | |
| int renzokumoji(char *inputs) /* 連続文字削除”ぁぃぅぇぉっー~”(R522)*/ | |
| { | |
| static char renzomoji[10][5] = | |
| { | |
| "ぁ","ぃ","ぅ","ぇ","ぉ","っっ","~","ーー" | |
| }; /* renzomoji */ | |
| static int mojisuu = 8; | |
| int count = 0; | |
| char *charptr; | |
| while(count<mojisuu) | |
| { | |
| while(charptr=(char*)strstr(inputs,renzomoji[count]),charptr!=0) | |
| { | |
| strcpy(charptr,(charptr+2)); | |
| } /* while1 */ | |
| count++; | |
| } /* while */ | |
| } /* renzokumoji */ | |
| int joshi2(char *tango) /* 文末助詞削除(R523) */ | |
| { | |
| int tanlen; | |
| tanlen=strlen(tango); | |
| joshi_sub(tango,"ね"); | |
| if(joshi_sub(tango,"にゃん")==0) | |
| { | |
| if(joshi_sub(tango,"かな")==0) | |
| { | |
| if(joshi_sub(tango,"か")==0) | |
| { | |
| joshi_sub(tango,"よ"); | |
| } /* if2 */ | |
| } /* if1 */ | |
| } /* if */ | |
| if(joshi_sub(tango,"だっちゃ")==0) | |
| { | |
| if(joshi_sub(tango,"っちゃ")==0) | |
| { | |
| if(joshi_sub(tango,"だよん")==0) | |
| { | |
| if(joshi_sub(tango,"ちゃ")==0) | |
| { | |
| if(joshi_sub(tango,"なの")==0) | |
| { | |
| if(joshi_sub(tango,"なに")==0) | |
| { | |
| if(joshi_sub(tango,"何")==0) | |
| { | |
| if(joshi_sub(tango,"ある")==0) | |
| { | |
| joshi_sub(tango,"だ"); | |
| } /* if7 */ | |
| } /* if6 */ | |
| } /* if5 */ | |
| } /* if4 */ | |
| } /* if3 */ | |
| } /* if2 */ | |
| } /* if1 */ | |
| } /* if */ | |
| if(joshi_sub(tango,"もの")==0) | |
| { | |
| if(joshi_sub(tango,"こと")==0) | |
| { | |
| joshi_sub(tango,"事"); | |
| } /* if1 */ | |
| } /* if */ | |
| if(joshi_sub(tango,"のは")==0) | |
| { | |
| if(joshi_sub(tango,"とは")==0) | |
| { | |
| if(joshi_sub(tango,"って")==0) | |
| { | |
| if(joshi_sub(tango,"に")==0) | |
| { | |
| if(joshi_sub(tango,"は")==0) | |
| { | |
| if(tanlen!=strlen(tango)) | |
| { | |
| joshi_sub(tango,"の"); | |
| } /* if5 */ | |
| } /* if4 */ | |
| } /* if3 */ | |
| } /* if2 */ | |
| } /* if1 */ | |
| } /* if */ | |
| } /* joshi2 */ | |
| int joshi1(char *tango) /* 助詞削除(R524) */ | |
| { | |
| if(joshi_sub(tango,"のは")==0) | |
| { | |
| if(joshi_sub(tango,"には")==0) | |
| { | |
| if(joshi_sub(tango,"とは")==0) | |
| { | |
| if(joshi_sub(tango,"って")==0) | |
| { | |
| if(joshi_sub(tango,"を")==0) | |
| { | |
| if(joshi_sub(tango,"で")==0) | |
| { | |
| if(joshi_sub(tango,"と")==0) | |
| { | |
| if(joshi_sub(tango,"も")==0) | |
| { | |
| if(joshi_sub(tango,"に")==0) | |
| { | |
| if(joshi_sub(tango,"が")==0) | |
| { | |
| if(joshi_sub(tango,"の")==0) | |
| { | |
| joshi_sub(tango,"は"); | |
| } /* if10 */ | |
| } /* if9 */ | |
| } /* if8 */ | |
| } /* if7 */ | |
| } /* if6 */ | |
| } /* if5 */ | |
| } /* if4 */ | |
| } /* if3 */ | |
| } /* if2 */ | |
| } /* if1 */ | |
| } /* if */ | |
| } /* joshi1 */ | |
| int joshi_sub(char *tango,char *joshi1) /* 助詞削除のサブ(R5241) */ | |
| { | |
| char *charptr; /* ちゃーぽいんたー */ | |
| char joshi2[96]; /* ひかくよう */ | |
| if(strlen(tango)>strlen(joshi1)) /* たんごのながさは じゅうぶん? */ | |
| { | |
| charptr=tango+strlen(tango)-strlen(joshi1); | |
| strcpy(joshi2,charptr); | |
| if(strcmp(joshi2,joshi1)==0) | |
| { | |
| *charptr=0; | |
| return(1); /* 削除したよっと */ | |
| } /* if1 */ | |
| } /* if */ | |
| return(0); /* 削除しなかったよっと */ | |
| } /* joshi_sub */ | |
| int disk_seek(char *answers,char *tango,posstyp *poss) /*単語検索(R53)*/ | |
| { | |
| FILE *fileptr; /* ふぁいるぽいんたー */ | |
| char readdta[144]; /* でいすくから よんでくる でえたあ */ | |
| char id; | |
| char *charptr; | |
| int qa0; | |
| fileptr=file_open("kurumi3.dic","rt"); /* ふぁいるの おーぷん */ | |
| while(feof(fileptr)==0) /* ふぁいるが おわるまで るーぷ */ | |
| { | |
| fgets(readdta,142,fileptr); /* でえたあの よみこみ */ | |
| id=readdta[0]; /* でいたあの あいでい (1なら たんご) */ | |
| if(id=='1') | |
| { | |
| charptr=(char*)strchr(&readdta[2],':'); | |
| if(charptr!=0) | |
| { | |
| *charptr=0; /* ":"のところをnullにしちゃう */ | |
| if((strcmp(&readdta[2],tango)==0) | |
| &&(random(100)>=(poss->otoboke))) /* 知ってる単語をとぼける確率 */ | |
| { | |
| charptr++; | |
| strcpy(answers,charptr); | |
| qa0=strlen(answers)-1; | |
| answers[qa0]=0; | |
| file_close(fileptr); /* ふぁいるの くろーず */ | |
| if(answers[0]==0) | |
| { | |
| strcpy(answers,"わだいを かえましょ"); | |
| } /* if3 */ | |
| return(0); | |
| } /* if2 */ | |
| } /* if1 */ | |
| } /* if */ | |
| } /* while */ | |
| file_close(fileptr); | |
| answers[0]=0; /* でえたあが でいすくに なかったら こたえは0 */ | |
| } /* disk_seek */ | |
| int question(char *answers,int loopflg,posstyp *poss) /* 質問変換(R54) */ | |
| { | |
| static char squest[10][64] = | |
| { | |
| "", | |
| "ってなに?", | |
| "ってなぁに?", | |
| "って?", | |
| "??", | |
| "ってなんでしょ?", | |
| "ってなにかな?", | |
| "?" | |
| }; /* char suest */ | |
| char totsuzen[96] = "とつぜんだけどぉ、"; | |
| int rnd; | |
| int qa0; | |
| if(loopflg!=0) /* るーぷふらぐが1なら 「とつぜんだけどぉ」をくわえる */ | |
| { | |
| strcat(totsuzen,answers); | |
| strcpy(answers,totsuzen); | |
| } /* if */ | |
| rnd=random(100); | |
| qa0=1; | |
| while(qa0<=(poss->quest[0])) /* しつもんの かずだよ */ | |
| { | |
| if(rnd<(poss->quest[qa0])) | |
| { | |
| strcat(answers,squest[qa0]); | |
| break; | |
| } /* if */ | |
| qa0++; | |
| } /* while */ | |
| } /* question */ | |
| int tokusyutango(char *answers,posstyp *poss) /* 特殊単語変換(R55) */ | |
| { | |
| char answers1[96]; | |
| FILE *fileptr; | |
| int count; | |
| char dummy[144]; | |
| strcpy(answers1,answers); | |
| joshi2(answers1); /* 助詞を削除「文末」(R523) */ | |
| if((strcmp(answers1,"辞書")==0)||(strcmp(answers1,"じしょ")==0)) | |
| { | |
| fileptr=file_open("kurumi3.dic","rt"); | |
| count=0; | |
| while(feof(fileptr)==0) | |
| { | |
| fgets(dummy,142,fileptr); | |
| count++; | |
| } /* while */ | |
| file_close(fileptr); | |
| strcpy(answers,"とうろくたんごすうは、"); | |
| strcat(answers,itoa(count,dummy,10)); | |
| if(random(100)<(poss->dayo)) /* 「だよ」の確率 */ | |
| { | |
| strcat(answers,"だよ"); | |
| } /* then1 */ | |
| else | |
| { | |
| strcat(answers,"でぃっす"); | |
| } /* if1 */ | |
| } /* if */ | |
| if((strcmp(answers1,"時間")==0)||(strcmp(answers1,"じかん")==0)) | |
| { | |
| struct time now; | |
| gettime(&now); | |
| strcpy(answers,"ただいまの じかんは、"); | |
| strcat(answers,itoa(now.ti_hour,dummy,10)); | |
| strcat(answers,"時"); | |
| strcat(answers,itoa(now.ti_min,dummy,10)); | |
| strcat(answers,"分"); | |
| strcat(answers,itoa(now.ti_sec,dummy,10)); | |
| strcat(answers,"秒"); | |
| if(random(100)<(poss->dayo)) /* 「だよ」の確率 */ | |
| { | |
| strcat(answers,"だよ"); | |
| } /* then1 */ | |
| else | |
| { | |
| strcat(answers,"でぃっす"); | |
| } /* if1 */ | |
| } /* if */ | |
| if((strcmp(answers1,"日付")==0)||(strcmp(answers1,"ひづけ")==0)) | |
| { | |
| struct date today; | |
| getdate(&today); | |
| strcpy(answers,"きょうは、"); | |
| strcat(answers,itoa(today.da_year,dummy,10)); | |
| strcat(answers,"年"); | |
| strcat(answers,itoa(today.da_mon,dummy,10)); | |
| strcat(answers,"月"); | |
| strcat(answers,itoa(today.da_day,dummy,10)); | |
| strcat(answers,"日"); | |
| if(random(100)<(poss->dayo)) /* 「だよ」の確率 */ | |
| { | |
| strcat(answers,"だよ"); | |
| } /* then1 */ | |
| else | |
| { | |
| strcat(answers,"でぃっす"); | |
| } /* if1 */ | |
| } /* if */ | |
| if((strcmp(answers1,"曜日")==0)||(strcmp(answers1,"ようび")==0)) | |
| { | |
| struct REGPACK preg; | |
| int youbi; | |
| preg.r_ax=0x2a00; | |
| intr(0x21,&preg); | |
| youbi=preg.r_ax % 256; | |
| strcpy(answers,"きょうは、"); | |
| switch(youbi) | |
| { | |
| case 0 : strcat(answers,"日曜日"); break; | |
| case 1 : strcat(answers,"月曜日"); break; | |
| case 2 : strcat(answers,"火曜日"); break; | |
| case 3 : strcat(answers,"水曜日"); break; | |
| case 4 : strcat(answers,"木曜日"); break; | |
| case 5 : strcat(answers,"金曜日"); break; | |
| case 6 : strcat(answers,"土曜日"); break; | |
| default: puts("なんか、ようびのところが おかしいよぉ"); | |
| } /* switch */ | |
| if(random(100)<(poss->dayo)) /* 「だよ」の確率 */ | |
| { | |
| strcat(answers,"だよ"); | |
| } /* then1 */ | |
| else | |
| { | |
| strcat(answers,"でぃっす"); | |
| } /* if1 */ | |
| } /* if */ | |
| if((strcmp(answers1,"挨拶")==0)||(strcmp(answers1,"あいさつ")==0)) | |
| { | |
| strcpy(answers,greeting(poss)); /* あいさつ(R4) */ | |
| } /* if */ | |
| if(answers1[0]=='!') | |
| { | |
| system(&answers1[1]); /* DOSのコマンド じっこうだよ */ | |
| strcpy(answers,&answers1[1]); | |
| } /* if */ | |
| } /* tokusyutango */ | |
| int zenkaku(char *inputs) /* 半角を全角に変換(R56) */ | |
| { | |
| unsigned char inputs1[96]; | |
| unsigned char *charptr; | |
| unsigned char *charptr1; | |
| unsigned short zen; | |
| if(inputs[0]=='!') | |
| { | |
| return(0); | |
| } /* if */ | |
| charptr = inputs; | |
| charptr1 = inputs1; | |
| while(*charptr!=0) | |
| { | |
| if(((0x080<=*charptr)&&(*charptr<=0x09f)) | |
| ||((0x0c0<=*charptr)&&(*charptr<=0x0fc))) /* 全角の1バイト目か? */ | |
| { | |
| *charptr1=*charptr; | |
| charptr++; | |
| charptr1++; | |
| if(*charptr==0) | |
| { | |
| break; | |
| } /* if1 */ | |
| *charptr1=*charptr; | |
| charptr++; | |
| charptr1++; | |
| } /* then */ | |
| else | |
| { | |
| if((0x020<=*charptr)&&(*charptr<=0x07e)) | |
| { | |
| zen=hantozen(*charptr); /* はんかくをぜんかくに(あるふぁべっとだよ)*/ | |
| charptr++; | |
| *charptr1 = zen / 256; | |
| charptr1++; | |
| *charptr1 = zen % 256; | |
| charptr1++; | |
| } /* then1 */ | |
| else | |
| { | |
| *charptr1=*charptr; | |
| charptr++; | |
| charptr1++; | |
| } /* if1 */ | |
| } /* if */ | |
| } /* while */ | |
| *charptr1=0; | |
| strcpy(inputs,inputs1); | |
| /* 半角カタカナも全角に変換しようかと思ったけど、失敗しちゃった */ | |
| } /* zenkaku */ | |
| int set_color(char *kurucol,char *usercol) | |
| /* カラーコードを辞書から読み込む(R7) */ | |
| { | |
| FILE *fileptr; /* ふぁいるぽいんたー */ | |
| char readdta[144]; /* でいすくから よんでくる でえたあ */ | |
| char id; | |
| char *charptr0; | |
| char *charptr1; | |
| int qa0; | |
| fileptr=file_open("kurumi3.dic","rt"); /* ふぁいるの おーぷん */ | |
| while(feof(fileptr)==0) /* ふぁいるが おわるまで るーぷ */ | |
| { | |
| fgets(readdta,142,fileptr); /* でえたあの よみこみ */ | |
| id=readdta[0]; | |
| if(id=='3') | |
| { | |
| charptr0=(char*)strchr(&readdta[2],':'); | |
| if(charptr0!=0) | |
| { | |
| *charptr0=0; /* ":"のところをnullにしちゃう */ | |
| if(strcmp(&readdta[2],"color")==0) | |
| { | |
| charptr0++; | |
| charptr1=(char*)strchr(charptr0,':'); | |
| if(charptr1!=0) | |
| { | |
| *charptr1=0; | |
| charptr1++; | |
| strcpy(kurucol,charptr0); | |
| strcpy(usercol,charptr1); | |
| qa0=strlen(usercol)-1; | |
| usercol[qa0]=0; | |
| } /* if3 */ | |
| file_close(fileptr); /* ふぁいるの くろーず */ | |
| return(0); | |
| } /* if2 */ | |
| } /* if1 */ | |
| } /* if */ | |
| } /* while */ | |
| file_close(fileptr); | |
| } /* set_color */ | |
| int set_name(char *kuruname) /* 名前を辞書から読み込む(R8) */ | |
| { | |
| FILE *fileptr; /* ふぁいるぽいんたー */ | |
| char readdta[144]; /* でいすくから よんでくる でえたあ */ | |
| char id; | |
| char *charptr0; | |
| int qa0; | |
| fileptr=file_open("kurumi3.dic","rt"); /* ふぁいるの おーぷん */ | |
| while(feof(fileptr)==0) /* ふぁいるが おわるまで るーぷ */ | |
| { | |
| fgets(readdta,142,fileptr); /* でえたあの よみこみ */ | |
| id=readdta[0]; | |
| if(id=='3') | |
| { | |
| charptr0=(char*)strchr(&readdta[2],':'); | |
| if(charptr0!=0) | |
| { | |
| *charptr0=0; /* ":"のところをnullにしちゃう */ | |
| if(strcmp(&readdta[2],"name")==0) | |
| { | |
| charptr0++; | |
| strcpy(kuruname,charptr0); | |
| qa0=strlen(kuruname)-1; | |
| kuruname[qa0]=0; | |
| file_close(fileptr); /* ふぁいるの くろーず */ | |
| return(0); | |
| } /* if2 */ | |
| } /* if1 */ | |
| } /* if */ | |
| } /* while */ | |
| file_close(fileptr); | |
| } /* set_name */ | |
| int set_gobi(char *gobi) /* 語尾を辞書から読み込む(R9) */ | |
| { | |
| FILE *fileptr; /* ふぁいるぽいんたー */ | |
| char readdta[144]; /* でいすくから よんでくる でえたあ */ | |
| char id; | |
| char *charptr0; | |
| int qa0; | |
| fileptr=file_open("kurumi3.dic","rt"); /* ふぁいるの おーぷん */ | |
| while(feof(fileptr)==0) /* ふぁいるが おわるまで るーぷ */ | |
| { | |
| fgets(readdta,142,fileptr); /* でえたあの よみこみ */ | |
| id=readdta[0]; | |
| if(id=='3') | |
| { | |
| charptr0=(char*)strchr(&readdta[2],':'); | |
| if(charptr0!=0) | |
| { | |
| *charptr0=0; /* ":"のところをnullにしちゃう */ | |
| if(strcmp(&readdta[2],"gobi")==0) | |
| { | |
| charptr0++; | |
| strcpy(gobi,charptr0); | |
| qa0=strlen(gobi)-1; | |
| gobi[qa0]=0; | |
| file_close(fileptr); /* ふぁいるの くろーず */ | |
| return(0); | |
| } /* if2 */ | |
| } /* if1 */ | |
| } /* if */ | |
| } /* while */ | |
| file_close(fileptr); | |
| } /* set_gobi */ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment