commit 895a9dd01b21d5038aac0e62bfc7bc37971931e6 Author: Alberto Venturini Date: Mon Oct 28 07:14:02 2019 +0200 Add initial classes and a couple of tests for Board diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 0000000..163eb75 --- /dev/null +++ b/.editorconfig @@ -0,0 +1,9 @@ +root = true + +[*.cr] +charset = utf-8 +end_of_line = lf +insert_final_newline = true +indent_style = space +indent_size = 2 +trim_trailing_whitespace = true diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..0bb75ea --- /dev/null +++ b/.gitignore @@ -0,0 +1,5 @@ +/docs/ +/lib/ +/bin/ +/.shards/ +*.dwarf diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 0000000..765f0e9 --- /dev/null +++ b/.travis.yml @@ -0,0 +1,6 @@ +language: crystal + +# Uncomment the following if you'd like Travis to run specs and check code formatting +# script: +# - crystal spec +# - crystal tool format --check diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..72d4c31 --- /dev/null +++ b/LICENSE @@ -0,0 +1,21 @@ +The MIT License (MIT) + +Copyright (c) 2019 Alberto Venturini + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. diff --git a/README.md b/README.md new file mode 100644 index 0000000..d190f6d --- /dev/null +++ b/README.md @@ -0,0 +1,27 @@ +# sudoku + +TODO: Write a description here + +## Installation + +TODO: Write installation instructions here + +## Usage + +TODO: Write usage instructions here + +## Development + +TODO: Write development instructions here + +## Contributing + +1. Fork it () +2. Create your feature branch (`git checkout -b my-new-feature`) +3. Commit your changes (`git commit -am 'Add some feature'`) +4. Push to the branch (`git push origin my-new-feature`) +5. Create a new Pull Request + +## Contributors + +- [Alberto Venturini](https://github.com/your-github-user) - creator and maintainer diff --git a/shard.yml b/shard.yml new file mode 100644 index 0000000..a5606d7 --- /dev/null +++ b/shard.yml @@ -0,0 +1,13 @@ +name: crystal-sudoku +version: 0.1.0 + +authors: + - Alberto Venturini + +targets: + sudoku: + main: src/sudoku.cr + +crystal: 0.31.1 + +license: MIT diff --git a/spec/board_spec.cr b/spec/board_spec.cr new file mode 100644 index 0000000..092142d --- /dev/null +++ b/spec/board_spec.cr @@ -0,0 +1,16 @@ +require "./spec_helper" + +describe Sudoku::Board do + + it "initialized grid with nil values" do + board = Sudoku::Board.new(8, 8) + board.get(0, 0).should eq nil + end + + it "puts numbers correctly" do + board = Sudoku::Board.new(8, 8) + board.put(1, 0, 0) + board.get(0, 0).should eq 1 + end + +end diff --git a/spec/spec_helper.cr b/spec/spec_helper.cr new file mode 100644 index 0000000..2855210 --- /dev/null +++ b/spec/spec_helper.cr @@ -0,0 +1,2 @@ +require "spec" +require "../src/sudoku.cr" diff --git a/spec/sudoku_spec.cr b/spec/sudoku_spec.cr new file mode 100644 index 0000000..f45d891 --- /dev/null +++ b/spec/sudoku_spec.cr @@ -0,0 +1,5 @@ +require "./spec_helper" + +describe Sudoku do + +end diff --git a/src/board.cr b/src/board.cr new file mode 100644 index 0000000..9a45cc8 --- /dev/null +++ b/src/board.cr @@ -0,0 +1,29 @@ + +module Sudoku + + class Board + + alias Value = Nil | Int8 + + enum State + Valid + Invalid + end + + getter grid + + def initialize(@width : Int8, @height : Int8) + @grid = Array(Value).new(@width * @height, nil) + end + + def put(value : Value, x, y) + @grid[y * @width + x] = value + end + + def get(x, y) + @grid[y * @width + x] + end + + end + +end \ No newline at end of file diff --git a/src/parser.cr b/src/parser.cr new file mode 100644 index 0000000..7800c99 --- /dev/null +++ b/src/parser.cr @@ -0,0 +1,7 @@ +module Sudoku + # Parse a sudoku board from a string. Return a board. + class Parser + def self.parse(board_str) + end + end +end \ No newline at end of file diff --git a/src/position.cr b/src/position.cr new file mode 100644 index 0000000..25a0b3c --- /dev/null +++ b/src/position.cr @@ -0,0 +1,7 @@ +module Sudoku + + struct Position + + end + +end \ No newline at end of file diff --git a/src/solver.cr b/src/solver.cr new file mode 100644 index 0000000..5a52bff --- /dev/null +++ b/src/solver.cr @@ -0,0 +1,6 @@ +module Sudoku + class Solver + def self.solve(board) + end + end +end \ No newline at end of file diff --git a/src/sudoku.cr b/src/sudoku.cr new file mode 100644 index 0000000..defe90e --- /dev/null +++ b/src/sudoku.cr @@ -0,0 +1,7 @@ +# TODO: Write documentation for `Sudoku` + +require "./*" + +module Sudoku + VERSION = "0.1.0" +end diff --git a/sudoku b/sudoku new file mode 100755 index 0000000..d456cee Binary files /dev/null and b/sudoku differ