|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
本帖最后由 额外减小 于 2023-3-27 06:45 编辑
如题
随便写了一个
附带词库。(可自行添加新词)
1.难度较大版本(输入须包含在词库中)
- #include <stdio.h>
- #include <string.h>
- #include <windows.h>
- #include <time.h>
- void color(int type)
- {
- if((type>=0)||(type<=15))
- {
- SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),type);
- }
- else
- {
- SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),7);
- }
- }
- int CountLines(const char *filename)
- {
- FILE *fp;
- int count = 0;
- int temp;
-
- if ((fp = fopen(filename, "r")) == NULL)
- {
- fprintf(stderr, "Can not open the file:%s\n", filename);
- return -1;
- }
-
- while ((temp = fgetc(fp)) != EOF)
- {
- if (temp == '\n')
- {
- count++;
- }
- }
-
- fclose(fp);
-
- return count;
- }
- int main()
- {
- char key[6]={'\0'},ans[6]={'\0'},word[6]={'\0'};
- srand((unsigned)time(NULL));
- int lines=CountLines("wordle.txt")+1,n=(rand()*rand()+512)%lines,status=0,i,count,isinclude;
- FILE *fp=fopen("wordle.txt","r");
- for(int i=0;i<n;i++)
- {
- fscanf(fp,"%s",key);
- }
- fclose(fp);
- for(int times=1;times<=6;times++)
- {
- color(7);
- count=0;
-
- while(1)
- {
- scanf("%s",ans);
- fp=fopen("wordle.txt","r");
- for(int i=0;i<lines;i++)
- {
- status=0;
- fscanf(fp,"%s",word);
- if(!strncmp(ans,word,5))
- {
- status=1;
- break;
- }
- }
- fclose(fp);
- if(status)
- {
- break;
- }
- }
-
- for(int i=0;i<5;i++)
- {
- if(ans[i]==key[i])
- {
- color(10);
- count++;
- printf("%c",ans[i]);
- }
- else
- {
- status=1;
- for(int j=0;j<5;j++)
- {
- if(ans[i]==key[j])
- {
- status=0;
- color(6);
- printf("%c",ans[i]);
- break;
- }
- }
- if(status)
- {
- color(8);
- printf("%c",ans[i]);
- }
- }
- }
- printf("\n");
- if(count==5)
- {
- color(7);
- printf("\nSucceeded in %d times.\n",times);
- system("pause");
- return 0;
- }
- }
- color(7);
- printf("\nGood luck next time\nThe correct answer is : %s\n",key);
- system("pause");
- return 0;
- }
复制代码
2.难度较小版本(随便输入 有点不讲武德)
- #include <stdio.h>
- #include <string.h>
- #include <windows.h>
- #include <time.h>
- void color(int type)
- {
- if((type>=0)||(type<=15))
- {
- SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),type);
- }
- else
- {
- SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),7);
- }
- }
- int CountLines(const char *filename)
- {
- FILE *fp;
- int count = 0;
- int temp;
-
- if ((fp = fopen(filename, "r")) == NULL)
- {
- fprintf(stderr, "Can not open the file:%s\n", filename);
- return -1;
- }
-
- while ((temp = fgetc(fp)) != EOF)
- {
- if (temp == '\n')
- {
- count++;
- }
- }
-
- fclose(fp);
-
- return count;
- }
- int main()
- {
- char key[6]={'\0'},ans[6]={'\0'},word[6]={'\0'};
- srand((unsigned)time(NULL));
- int lines=CountLines("wordle.txt")+1,n=(rand()*rand()+512)%lines,status=0,i,count,isinclude;
- FILE *fp=fopen("wordle.txt","r");
- for(int i=0;i<n;i++)
- {
- fscanf(fp,"%s",key);
- }
- fclose(fp);
- for(int times=1;times<=6;times++)
- {
- color(7);
- count=0;
-
- scanf("%s",ans);
-
- for(int i=0;i<5;i++)
- {
- if(ans[i]==key[i])
- {
- color(10);
- count++;
- printf("%c",ans[i]);
- }
- else
- {
- status=1;
- for(int j=0;j<5;j++)
- {
- if(ans[i]==key[j])
- {
- status=0;
- color(6);
- printf("%c",ans[i]);
- break;
- }
- }
- if(status)
- {
- color(8);
- printf("%c",ans[i]);
- }
- }
- }
- printf("\n");
- if(count==5)
- {
- color(7);
- printf("\nSucceeded in %d times.\n",times);
- system("pause");
- return 0;
- }
- }
- color(7);
- printf("\nGood luck next time\nThe correct answer is : %s\n",key);
- system("pause");
- return 0;
- }
复制代码
做的有点简单,大佬勿喷谢谢
下次做个wordle机器人(用信息熵)
附件:词库
wordle.zip
(5.01 KB, 下载次数: 5)
祝大家玩的愉快!
什么,你说不会规则?
baidu.com
想看看它的运行情况吗(bushi)
|
|