-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
143 lines (118 loc) · 3.62 KB
/
main.cpp
File metadata and controls
143 lines (118 loc) · 3.62 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
/* Main file "main.cpp" */
/* Aurthor: Sami Khan
Program last changed: 22/10/2019 */
#include <iostream>
#include "sudoku.h"
#include <time.h>
using namespace std;
/* MAIN FUNCTION */
int main() {
char board[9][9];
char boardC[9][9];
cout << "============= Testing load_board() 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 << "=================== Testing the completeness ===================" << "\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", boardC);
cout << "Board is ";
if (!is_complete(boardC))
cout << "NOT ";
cout << "complete." << "\n\n";
cout << "=================== Testing move ===================" << "\n\n";
load_board("easy.dat", board);
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);
cout << "=================== Testing saving file ===================" << "\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 << "=================== Trying to solve the boards ===================" << "\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';
load_board("test.dat", board);
if (solve_board(board))
{
cout << "The 'test' board has a solution:" << '\n';
display_board(board);
}
else
cout << "A solution cannot be found." << '\n';
cout << '\n';
cout << "=================== Checking run-time of code ===================" << "\n\n";
clock_t beginTime = clock(); // clock used here to calculate runtime for each compilation
float duration = 0.0;
load_board("mystery1.dat", board);
if (solve_board(board))
{
cout << "The 'mystery1' board has a solution:" << '\n';
display_board(board);
duration = ((float)(clock() - beginTime))/CLOCKS_PER_SEC;
cout << "This took " << duration << " seconds to complete.\n";
}
else
{
cout << "A solution cannot be found." << '\n';
duration = 0.0;
}
cout << '\n';
beginTime = clock();
load_board("mystery2.dat", board);
if (solve_board(board))
{
cout << "The 'mystery2' board has a solution:" << '\n';
display_board(board);
duration = ((float)(clock() - beginTime))/CLOCKS_PER_SEC;
cout << "This took " << duration << " seconds to complete.\n";
}
else
{
cout << "A solution cannot be found." << '\n';
duration = 0.0;
}
cout << '\n';
beginTime = clock();
load_board("mystery3.dat", board);
if (solve_board(board))
{
cout << "The 'mystery3' board has a solution:" << '\n';
display_board(board);
duration = ((float)(clock() - beginTime))/CLOCKS_PER_SEC;
cout << "This took " << duration << " seconds to complete.\n";
}
else
{
cout << "A solution cannot be found." << '\n';
duration = 0.0;
}
cout << '\n';
return 0;
}
/* END OF MAIN FUNCTION */