-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
143 lines (111 loc) · 3.79 KB
/
main.cpp
File metadata and controls
143 lines (111 loc) · 3.79 KB
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
#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);
// write more tests
cout << "Putting '6' into H7 is ";
if (!make_move("H7", '6', board))
cout << "NOT ";
cout << "a valid move. The board is:" << '\n';
display_board(board);
cout << "Putting '1' into Z8 is ";
if (!make_move("Z8", '1', board))
cout << "NOT ";
cout << "a valid move. The board is:" << '\n';
display_board(board);
cout << "Putting '4' into I8 is ";
if (!make_move("I8", '4', board))
cout << "NOT ";
cout << "a valid move. The board is:" << '\n';
display_board(board);
cout << "Putting '9' into H7 is ";
if (!make_move("H7", '9', board))
cout << "NOT ";
cout << "a valid move. The board is:" << '\n';
display_board(board);
cout << "Putting '1' into A1 is ";
if (!make_move("A1", '1', board))
cout << "NOT ";
cout << "a valid move. The board is:" << '\n';
display_board(board);
cout << "Putting '5' into C4 is ";
if (!make_move("C4", '5', 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";
//1 doesn't work rn bc it starts from the first value so you need to modify that.
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';
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("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';//1 doesn't work rn bc it starts from the first value so you need to modify that.
// write more tests
return 0;
}