Giter VIP home page Giter VIP logo

java-sudoku's Introduction

java-sudoku

Current state: Complete. ComputerPlayer can be optimized and may not finish on hard puzzles.

Sudoku written in Java.

This version of sudoku is console based and has two playing methods. There is a NormalPlayer class that allows play as you would expect. There is a ComputerPlayer class that automatically solves the puzzle and you get to watch as it makes each move.

Getting Started

  1. javac Sudoku.java
  2. java Sudoku

Class Descriptions

Sudoku.java -- This class holds the main method which jump starts the game. It creates a new instance of Gameboard and Player (NormalPlayer, Computer Player) it then enters the main game loop which will continue until the gameboard is filled and it passes a few checks confirming that board is correct.

Tile.java -- Is a single location on the board and holds a 1-9 or possibly empty.

Gameboard.java -- This class allows interaction with the board a 9x9 grid of Tiles. It has a two dimensional array of Tiles that form the actual gameboard. It also uses support structures: Quadrant, Vertical and Horizontal. The support structures form the nine vertical collumns, horizontal rows and 3x3 grids in the 9x9 gameboard. It has several methods used to interact with the board.

Player.java -- This class is abstract. NormalPlayer and ComputerPlayer extend it in order to be used in the game. It forces any class that extends it to override the required methods needed to play the game.

ComputerPlayer.java -- Extends Player and provides its own nextMove() method that solves the puzzle.

NormalPlayer.java -- Extends the Player and provides a nextMove() methods that takes input from the command line to play the game.

Move.java -- This class is used to hold an x, y and data. Which correspond to a row, collumn and that number 1-9 that you put at that location. The Move is passed as one object to make it simpler to validate.

Support.java -- Is a helper class that holds nine tiles and can perform checks on those tiles including checking for a duplicate. A Sudoku board must meet certain criteria and three Support objects are used to represent them Quadrant, Horizontal and Vertical.

*.su

These files hold the gameBoard the program loads. It is a comma delimited file where each row corresponds directly to a row on the board.

Solver Methodology

The actual code can be found in ComputerPlayer::nextMove(). Here is the psuedo code.

  1. Iterate through all tiles.
  2. Check if tile is open.
  3. If open iterate 1 - 9 possible values for that tile.
  4. Check if placing that move would create a duplicate in it's quadrant, horizontal or vertical.
  5. If no duplicates exist check if this tile is only location where this index can be put.
  6. Place move.

java-sudoku's People

Contributors

andrewhood125 avatar

Stargazers

 avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.