Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

普二仁 911073 海馬 <好啦我新開檔案啦> #4

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
111 changes: 111 additions & 0 deletions wordle_guess.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
#include <iostream>
#include <vector>
#include <cstdlib>
#include <ctime>
#define RESET "\033[0m"
#define YELLOW "\033[43m"
#define GREEN "\033[42m"

using namespace std;

void start_guessing(string ans) {
cout << "Start Guessing:" << endl;
bool correct = 0;
int guess = 0;
string guessing;
do {
int color[5] = {0}; // 0 = white, 1 = yellow, 2 = green
bool used[5] = {0};
guess++;
cin >> guessing;
for (int i = 0; i < 5; i++) {
if (guessing[i] == ans[i]) {
color[i] = 2;
used[i] = 1;
}
}
for (int i = 0; i < 5; i++) {
for (int j = 0; j < 5; j++) {
if (guessing[i] == ans[j] && !used[j] && i != j && guessing[i] != ans[i]) {
color[i] = 1;
used[j] = 1;
}
}
}
for (int i = 0; i < 5; i++) {
switch (color[i]) {
case 0:
cout << RESET << guessing[i];
break;
case 1:
cout << YELLOW << guessing[i];
break;
case 2:
cout << GREEN << guessing[i];
break;
default:
break;
}
cout << RESET;
}
cout << endl;
if (color[0] == 2 && color[1] == 2 && color[2] == 2 && color[3] == 2 && color[4] == 2) {
correct = 1;
break;
}
} while (guess < 6);
if (correct) {
cout << RESET << "WORDLE NSCSC " << guess << "/6" << endl;
}
else {
cout << RESET << "WORDLE NSCSC X/6" << endl;
}
}

int main() {
cout << RESET;
vector<string> words {
"apple",
"pizza",
"never",
"gonna",
"given",
"yours",
"upper",
"utter",
"cloth",
"plant",
"grand",
"clear",
"clean",
"spill",
"skill",
"still",
"worth",
"wound",
"would",
"above",
"below",
"treat",
"snail",
"truth",
"birth",
"brand",
"asset",
"guess",
"slave",
"snake",
"proof",
"prove",
// TODO: 請協助 PR 以擴充題庫
};

srand(time(NULL));

int wordCount = words.size();
int questionIndex = rand() % wordCount;

cout << "本次題目:" << words[questionIndex] << endl; // comment out this line if needed

start_guessing(words[questionIndex]);
}