Final preparations for project

This commit is contained in:
Trianta 2023-10-22 05:29:20 -05:00
parent b7217dc877
commit 670027c119
3 changed files with 50 additions and 2 deletions

View File

@ -19,29 +19,72 @@ void Sudoku::FillBoard(std::string filePath) {
sudokuFile >> line;
std::cout << line << std::endl;
}
// TODO: Finish inputting sudoku file
// Really just needs to be split by digit then stored
}
// TODO: Implement solving algorithm
void Sudoku::Solve(void) {
}
// TODO: Add checking for full board completion
bool Sudoku::IsBoardSolved(void) {
return true;
}
// TODO: Add printing of board for visuals
// Maybe also print during solve?
void Sudoku::Print(void) {
}
// TODO: Add checking for row completion
bool Sudoku::IsRowComplete(int row) {
return true;
}
// TODO: Add checking for column completion
bool Sudoku::IsColumnComplete(int column) {
return true;
}
// WARNING: This function and one below could be swapped, untested
std::vector<int> Sudoku::GetUnusedInRow(int row) {
std::vector<int> leftOver{0,1,2,3,4,5,6,7,8,9};
int number;
for (int i = 0; i < 9; i++) {
number = board[i][row];
if (leftOver[number] == number) {
leftOver[number] = 0;
}
if (leftOver[number] == 0) { // Two of same number was placed
leftOver[number] = -1;
}
}
for (auto it = leftOver.begin(); it != leftOver.end();) {
if (*it == 0) { it = leftOver.erase(it); }
else { ++it; }
}
return leftOver;
}
std::vector<int> Sudoku::GetUnusedInColumn(int column) {
std::vector<int> leftOver{0,1,2,3,4,5,6,7,8,9};
int number;
for (int i = 0; i < 9; i++) {
number = board[column][i];
if (leftOver[number] == number) {
leftOver[number] = 0;
}
if (leftOver[number] == 0) { // Two of same number was placed
leftOver[number] = -1;
}
}
for (auto it = leftOver.begin(); it != leftOver.end();) {
if (*it == 0) { it = leftOver.erase(it); }
else { ++it; }
}
return leftOver;
}

View File

@ -11,6 +11,7 @@ public:
void FillBoard(std::string filePath);
void Solve(void);
bool IsBoardSolved(void);
void Print(void);
private:
bool IsRowComplete(int row);
bool IsColumnComplete(int column);

View File

@ -1,5 +1,9 @@
#include "sudoku.hpp"
// TODO:
// Take in sudoku file from arguments
// Run solve
// Print solution
int main(void) {
return 0;
}