Skip to content

Commit c0c6488

Browse files
committed
Class Project status
The actual submission source files for my C Programming class final project
1 parent 2eae33a commit c0c6488

14 files changed

+2890
-0
lines changed

sudoku.c

Lines changed: 120 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,120 @@
1+
/******************************************************************************
2+
* Program: sudoku.c
3+
*
4+
* Purpose: To implement a sudoku application, with assistant functions to help
5+
* user solve sudoku puzzles
6+
*
7+
* Developer: Philip Ormand
8+
*
9+
* Date: 5/13/16
10+
*
11+
****************************************************************************/
12+
#include <stdio.h>
13+
#include <stdlib.h>
14+
#include <string.h>
15+
16+
#include "sudoku_board.h"
17+
#include "sudoku_commands.h"
18+
#include "sudoku_test_digits.h"
19+
#include "sudoku_utility.h"
20+
21+
/*
22+
* ======= SUDOKU SEMANTICS ======= (AKA, my chosen definitions for terms in variable names, etc.)
23+
* 'board': the sudoku puzzle space. The actual matrix that makes up a given puzzle or solution.
24+
* 'square': individual space for a digit on a sudoku board. A sudoku board is 9 squares by 9 squares.
25+
* 'row' / 'column': self-explanitory. A horizontal or vertical row of squares on the sudoku board.
26+
* 'block' : the 9 3x3 blocks of squares that must each contain the digits 1-9 on the sudoku board.
27+
*
28+
* Which block is which?
29+
* +---+---+---+
30+
* | 1 | 2 | 3 |
31+
* +---+---+---+
32+
* | 4 | 5 | 6 |
33+
* +---+---+---+
34+
* | 7 | 8 | 9 |
35+
* +---+---+---+
36+
*/
37+
38+
int main(int argc, char* argv[])
39+
{
40+
bool running = true;
41+
struct SudokuBoard board = { 0 };
42+
struct SudokuCommandInput commandInput = { 0 };
43+
const struct SudokuCommand *command = NULL;
44+
SudokuCommandResult status = SUDOKU_COMMAND_SUCCESS;
45+
46+
initializeSudokuBoard(&board);
47+
initializeString(&commandInput.string);
48+
49+
// if one argument was provided, go ahead and load sudoku board from textfile
50+
if (argc > 1)
51+
{
52+
// if filename provided by argument cannot be found/read, loadSudokuBoard will
53+
// print an error statement, and execution will continue with a blank board
54+
loadSudokuBoard(argv[1], &board);
55+
}
56+
57+
puts("========== Sudoku Game ==========");
58+
puts(showAllCommandsPrompt);
59+
putchar('\n');
60+
printSudokuBoard(&board);
61+
62+
while (running)
63+
{
64+
// put extra space between previous output and command prompt
65+
putchar('\n');
66+
67+
command = getCommand(&commandInput);
68+
69+
status = command->commandFunction(&board, &commandInput);
70+
71+
if (status == SUDOKU_COMMAND_USAGE)
72+
{
73+
printf("Usage: '%s'\n", command->usagePrompt);
74+
}
75+
else if (status == SUDOKU_COMMAND_EXIT)
76+
{
77+
running = false;
78+
}
79+
}
80+
81+
freeHistory(&board.history);
82+
83+
return 0;
84+
}
85+
86+
87+
/*
88+
int main(int argc, char **argv)
89+
{
90+
char *fileName = "sudoku_text_file.txt";
91+
FILE *sudokuTextFile;
92+
struct SudokuBoard board;
93+
94+
if (argc == 2)
95+
{
96+
// if an argument was provided
97+
fileName = argv[1];
98+
}
99+
100+
initializeSudokuBoard(&board);
101+
102+
if ( (sudokuTextFile = fopen(fileName, "r")) == NULL )
103+
{
104+
terminate("ERROR: couldn't open sudoku file");
105+
}
106+
107+
if ( !readSudokuBoard(sudokuTextFile, &board) )
108+
{
109+
exit(EXIT_FAILURE); // error message printed by readSudokuBoard
110+
}
111+
112+
printSudokuBoard(&board);
113+
putchar('\n');
114+
115+
puts("Evaluating solution:");
116+
evaluateDigitsPresent(&board);
117+
118+
exit(EXIT_SUCCESS);
119+
}
120+
*/

0 commit comments

Comments
 (0)