Add initial classes and a couple of tests for Board
This commit is contained in:
commit
895a9dd01b
15 changed files with 160 additions and 0 deletions
9
.editorconfig
Normal file
9
.editorconfig
Normal file
|
@ -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
|
5
.gitignore
vendored
Normal file
5
.gitignore
vendored
Normal file
|
@ -0,0 +1,5 @@
|
|||
/docs/
|
||||
/lib/
|
||||
/bin/
|
||||
/.shards/
|
||||
*.dwarf
|
6
.travis.yml
Normal file
6
.travis.yml
Normal file
|
@ -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
|
21
LICENSE
Normal file
21
LICENSE
Normal file
|
@ -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.
|
27
README.md
Normal file
27
README.md
Normal file
|
@ -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 (<https://github.com/your-github-user/sudoku/fork>)
|
||||
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
|
13
shard.yml
Normal file
13
shard.yml
Normal file
|
@ -0,0 +1,13 @@
|
|||
name: crystal-sudoku
|
||||
version: 0.1.0
|
||||
|
||||
authors:
|
||||
- Alberto Venturini <aventurini@gmail.com>
|
||||
|
||||
targets:
|
||||
sudoku:
|
||||
main: src/sudoku.cr
|
||||
|
||||
crystal: 0.31.1
|
||||
|
||||
license: MIT
|
16
spec/board_spec.cr
Normal file
16
spec/board_spec.cr
Normal file
|
@ -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
|
2
spec/spec_helper.cr
Normal file
2
spec/spec_helper.cr
Normal file
|
@ -0,0 +1,2 @@
|
|||
require "spec"
|
||||
require "../src/sudoku.cr"
|
5
spec/sudoku_spec.cr
Normal file
5
spec/sudoku_spec.cr
Normal file
|
@ -0,0 +1,5 @@
|
|||
require "./spec_helper"
|
||||
|
||||
describe Sudoku do
|
||||
|
||||
end
|
29
src/board.cr
Normal file
29
src/board.cr
Normal file
|
@ -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
|
7
src/parser.cr
Normal file
7
src/parser.cr
Normal file
|
@ -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
|
7
src/position.cr
Normal file
7
src/position.cr
Normal file
|
@ -0,0 +1,7 @@
|
|||
module Sudoku
|
||||
|
||||
struct Position
|
||||
|
||||
end
|
||||
|
||||
end
|
6
src/solver.cr
Normal file
6
src/solver.cr
Normal file
|
@ -0,0 +1,6 @@
|
|||
module Sudoku
|
||||
class Solver
|
||||
def self.solve(board)
|
||||
end
|
||||
end
|
||||
end
|
7
src/sudoku.cr
Normal file
7
src/sudoku.cr
Normal file
|
@ -0,0 +1,7 @@
|
|||
# TODO: Write documentation for `Sudoku`
|
||||
|
||||
require "./*"
|
||||
|
||||
module Sudoku
|
||||
VERSION = "0.1.0"
|
||||
end
|
BIN
sudoku
Executable file
BIN
sudoku
Executable file
Binary file not shown.
Loading…
Add table
Reference in a new issue