-
Notifications
You must be signed in to change notification settings - Fork 0
/
Wordle.cs
136 lines (114 loc) · 3.86 KB
/
Wordle.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
using System;
using System.Collections;
using System.Collections.Specialized;
class Wordle {
static bool IsCorrectString(HashSet<string> answers, string input)
{
bool bInputError = false;
for (int i = 0; i < input.Length; ++i)
{
if (!Char.IsUpper(input[i]))
{
bInputError = true;
break;
}
}
if (bInputError || input.Length != 5)
{
Console.WriteLine("영어 대문자 5글자가 아닙니다.");
return false;
}
if (!answers.Contains(input))
{
Console.WriteLine("사전에 없는 단어입니다.");
return false;
}
return true;
}
// BATTA TTTDF
static void Main() {
var data = CSVReader.Read();
/*
Write your code below here.
*/
Random random = new Random();
var temp = random.Next(0, data.Count - 1);
string answer = data[temp]["Name"];
// Console.WriteLine(answer);
var answers = new HashSet<string>();
foreach (var row in data)
answers.Add(row["Name"]);
int test;
for (test = 0; test < 5; ++test)
{
var numStrike = 0;
var strike = new bool[5];
var answerCharacters = new Dictionary<char, int>();
var inputCharacters = new Dictionary<char, int>();
var letterHit = new int[26];
foreach (char c in answer)
if (!answerCharacters.TryAdd(c, 1))
++answerCharacters[c];
Console.WriteLine("단어를 입력하세요. (영어 대문자 5글자) ; 이번을 포함한 남은 기회 {0}번", 5 - test);
string input = Console.ReadLine();
while (!IsCorrectString(answers, input))
input = Console.ReadLine();
// Strike Check
for (int i = 0; i < 5; ++i)
{
if (input[i] == answer[i])
{
strike[i] = true;
if (!inputCharacters.TryAdd(input[i], 1))
inputCharacters[input[i]] = 1;
++numStrike;
}
inputCharacters.TryAdd(input[i], 0);
}
// Ball Check
for (int i = 0; i < 5; ++i)
{
char ch = input[i];
if (strike[i])
{
letterHit[ch - 'A'] = 3;
Console.Write("G");
continue;
}
int answerCount = 0;
int inputCount = 1000000000;
answerCharacters.TryGetValue(ch, out answerCount);
inputCharacters.TryGetValue(ch, out inputCount);
if (answerCount > inputCount)
{
letterHit[ch - 'A'] = int.Max(letterHit[ch - 'A'], 2);
Console.Write("Y");
++inputCharacters[ch];
}
else
{
letterHit[ch - 'A'] = 1;
Console.Write("B");
}
}
Console.WriteLine();
// Print all the alphabets and their records
for (int i = 0; i < letterHit.Length; ++i)
{
Console.Write("{0}:{1}", (char)('A' + i), "NBYG"[letterHit[i]]);
if (i < letterHit.Length - 1)
Console.Write(", ");
if ((i + 1) % 5 == 0)
Console.WriteLine();
}
Console.WriteLine();
Console.WriteLine();
if (numStrike == 5)
break;
}
if (test != 5)
Console.WriteLine("Correct!");
else
Console.WriteLine("Wrong!");
}
}