-
Notifications
You must be signed in to change notification settings - Fork 0
/
SudokuDemo.cpp
293 lines (270 loc) · 8.46 KB
/
SudokuDemo.cpp
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
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
// SudokuDemo.cpp : This file contains the 'main' function. Program execution begins and ends there.
//
#include <iostream>
#include <time.h>
#include <string>
#include <windows.h>
#include <iomanip>
#include <Windows.h>
#include "Algorithm.h"
using namespace std;
string Grid[19][19];
Board newBoard = MakeBoard();
vector<Board> Solutions;
int hours = 0, minutes = 0, seconds = 0;
clock_t start, finish;
struct Time
{
int minutes;
int seconds;
};
int elapsed_time(clock_t start, clock_t finish) {
// returns elapsed time in milliseconds
return (finish - start) / (CLOCKS_PER_SEC);
}
Time changeTime(int sec)
{
Time t;
t.minutes = sec / 60;
t.seconds = sec % 60;
return t;
}
void printSudokuLogo()
{
cout << "\x1b[32m ** \x1b[31m * * \x1b[32m * * * \x1b[31m * * \x1b[32m * * \x1b[31m * * * * \x1b[37m" << endl;
cout << "\x1b[32m* * \x1b[31m * * \x1b[32m * * \x1b[31m* * \x1b[32m * * \x1b[31m * * * * \x1b[37m" << endl;
cout << "\x1b[32m * \x1b[31m * * \x1b[32m * * \x1b[31m* * \x1b[32m * * \x1b[31m * * * * \x1b[37m" << endl;
cout << "\x1b[32m * \x1b[31m * * \x1b[32m * * \x1b[31m* * \x1b[32m * * \x1b[31m * * \x1b[32m * * * \x1b[31m * * \x1b[37m" << endl;
cout << "\x1b[32m* * \x1b[31m * * \x1b[32m * * \x1b[31m* * \x1b[32m* * \x1b[31m * * \x1b[32m * * * * \x1b[31m * * \x1b[37m" << endl;
cout << "\x1b[32m ** \x1b[31m * * \x1b[32m * * * \x1b[31m * * \x1b[32m* * \x1b[31m * * \x1b[32m * * \x1b[31m * * \x1b[37m" << endl << endl;
}
void printUwU()
{
cout << " . ` ` `" << endl;
cout << " /y :y. .h: +:" << endl;
cout << " yh oN- -No yy" << endl;
cout << " sm` dN` `Nd `Ny" << endl;
cout << " .mh. .yN+ +Ny. .hm." << endl;
cout << " `----..+hdyydmy- `` `` -ymdyydh+..----`" << endl;
cout << " `//+++++/- `..` +o .. o+ `..` :+////++/`" << endl;
cout << " -+/+++++++. -d++hy++d- .++//////+-" << endl;
cout << " .////++++/` `--``--` ./////////." << endl;
cout << " `-:////:. `://///:`" << endl;
cout << " ```` `````" << endl << endl;
}
void rules()
{
system("CLS");
/// <summary>
cout << " Game Rules" << endl;
cout << "1. Within the rows and columns are 9 squares (3x3 spaces)\n2. Each rows and columns needs to be filled out with the numbers \n1-9 without repeating numbers within the rows or columns\n";
/// </summary>
system("pause");
} // Nguyen
//void generate_sudoku(Board b);
/*
void playAgain();
void showSolution();*/
/*bool checkSolutions() // con` dang do?
{
for (int i = 0; i < Solutions.size(); i++)
{
for (int j = 0; j < 9; j++)
for (int k = 0; k < 9; k++)
{
if (to_string(Solutions[i][j][k]) == Grid[j * 2 + 1][k * 2 + 1]);
}
}
}*/
void CongratulationMenu()
{
system("CLS");
printUwU();
cout << "Congratulation, you are a genius UwU" << endl;
return;
}
bool checkInput(int num)
{
if ((num <= 9) && (num >= 1))
return true;
else
return false;
}
void displayClock()
{
cout << setfill(' ') << setw(55) << " TIMER \n";
cout << setfill(' ') << setw(55) << " --------------------------\n";
cout << setfill(' ') << setw(29);
cout << "| " << setfill('0') << setw(2) << hours << " hrs | ";
cout << setfill('0') << setw(2) << minutes << " min | ";
cout << setfill('0') << setw(2) << seconds << " sec |" << endl;
cout << setfill(' ') << setw(55) << " --------------------------\n";
}
void PrintNumber(int row, int col, int num)
{
Grid[(row - 1) * 2 + 1][(col - 1) * 2 + 1] = to_string(num);
}
void GridCreating()
{
for (int i = 0; i < 19; i++)
for (int j = 0; j < 19; j++)
Grid[i][j] = " ";
}
void generate_sudoku()
{
system("CLS");
for (int i = 1; i < 18; i += 2)
for (int j = 0; j <= 18; j += 2)
{
Grid[i][j] = "|";
}
for (int i = 0; i <= 18; i += 2)
for (int j = 1; j < 18; j += 2)
{
Grid[i][j] = "=";
}
for (int i = 0; i < 9; i++)
{
for (int j = 0; j < 9; j++)
{
if (newBoard[i][j] != 0)
PrintNumber(i + 1, j + 1, newBoard[i][j]);
}
}
for (int i = 0; i < 19; i++)
{
for (int j = 0; j < 19; j++) {
if (Grid[i][j] != "|" && Grid[i][j] != "=")
{
if (newBoard[(i - 1) / 2][(j - 1) / 2] != 0)
cout << "\x1b[33m" << Grid[i][j] << "\x1b[37m";
else
cout << Grid[i][j];
}
else {
cout << Grid[i][j];
}
}
cout << endl;
}
int row, column, number;
while (true)
{
finish = clock();
cout << "Your time is: " << changeTime(elapsed_time(start, finish)).minutes << " Minutes " << changeTime(elapsed_time(start, finish)).seconds << " Seconds" << endl;
cout << "Enter the number of Row, Column and Number" << endl;
cout << "If you've finished, Please Enter only 0" << endl;
//cout << "If you wanna see timer, Please Enter only 1" << endl;
cin >> row;
if (row == 0)
{
//Check solution if right
CongratulationMenu();
break;
//if Wrong ....
}
cin >> column >> number;
if (!((checkInput(row)) && (checkInput(column)) && (checkInput(number))))
{
cout << "Invalid answer, please try again!" << endl;
}
else
{
if ((Grid[(row - 1) * 2 + 1][(column - 1) * 2 + 1] == " ") || (newBoard[row - 1][column - 1] == 0))
{
PrintNumber(row, column, number);
generate_sudoku();
}
else {
cout << "Invalid answer, please try again!" << endl;
}
}
}
system("pause");
}
void playInterface()
{
system("CLS");
printUwU();
cout << "Choose the level you want to UwU" << endl;
cout << "1_Easy" << endl;
cout << "2_Normal" << endl;
cout << "3_Hard" << endl;
int NumberMode;
cout << "Your number is: ";
cin >> NumberMode;
if (NumberMode == 1)
{
newBoard = EasyMode();
Solutions = TestUnique(newBoard, Solutions);
GridCreating();
start = clock();
generate_sudoku();
}
if (NumberMode == 2)
{
newBoard = NormalMode();
Solutions = TestUnique(newBoard, Solutions);
GridCreating();
generate_sudoku();
}
if (NumberMode == 3)
{
newBoard = HardMode();
Solutions = TestUnique(newBoard, Solutions);
GridCreating();
generate_sudoku();
}
}
void ExitMenu()
{
system("CLS");
printUwU();
cout << "Thank you for playing our game UwU" << endl;
system("pause");
}
void start_menu()
{
bool check = true;
while (check)
{
system("CLS");
printSudokuLogo();
printUwU();
CONSOLE_FONT_INFOEX cfi;
cfi.cbSize = sizeof(cfi);
cfi.nFont = 0;
cfi.dwFontSize.X = 0; // Width of each character in the font
cfi.dwFontSize.Y = 24; // Height
cfi.FontFamily = FF_DONTCARE;
cfi.FontWeight = FW_NORMAL;
wcscpy_s(cfi.FaceName, L"Consolas"); // Choose your font
SetCurrentConsoleFontEx(GetStdHandle(STD_OUTPUT_HANDLE), FALSE, &cfi);
cout << " Welcome to SudokUwU" << endl;
//cout << "(´꒳`)" << endl;
cout << " 1_Rules " << endl;
cout << " 2_Play" << endl;
cout << " 3_Exit" << endl;
cout << " Enter your Number: ";
int NUMBER;
cin >> NUMBER;
if (NUMBER == 1)
{
rules();
}
if (NUMBER == 2)
{
playInterface();
}
if (NUMBER == 3)
{
check = false;
ExitMenu();
}
}
}
int main()
{
start_menu();
return 0;
}