鱼C论坛

 找回密码
 立即注册
查看: 1111|回复: 5

[作品展示] WORDLE (高内存低效率控制台老土版)

[复制链接]
发表于 2023-3-27 00:07:24 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能^_^

您需要 登录 才可以下载或查看,没有账号?立即注册

x
本帖最后由 额外减小 于 2023-3-27 06:45 编辑

如题
随便写了一个
附带词库。(可自行添加新词)
1.难度较大版本(输入须包含在词库中)
  1. #include <stdio.h>
  2. #include <string.h>
  3. #include <windows.h>
  4. #include <time.h>

  5. void color(int type)
  6. {
  7.         if((type>=0)||(type<=15))
  8.         {
  9.                 SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),type);
  10.         }
  11.         else
  12.         {
  13.                 SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),7);
  14.         }
  15. }

  16. int CountLines(const char *filename)
  17. {
  18.         FILE *fp;
  19.         int count = 0;
  20.         int temp;
  21.         
  22.         if ((fp = fopen(filename, "r")) == NULL)
  23.         {
  24.                 fprintf(stderr, "Can not open the file:%s\n", filename);
  25.                 return -1;
  26.         }
  27.         
  28.         while ((temp = fgetc(fp)) != EOF)
  29.         {
  30.                 if (temp == '\n')
  31.                 {
  32.                         count++;
  33.                 }
  34.         }
  35.         
  36.         fclose(fp);
  37.         
  38.         return count;
  39. }

  40. int main()
  41. {
  42.         char key[6]={'\0'},ans[6]={'\0'},word[6]={'\0'};
  43.         srand((unsigned)time(NULL));
  44.         int lines=CountLines("wordle.txt")+1,n=(rand()*rand()+512)%lines,status=0,i,count,isinclude;
  45.         FILE *fp=fopen("wordle.txt","r");
  46.         for(int i=0;i<n;i++)
  47.         {
  48.                 fscanf(fp,"%s",key);
  49.         }
  50.         fclose(fp);
  51.         for(int times=1;times<=6;times++)
  52.         {
  53.                 color(7);
  54.                 count=0;
  55.                
  56.                 while(1)
  57.                 {
  58.                         scanf("%s",ans);
  59.                         fp=fopen("wordle.txt","r");
  60.                         for(int i=0;i<lines;i++)
  61.                         {
  62.                                 status=0;
  63.                                 fscanf(fp,"%s",word);
  64.                                 if(!strncmp(ans,word,5))
  65.                                 {
  66.                                         status=1;
  67.                                         break;
  68.                                 }
  69.                         }
  70.                         fclose(fp);
  71.                         if(status)
  72.                         {
  73.                                 break;
  74.                         }
  75.                 }
  76.                
  77.                 for(int i=0;i<5;i++)
  78.                 {
  79.                         if(ans[i]==key[i])
  80.                         {
  81.                                 color(10);
  82.                                 count++;
  83.                                 printf("%c",ans[i]);
  84.                         }
  85.                         else
  86.                         {
  87.                                 status=1;
  88.                                 for(int j=0;j<5;j++)
  89.                                 {
  90.                                         if(ans[i]==key[j])
  91.                                         {
  92.                                                 status=0;
  93.                                                 color(6);
  94.                                                 printf("%c",ans[i]);
  95.                                                 break;
  96.                                         }
  97.                                 }
  98.                                 if(status)
  99.                                 {
  100.                                         color(8);
  101.                                         printf("%c",ans[i]);
  102.                                 }
  103.                         }
  104.                 }
  105.                 printf("\n");
  106.                 if(count==5)
  107.                 {
  108.                         color(7);
  109.                         printf("\nSucceeded in %d times.\n",times);
  110.                         system("pause");
  111.                         return 0;
  112.                 }
  113.         }
  114.         color(7);
  115.         printf("\nGood luck next time\nThe correct answer is : %s\n",key);
  116.         system("pause");
  117.         return 0;
  118. }
复制代码


