View the step-by-step solution to:

CSCE 2004 - Programming Foundations 1 University of Arkansas, Fayetteville Spring 2016 Assignment 4: Sudoku - Due March 13th at 11: You will read...

Hello,

Needing help on this program. Interactive sudoku board. Please see attachments.

CSCE 2004 – Programming Foundations 1 Spring 2016 University of Arkansas, Fayetteville Assignment 4: Sudoku - Due March 13th at 11:59pm Objective In this assignment, you will simulate a game of Sudoku. You will read numbers from a file that represent the starting position of a Sudoku puzzle and allow the user to play the game until they win or quit. Prerequisites To complete the assignment, you will need to be familiar with the following concepts: How to read and write to/from a file (Chapter 5) How to use functions (Chapter 6) How to create and use arrays (Chapter 7) Description Sudoku is a popular puzzle game in which the player must fill a 9x9 grid with numbers from 1 to 9. To solve the puzzle, the numbers 1 through 9 must appear exactly once in every row, column, and 3x3 square. In this assignment, you will use a 2-D array to represent a Sudoku board. You will be given a file called “ sudoku.txt ” (you do not need to ask the user for a filename). The file will contain 81 numbers denoting the starting configuration of the puzzle. 0 will represent an empty space. To make life easy, you will be provided with some skeleton code. This code will contain four empty functions: isLegalMove , updateBoard , isGameOver , and printBoard . Comments in the code will explain what the input to each function should be, what the output should be, and what the function should do. The body of each function will be empty, and the return type and arguments will be replaced with question marks (???). It will be up to you to write the body of each function, as well as figure out the return types and arguments based on the hints in the comments. When your program is finished, the user should be able to play a complete game of Sudoku. Your program should satisfy the following requirements: At the beginning of the game, and after every time the player makes a move, you should print an aesthetically pleasing representation of the current state of the board. See the sample output for an example of what this might look like. The player should be able to make a move by typing three numbers: the row, the column, and the number they want to write. For example, “3 4 9” means write a 9 in row 3, column 4. Keep in mind that arrays are 0-indexed, so your rows and columns will be numbered 0-8, not 1-9. The player should not be able to make illegal moves. This means a move must not break any of the following 6 rules: 1. The row and column should correspond to a valid position on the board;
CSCE 2004 – Programming Foundations 1 Spring 2016 University of Arkansas, Fayetteville 2. The number to be written should be between 0 and 9 inclusive, where writing 0 means the player wants to erase a number; 3. The player may erase a number only if it was a number they wrote themselves - not it if it was a number that was already part of the starting configuration. This means you will have to maintain a second data structure indicating whether or not each number is “permanent”; 4. A row shall not contain more than one of the same number; 5. A column shall not contain more than one of the same number; 6. Each designated 3x3 block shall not contain more than one of the same number. This does NOT mean every possible 3x3 block. Just the ones designated by bold lines in the following diagram: After every move, the program should check if the game has been won. If so, it should print a congratulatory message of your choice, and then quit. At any point, the user should be able to enter “9 9 9” to end the program. To store the state of the board, you should use a 2-dimensional array of integers. The size of this array will be 9x9. To keep track of which numbers can be erased and which are permanent, you should maintain a parallel array of booleans, where true indicates that a number is permanent, and false indicates that a number is not permanent. The size of this array should also be 9x9, and the boolean at each location (i, j) will correspond to the number on the board with the same coordinates (i, j).
Show entire document
#include <iostream> #include <fstream> using namespace std; /* Input: Sudoku board, row and column where user wants to move, something indicating whether or not that value can be erased, number user wants to write Output: True if the move does not violate any rules, False if it does Purpose: Check if a move is legal */ ??? isLegalMove(???) { } /* Input: Sudoku board, row and column where user wants to move, number user wants to write Output: None Purpose: Update the board to reflect the given move */ ??? updateBoard(???) { } /* Input: Sudoku board Output: True if the game has been won, False otherwise Purpose: Determine if the game is over */ ??? isGameOver(???) { } /* Input: Sudoku board Output: None Function: Print an aesthetically pleasing representation of the board */ ??? printBoard(???) { } int main() { //File operations, board representation, game flow, function calls should all happen here return 0; }

Here is the solution... View the full answer

Why Join Course Hero?

Course Hero has all the homework and study help you need to succeed! We’ve got course-specific notes, study guides, and practice tests along with expert tutors.

-

Educational Resources
• -

Study Documents

Find the best study resources around, tagged to your specific courses. Share your own to gain free Course Hero access.

Browse Documents