-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.cpp
169 lines (132 loc) · 4.61 KB
/
main.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
#include <iostream>
#include <cstdio>
#include "sudoku.h"
using namespace std;
int main() {
char board[9][9];
/* This section illustrates the use of the pre-supplied helper functions. */
cout << "============= Pre-supplied functions =============" << "\n\n";
cout << "Calling load_board():" << '\n';
load_board("easy.dat", board);
cout << '\n' << "Displaying Sudoku board with display_board():" << '\n';
display_board(board);
cout << "Done!" << "\n\n";
cout << "=================== Question 1 ===================" << "\n\n";
load_board("easy.dat", board);
cout << "Board is ";
if (!is_complete(board))
cout << "NOT ";
cout << "complete." << "\n\n";
load_board("easy-solution.dat", board);
cout << "Board is ";
if (!is_complete(board))
cout << "NOT ";
cout << "complete." << "\n\n";
cout << "=================== Question 2 ===================" << "\n\n";
load_board("easy.dat", board);
/* Should be OK */
cout << "Putting '1' into I8 is ";
if (!make_move("I8", '1', board))
cout << "NOT ";
cout << "a valid move. The board is:" << '\n';
display_board(board);
/* Testing row duplicate*/
cout << "Putting '7' into I7 is ";
if (!make_move("I7", '7', board))
cout << "NOT ";
cout << "a valid move. The board is:" << '\n';
display_board(board);
/* Testing column duplicate*/
cout << "Putting '3' into H7 is ";
if (!make_move("H7", '3', board))
cout << "NOT ";
cout << "a valid move. The board is:" << '\n';
display_board(board);
/* Testing square duplicate*/
cout << "Putting '7' into H1 is ";
if (!make_move("H1", '7', board))
cout << "NOT ";
cout << "a valid move. The board is:" << '\n';
display_board(board);
/* Testing lowercase row index */
cout << "Putting '6' into a1 is ";
if (!make_move("a1", '6', board))
cout << "NOT ";
cout << "a valid move. The board is:" << '\n';
display_board(board);
/* Testing row out of bounds */
cout << "Putting '5' into Y2 is ";
if (!make_move("Y2", '5', board))
cout << "NOT ";
cout << "a valid move. The board is:" << '\n';
display_board(board);
/* Testing column out of bounds */
cout << "Putting '1' into I11 is ";
if (!make_move("I11", '1', board))
cout << "NOT ";
cout << "a valid move. The board is:" << '\n';
display_board(board);
/* Testing non-numerical input */
cout << "Putting '*' into E5 is ";
if (!make_move("E5", '*', board))
cout << "NOT ";
cout << "a valid move. The board is:" << '\n';
display_board(board);
/* Testing pre-filled sudoku position */
cout << "Putting '7' into A6 is ";
if (!make_move("A6", '7', board))
cout << "NOT ";
cout << "a valid move. The board is:" << '\n';
display_board(board);
cout << "=================== Question 3 ===================" << "\n\n";
load_board("easy.dat", board);
if (save_board("easy-copy.dat", board))
cout << "Save board to 'easy-copy.dat' successful." << '\n';
else
cout << "Save board failed." << '\n';
cout << '\n';
cout << "=================== Question 4 ===================" << "\n\n";
load_board("easy.dat", board);
if (solve_board(board)) {
cout << "The 'easy' board has a solution:" << '\n';
display_board(board);
} else
cout << "A solution cannot be found." << '\n';
cout << '\n';
load_board("medium.dat", board);
if (solve_board(board)) {
cout << "The 'medium' board has a solution:" << '\n';
display_board(board);
} else
cout << "A solution cannot be found." << '\n';
cout << '\n';
cout << "=================== Question 5 ===================" << "\n\n";
load_board("mystery1.dat", board);
if (solve_board(board)) {
cout << "The 'mystery1' board has a solution:" << '\n';
display_board(board);
} else
cout << "A solution cannot be found." << '\n';
cout << '\n';
cout << "===============================================" << endl;
solve_mystery_board("mystery1.dat");
cout << "===============================================" << endl;
load_board("mystery2.dat", board);
if (solve_board(board)) {
cout << "The 'mystery2' board has a solution:" << '\n';
display_board(board);
} else
cout << "A solution cannot be found." << '\n';
cout << '\n';
load_board("mystery3.dat", board);
if (solve_board(board)) {
cout << "The 'mystery3' board has a solution:" << '\n';
display_board(board);
} else
cout << "A solution cannot be found." << '\n';
cout << '\n';
cout << "===============================================" << endl;
solve_mystery_board("mystery3.dat");
cout << "===============================================" << endl;
return 0;
}