Giter Club home page Giter Club logo

sudoku's Introduction

sudoku

Build Status Dependency Status devDependency Status

This project provides a simple implementation of Sudoku in Javascript, HTML and CSS. It does not use any front-end frameworks like Backbone or Bootstrap.

Each game board is pseudo-randomly generated. This game is responsive and additionally includes support for keyboard navigation on desktop. Players receive instant feedback if their play violates one of the constraints of the game.

This project includes a build system that uses Grunt, Browserify and LESS. The application is tested using Mocha and Chai (for more information on tests, see the testing section).

Hosted version

You can play this Sudoku game online at sudoku.stephenhebson.com.

Running locally

Installation

$ git clone https://github.com/shebson/sudoku.git cd sudoku npm install

Building and running

Build the project and run a development server by running:

$ grunt server

The sudoku game will now be available at http://localhost:8080.

$ open http://localhost:8080

Testing

The application is tested using Mocha. To run the test suite, do npm test. Tests are located in the test directory.

This project uses Travis for continuous integration. Travis runs the test suite whenever a commit is pushed to master.

Style

Code style is enforced by JSLint and JSHint. Application code and configuration code must pass JSLint.

Test code need only pass JSHint, as Chai's expect syntax is incompatible with JSLint (at least until JSLint provides an option for disabling the "expected an assignment or function call..." warning).

Technical notes

Project structure and technologies used

I elected to follow an MV* structure for this project. The project is organized into views, models, and Handlebars templates. Because of the simplicity of this project, many standard components like a router were unnecessary.

The views extend a base view that exposes a minimal delegateEvents method. Rather than providing a .extend method or using constructor functions, I elected to take advantage of JavaScript's prototypal inheritance directly by using Object.create to create new views with the base view's prototype.

There is a strict separation of concerns between models and views. This separation is possible because of a observer design pattern in which the game view and validation highlighter listen for events emitted by the board model.

The application is organized in CommonJS modules and bundled by Browserify. When running locally, the application provides source maps, making it possible to take full advantage of developer tools.

Stylesheets are generated by LESS, and I make heavy use of LESS variables to make them more maintainable.

The build process is built on Grunt. In addition to Browserify and Less, autoprefixer is used to enable DRYer stylesheets, and Uglify compresses the final JavaScript before deploys.

Finally, the game is hosted on Amazon S3, and deploys to S3 are fully automated in a Grunt task (though, for obvious reasons, you'll have to provide your own AWS credentials file to deploy).

Next steps

I'm happy with how this game turned out. I think the choice of structure made it easy to work quickly, and would make it easy to continue iterating if this were an ongoing project.

If I had unlimited time, a couple of things I'd like to improve are:

  • If this were a real product, game difficulty should be selectable.
  • The board generator takes advantage of the fact that you can shuffle a known sudoku board following certain constraints and arrive at a new board. It then removes values until the game is appropriately difficult. The result is great for game play, but it would be fun to try generating the board from scratch using a backtracking algorithm (though that may be less performant than the pseudo-random solution I implemented).

License

MIT

sudoku's People

Contributors

shebson avatar

Watchers

James Cloos avatar  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.