Skip to content

HarryTranAU/terminal_app

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

38 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Harry's Sudoku App


Help File

Dependencies:

Python 3.8.3
termcolor==1.1.0 

How to install and start Application:

1. Extract files
2. cd HarryTran_T1A3/src/
3. chmod +x main.py
4. ./main.py

optional args:

--help : print a list of optional arguments
--rule : print out the rules for sudoku
--colorblind : change error colors from default (red, no background) to blue with white background

To use the Sudoku Solver:

1. Start the application
2. Type '1' or 'Solver'

To play a generated Sudoku:

1. Start the application
2. Type '2' or 'Play'

Software Development Plan


Application Purpose and Scope

Describe at a high level what the application will do

Sudoku is a number puzzle played on a 9x9 grid. The goal of the puzzle is to fill in the 9x9 grid with the numbers 1-9 abiding by the following rule. Each row, column, and 3x3 box cannot have two of the same number.

This application will allow the user to solve a standard 9x9 sudoku and generate a sudoku of varying difficulty to play.

Identify the problem it will solve and explain why you are developing it

The benefits of using this application:

  • Improves concentration/memory
  • Reduce stress and anxiety
  • Promote a healthy mindset
  • Helps kids develop their problem solving skills

Mental health is a global issue that can be supported from multiple fronts. This application can help people of all ages by stimulating their minds.

Identify the target audience

  • Individuals who are interested in puzzles and board games
  • Educators looking to help students improve focus/concentration/memory
  • Businesses looking to give employees options to reduce stress

Explain how a member of the target audience will use it

A user with an unsolved Sudoku would open the Sudoku application. Then choose the solver option. Input their unsolved sudoku. Receive a solution to their Sudoku.

Having a little extra time on their hands the user would select the Play option in the navigation to generate a new Sudoku to play.


Features

Sudoku Solver

The solver takes in the user's unsolved Sudoku 1 row at a time. Until all 9 rows have been completed. The solver will check if the Sudoku is valid(Follows the rules of Sudoku). Then proceeds to solve the Sudoku.

The algorithm chosen for this solver uses backtracking and recursion. The algorithm finds an empty cell denoted with a '0' starting from the top left, and loops through left to right and top to bottom. Then tries to find a valid number to place in the empty cell. If a valid number is found the solver function calls itself again to find the next empty cell after. If no valid number is found the function returns to the previous cell and tries the next valid number. This loop continues until the sudoku is solved.

Image below shows the input then the solver's solution.

Solver Solution

Sudoku Generator

The Sudoku generator takes in the user input of difficulty(easy, medium, hard) and outputs a valid Sudoku.

The method used to generate a Sudoku incorporates the python random module. A list of numbers 1 to 9 is shuffled. Then placed randomly on a 9x9 grid. The Sudoku generator uses the solve function to complete the Sudoku puzzle. Then numbers are removed randomly according to the difficulty selected by the user.

Image below shows the Sudoku generator for the medium difficulty.

Medium Generated Sudoku

Play Mode

The user is able to play a generated sudoku. The play function uses a coordinate system to take user input. The play function expects 3 characters. The first character is the horizontal axis (a-i), the second character is the vertical axis (1-9), the last character is the user answer (1-9).

Image below shows the play function waiting for user input.

User Input - Play Function

Timer

The timer feature shows the user how long they took to solve the generated Sudoku. The timer will wait for the user to press enter before beginning. Then stops when the user finishes the Sudoku.

Image below shows the finish time of a completed generated Sudoku.

Timer Feature

Difficulty

The difficulty feature allows the user to generate Sudoku of varying difficulty. Easy, medium and hard are the options available. The difficulty determines how many numbers are missing in the generated sudoku.

Image below shows the difficulty options available to the user.

Difficulty Feature


User Interaction

Sudoku Generator

App Start > Navigation > (Solver option)

The Sudoku Generator option is shown to the user in the main navigation menu. The option can be selected with '1' or 'solver'. Upper case and spaces are removed for input leniency.

Navigation

The user will input their unsolved Sudoku one row at a time.

The solver expects a string of 9 integers. Should the user deviate the application will show an error in colored text to the user.

Possible errors in solver:

User press 'enter' with no input

No Input Error

User enters 'back' when list is empty

Nothing to remove Error

User input is bigger or smaller than 9 characters

Invalid length Error

User input has characters other than 0-9

Invalid input Error

Sudoku Generator

App Start > Navigation > (Play option)

The user interacts with the generator by choosing the 'Play' option in the navigation. The user does not directly interact with the generator, but does influence the outcome by choosing a difficulty.

Difficulty

App Start > Navigation > (Play option) > (difficulty selection)

After choosing the play option the user will be required to choose a difficulty.

Difficulty Feature

Should the user deviate from the choices given, an error in colored text will be shown.

Difficulty input error

Timer

App Start > Navigation > (Play option) > (difficulty selection) > (timer decision)

The user has the option to time their sudoku game. This option is available after choosing a difficulty. Only options are 'yes' and 'no'. If user deviates, an error message will be shown in colored text.

Timer input error

Play Mode

App Start > Navigation > (Play option) > (difficulty selection) > (timer decision) > (play mode)

The play feature is shown on the navigation menu. The user can select the play feature by typing '1' or 'Play'. The user will need to select a difficulty and timer before play can commence.

During play mode the user will be required to enter their answer using the application's notation. 3 character string is expected. The first character is the horizontal axis(a-i), the second character is the vertical axis(1-9), followed by the user's answer(1-9).

Possible errors during play: (errors found will be displayed in colored text)

Invalid move length - User input bigger or smaller than 3 characters

Play - Invalid length error

Invalid move - expecting (a-i)(1-9)(1-9)

Play - Invalid move error

Cannot overwrite cell - User tries to overwrite cell that is not originally empty

Play - Overwrite error

Duplicate found - User answer is already found in row/column/square

Play - Duplicate error


Control Flow

Sudoku App Flow Chart


Implementation Plan

Implementation was split into 3 parts. Each with sub-goals. Start date was 11/7/2020

As this was my first time officially using an implementation plan. I opted to put due dates on categories instead of individual functions/sub-goals.

Implementation Plan, Developer Logs, and README are not included in breakdown as they were progressed alongside all 3 parts.

Solver was created first because the solver is used in the generator. Generator was created second because play requires a generated sudoku.

  1. Solver (Due: 13/7/20 Duration: 2 days)

    1. Flow Diagram
    2. Print Grid
    3. Move Validation
    4. Whole Sudoku Validation
    5. Solve Function
    6. User input
    7. Error handling
  2. Generator/Difficulty (Due: 15/7/20 Duration: 2 days)

    1. Flow Diagram extension
    2. Generate Sudoku (no difficulty modifier)
    3. Add difficulty modifier
    4. Ask/give solution after generation
    5. Error handling
  3. Play Mode/Timer (Due: 17/7/20 Duration: 2 days)

    1. Flow Diagram extension
    2. Grid display with coordinates
    3. Play instructions
    4. List of empty cells (for overwrite error)
    5. Take user input
    6. Check move is valid
    7. Add move to grid
    8. Test: game finish
    9. Timer function
    10. Error handling

Implementation Plan part 1

Implementation Plan part 2

Implementation Plan part 3


Testing

Tests were performed manually by myself, classmates, and instructors. The tests outlined below formed the basis of structured testing. Further testing would require the tester to play around with the application unscripted.

Manual Testing


About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages