-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathInterface.h
More file actions
91 lines (85 loc) · 2.95 KB
/
Interface.h
File metadata and controls
91 lines (85 loc) · 2.95 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
//
// Created by Jgw on 27/2/19.
//
#ifndef TESTC_INTERFACE_H
#define TESTC_INTERFACE_H
#include "SudokuSolver.h"
#include "Dpll.h"
class App {
private:
SudokuSolver sudokuSolver;
SatSolver satSolver;
CnfParser cnfParser;
public:
App() {
sudokuSolver = *new SudokuSolver;
satSolver = *new SatSolver;
}
void Start() {
for (;;) {
cout << "---------------------" << endl;
cout << "Welcome" << endl;
cout << "1.Sudoku Game" << endl;
cout << "2.Solve SAT" << endl;
cout << "0.Exit" << endl;
cout << "---------------------" << endl;
int status;
cin >> status;
if (status == 0)
break;
else if (status == 1) {
sudokuSolver.Reset();
sudokuSolver.GenerateFinal();
cout << "Question: " << endl;
sudokuSolver.ShowBoard(-1);
cout << "input Row Column and Number to fill blanks,input 0 to submit,input -1 to cheat" << endl;
int row = 0, column = 0, num = 0;
for (;;) {
cin >> row;
if (row == 0) {
if (sudokuSolver.submit()) {
cout << "Correct!" << endl;
break;
} else {
cout << "Wrong!" << endl;
sudokuSolver.ShowBoard(-1);
continue;
}
} else if (row == -1) {
sudokuSolver.Cheat();
sudokuSolver.ShowBoard(-1);
} else {
cin >> column >> num;
if (sudokuSolver.fill(row - 1, column - 1, num)) {
sudokuSolver.ShowBoard(-1);
continue;
} else {
cout << "Invalid Input" << endl;
sudokuSolver.ShowBoard(-1);
continue;
}
}
}
} else if (status == 2) {
cout << "Input Name" << endl;
string targetName;
cin >> targetName;
try {
Formula formula = cnfParser.readCnf(targetName);
Solution solution = satSolver.Solve(formula, cnfParser.symbolNum);
cnfParser.outputSolution(satSolver.status, solution, satSolver.time);
satSolver.OutputLog();
continue;
}
catch (...) {
cout << "Invalid Input!" << endl;
continue;
}
} else {
cout << "Invalid Input!" << endl;
continue;
}
}
}
};
#endif //TESTC_INTERFACE_H