WORDLE (高内存低效率控制台老土版)
本帖最后由 额外减小 于 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={'\0'},ans={'\0'},word={'\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==key)
{
color(10);
count++;
printf("%c",ans);
}
else
{
status=1;
for(int j=0;j<5;j++)
{
if(ans==key)
{
status=0;
color(6);
printf("%c",ans);
break;
}
}
if(status)
{
color(8);
printf("%c",ans);
}
}
}
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={'\0'},ans={'\0'},word={'\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==key)
{
color(10);
count++;
printf("%c",ans);
}
else
{
status=1;
for(int j=0;j<5;j++)
{
if(ans==key)
{
status=0;
color(6);
printf("%c",ans);
break;
}
}
if(status)
{
color(8);
printf("%c",ans);
}
}
}
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机器人(用信息熵)
附件:词库
祝大家玩的愉快!
什么,你说不会规则?
baidu.com
想看看它的运行情况吗(bushi)
啥东西,没看懂
谢谢分享!! 博主这是干啥的呀没看太懂
Mike_python小 发表于 2023-3-27 08:19
啥东西,没看懂
好 Mike_python小 发表于 2023-3-27 08:19
啥东西,没看懂
Wordle游戏的规则非常简单,它要求玩家在6次之内猜出一个由5个字母组成的单词。每次输入单词时,如果输入的字母在目标单词中,但是位置不对,那么格子会显示成黄色;如果输入的字母在目标单词中,且位置正确,那么格子会显示成绿色;如果都不对,则会显示成灰色。玩家需要根据每次猜词后的反馈来调整自己的猜词策略,最终猜出单词。
页:
[1]