-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.cc
44 lines (37 loc) · 1.08 KB
/
main.cc
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
#include "cell.h"
#include "game.h"
#include <iostream>
#include <sstream>
#include <string>
#include <vector>
using namespace std;
int main() {
try {
Game myGame;
myGame.setupGame(); // Read in sudoku, set it up
myGame.printGame(); // Print sudoku
// Backtracking portion
// Unsolved cells are a linked list
Cell *start = myGame.setBacktrack();
while(!myGame.checkSolved()) {
Cell *btCell = start;
int lowestNumPos = 10;
Cell *curNode = start;
// Find the cell with the lowest number of possibilities
while(curNode != NULL) {
if(curNode->getVal() < lowestNumPos && curNode->getVal() == 0) {
btCell = curNode;
lowestNumPos = curNode->getNumPos();
}
curNode = curNode->getNextNode();
}
// Guess its first possibility
if(lowestNumPos != 0 && lowestNumPos != 10) {
myGame.nextGuess(btCell);
} else { // Out of possibilities, backtrack
myGame.backtrack();
}
}
myGame.printGame();
} catch (...) { cout << "Invalid Sudoku puzzle" << endl; }
}