2.难度较小版本(随便输入 有点不讲武德)
  1. #include <stdio.h>
  2. #include <string.h>
  3. #include <windows.h>
  4. #include <time.h>

  5. void color(int type)
  6. {
  7.         if((type>=0)||(type<=15))
  8.         {
  9.                 SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),type);
  10.         }
  11.         else
  12.         {
  13.                 SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),7);
  14.         }
  15. }

  16. int CountLines(const char *filename)
  17. {
  18.         FILE *fp;
  19.         int count = 0;
  20.         int temp;
  21.         
  22.         if ((fp = fopen(filename, "r")) == NULL)
  23.         {
  24.                 fprintf(stderr, "Can not open the file:%s\n", filename);
  25.                 return -1;
  26.         }
  27.         
  28.         while ((temp = fgetc(fp)) != EOF)
  29.         {
  30.                 if (temp == '\n')
  31.                 {
  32.                         count++;
  33.                 }
  34.         }
  35.         
  36.         fclose(fp);
  37.         
  38.         return count;
  39. }

  40. int main()
  41. {
  42.         char key[6]={'\0'},ans[6]={'\0'},word[6]={'\0'};
  43.         srand((unsigned)time(NULL));
  44.         int lines=CountLines("wordle.txt")+1,n=(rand()*rand()+512)%lines,status=0,i,count,isinclude;
  45.         FILE *fp=fopen("wordle.txt","r");
  46.         for(int i=0;i<n;i++)
  47.         {
  48.                 fscanf(fp,"%s",key);
  49.         }
  50.         fclose(fp);
  51.         for(int times=1;times<=6;times++)
  52.         {
  53.                 color(7);
  54.                 count=0;
  55.                
  56.                 scanf("%s",ans);
  57.                
  58.                 for(int i=0;i<5;i++)
  59.                 {
  60.                         if(ans[i]==key[i])
  61.                         {
  62.                                 color(10);
  63.                                 count++;
  64.                                 printf("%c",ans[i]);
  65.                         }
  66.                         else
  67.                         {
  68.                                 status=1;
  69.                                 for(int j=0;j<5;j++)
  70.                                 {
  71.                                         if(ans[i]==key[j])
  72.                                         {
  73.                                                 status=0;
  74.                                                 color(6);
  75.                                                 printf("%c",ans[i]);
  76.                                                 break;
  77.                                         }
  78.                                 }
  79.                                 if(status)
  80.                                 {
  81.                                         color(8);
  82.                                         printf("%c",ans[i]);
  83.                                 }
  84.                         }
  85.                 }
  86.                 printf("\n");
  87.                 if(count==5)
  88.                 {
  89.                         color(7);
  90.                         printf("\nSucceeded in %d times.\n",times);
  91.                         system("pause");
  92.                         return 0;
  93.                 }
  94.         }
  95.         color(7);
  96.         printf("\nGood luck next time\nThe correct answer is : %s\n",key);
  97.         system("pause");
  98.         return 0;
  99. }
复制代码

做的有点简单,大佬勿喷谢谢
下次做个wordle机器人(用信息熵)
附件:词库
wordle.zip (5.01 KB, 下载次数: 5)
祝大家玩的愉快!
什么,你说不会规则?

baidu.com

想看看它的运行情况吗(bushi)

内存爆炸.png
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复

使用道具 举报

发表于 2023-3-27 08:19:22 | 显示全部楼层
啥东西,没看懂
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2023-3-28 17:10:51 | 显示全部楼层
谢谢分享!!
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2023-3-28 23:06:49 From FishC Mobile | 显示全部楼层
博主这是干啥的呀没看太懂
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

 楼主| 发表于 2023-3-31 22:59:26 | 显示全部楼层

想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

 楼主| 发表于 2023-3-31 23:24:33 | 显示全部楼层

Wordle游戏的规则非常简单,它要求玩家在6次之内猜出一个由5个字母组成的单词。每次输入单词时,如果输入的字母在目标单词中,但是位置不对,那么格子会显示成黄色;如果输入的字母在目标单词中,且位置正确,那么格子会显示成绿色;如果都不对,则会显示成灰色。玩家需要根据每次猜词后的反馈来调整自己的猜词策略,最终猜出单词。
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|手机版|Archiver|鱼C工作室 ( 粤ICP备18085999号-1 | 粤公网安备 44051102000585号)

GMT+8, 2024-5-27 07:03

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表