sashite-cpn 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 6830c4520f3621c796a6d5a4a723a1c672d454f6
4
+ data.tar.gz: 59c64f01c3ff30ddc5e8f7db3d3a322e16f144dc
5
+ SHA512:
6
+ metadata.gz: 59e97c50a55fb524023db8048445e0d26116ee471a1c783b09c57b44d0ab5e83cd7be543304629cc1ca63a967aec7ebc9ceb6267b6e7636b64a949410e9c9a9b
7
+ data.tar.gz: 46755b1e85057e93b6228fc579e1d0574ac28bd100efd240323085bfb8b3d357ca2fdb5b169390bd2752821107cd841893e8f0d6ae3b5a640c9cbf65483f93d5
@@ -0,0 +1,10 @@
1
+ /.bundle/
2
+ /.ruby-version
3
+ /.yardoc
4
+ /Gemfile.lock
5
+ /_yardoc/
6
+ /coverage/
7
+ /doc/
8
+ /pkg/
9
+ /spec/reports/
10
+ /tmp/
@@ -0,0 +1,14 @@
1
+ language: ruby
2
+ sudo: false
3
+ cache: bundler
4
+ script: 'bundle exec rake test:coverage --trace'
5
+ before_install:
6
+ - gem install bundler
7
+ rvm:
8
+ - 1.9.3
9
+ - 2.0
10
+ - 2.1
11
+ - 2.2
12
+ - jruby
13
+ - jruby-head
14
+ - rbx-2
@@ -0,0 +1,13 @@
1
+ # Contributor Code of Conduct
2
+
3
+ As contributors and maintainers of this project, we pledge to respect all people who contribute through reporting issues, posting feature requests, updating documentation, submitting pull requests or patches, and other activities.
4
+
5
+ We are committed to making participation in this project a harassment-free experience for everyone, regardless of level of experience, gender, gender identity and expression, sexual orientation, disability, personal appearance, body size, race, ethnicity, age, or religion.
6
+
7
+ Examples of unacceptable behavior by participants include the use of sexual language or imagery, derogatory comments or personal attacks, trolling, public or private harassment, insults, or other unprofessional conduct.
8
+
9
+ Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct. Project maintainers who do not follow the Code of Conduct may be removed from the project team.
10
+
11
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by opening an issue or contacting one or more of the project maintainers.
12
+
13
+ This Code of Conduct is adapted from the [Contributor Covenant](http://contributor-covenant.org), version 1.0.0, available at [http://contributor-covenant.org/version/1/0/0/](http://contributor-covenant.org/version/1/0/0/)
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gemspec
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2015 Cyril Wack
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
@@ -0,0 +1,55 @@
1
+ # Sashite::Cpn
2
+
3
+ [![Build Status](https://travis-ci.org/sashite/cpn.rb.svg?branch=master)][travis]
4
+ [![Gem Version](https://badge.fury.io/rb/sashite-cpn.svg)][gem]
5
+ [![Inline docs](http://inch-ci.org/github/sashite/cpn.rb.svg?branch=master)][inchpages]
6
+ [![Documentation](http://img.shields.io/:yard-docs-38c800.svg)][rubydoc]
7
+
8
+ Export in to the [CPN format](http://www.sashite.com/developer/wiki/Chess-Position-Notation).
9
+
10
+ ## Installation
11
+
12
+ Add this line to your application's Gemfile:
13
+
14
+ ```ruby
15
+ gem 'sashite-cpn'
16
+ ```
17
+
18
+ And then execute:
19
+
20
+ $ bundle
21
+
22
+ Or install it yourself as:
23
+
24
+ $ gem install sashite-cpn
25
+
26
+ ## Usage
27
+
28
+ ```ruby
29
+ Sashite::Cpn.generate(false, [8, 8], ['w:r', 'w:n', 'w:b', 'w:q', 'w:^k', 'w:b', 'w:n', 'w:r',
30
+ 'w:p', 'w:p', 'w:p', 'w:p', 'w:p', 'w:p', 'w:p', 'w:p',
31
+ nil, nil, nil, nil, nil, nil, nil, nil,
32
+ nil, nil, nil, nil, nil, nil, nil, nil,
33
+ nil, nil, nil, nil, nil, nil, nil, nil,
34
+ nil, nil, nil, nil, nil, nil, nil, nil,
35
+ 'W:P', 'W:P', 'W:P', 'W:P', 'W:P', 'W:P', 'W:P', 'W:P',
36
+ 'W:R', 'W:N', 'W:B', 'W:Q', 'W:^K', 'W:B', 'W:N', 'W:R'], [])
37
+ # => 'B--8,8--w:r,w:n,w:b,w:q,w:^k,w:b,w:n,w:r,w:p,w:p,w:p,w:p,w:p,w:p,w:p,w:p,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,W:P,W:P,W:P,W:P,W:P,W:P,W:P,W:P,W:R,W:N,W:B,W:Q,W:^K,W:B,W:N,W:R--'
38
+ ```
39
+
40
+ ## Contributing
41
+
42
+ Bug reports and pull requests are welcome on GitHub at https://github.com/sashite/cpn.rb. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](contributor-covenant.org) code of conduct.
43
+
44
+ ## Versioning
45
+
46
+ __Sashite::Cpn__ follows [Semantic Versioning 2.0](http://semver.org/).
47
+
48
+ ## License
49
+
50
+ See `LICENSE.md` file.
51
+
52
+ [gem]: https://rubygems.org/gems/sashite-cpn
53
+ [travis]: https://travis-ci.org/sashite/cpn.rb
54
+ [inchpages]: http://inch-ci.org/github/sashite/cpn.rb/
55
+ [rubydoc]: http://rubydoc.info/gems/sashite-cpn/frames
@@ -0,0 +1,20 @@
1
+ require 'bundler/gem_tasks'
2
+ require 'rake/testtask'
3
+ require 'rubocop/rake_task'
4
+
5
+ RuboCop::RakeTask.new
6
+
7
+ Rake::TestTask.new do |t|
8
+ t.verbose = true
9
+ t.warning = true
10
+ end
11
+
12
+ namespace :test do
13
+ task :coverage do
14
+ ENV['COVERAGE'] = 'true'
15
+ Rake::Task['test'].invoke
16
+ end
17
+ end
18
+
19
+ task(:doc_stats) { ruby '-S yard stats' }
20
+ task default: [:test, :doc_stats, :rubocop]
@@ -0,0 +1 @@
1
+ 0.1.0
@@ -0,0 +1,7 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'bundler/setup'
4
+ require 'sashite/cpn'
5
+
6
+ require 'irb'
7
+ IRB.start
@@ -0,0 +1,5 @@
1
+ #!/bin/bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+
5
+ bundle install
@@ -0,0 +1,49 @@
1
+ # Global namespace.
2
+ module Sashite
3
+ # Namespace for the library.
4
+ module Cpn
5
+ # Generate the CPN.
6
+ #
7
+ # @param bool [Boolean] The turn to play.
8
+ # @param indexes [Array] The shape of the board.
9
+ # @param squares [Array] The board structure.
10
+ # @param pieces [Array] The list of pieces in hand.
11
+ def self.generate(bool, indexes, squares, pieces)
12
+ Generate.new(bool, indexes, squares, pieces).to_s
13
+ end
14
+
15
+ # Custom error raised with indexes and squares are not synchonized.
16
+ class LengthError < RuntimeError
17
+ end
18
+
19
+ # Main class.
20
+ class Generate
21
+ # @param bool [Boolean] The turn to play.
22
+ # @param indexes [Array] The shape of the board.
23
+ # @param squares [Array] The board structure.
24
+ # @param pieces [Array] The list of pieces in hand.
25
+ def initialize(bool, indexes, squares, pieces)
26
+ fail LengthError unless indexes.inject(:*).to_i.equal?(squares.length)
27
+
28
+ @turn = Turn.new(bool)
29
+ @shape = Shape.new(*indexes)
30
+ @position = Position.new(*squares)
31
+ @pieces_in_hand = PiecesInHand.new(*pieces)
32
+ end
33
+
34
+ # @return [String] A CPN string.
35
+ def to_s
36
+ [
37
+ @turn.to_s,
38
+ @shape.to_s,
39
+ @position.to_s,
40
+ @pieces_in_hand.to_s
41
+ ].join('--')
42
+ end
43
+ end
44
+ end
45
+ end
46
+
47
+ Dir[File.join File.dirname(__FILE__), 'cpn', '*.rb'].each do |fname|
48
+ require_relative fname
49
+ end
@@ -0,0 +1,23 @@
1
+ # Global namespace.
2
+ module Sashite
3
+ # Namespace for the library.
4
+ module Cpn
5
+ # Pieces in hand class.
6
+ class PiecesInHand
7
+ # @param pieces [Array] The list of pieces in hand.
8
+ def initialize(*pieces)
9
+ @pieces = pieces.map(&:to_s).sort
10
+ end
11
+
12
+ # @!attribute [r] pieces
13
+ #
14
+ # @return [Array] The list of pieces in hand.
15
+ attr_reader :pieces
16
+
17
+ # @return [String] A string representation.
18
+ def to_s
19
+ pieces.join(',')
20
+ end
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,23 @@
1
+ # Global namespace.
2
+ module Sashite
3
+ # Namespace for the library.
4
+ module Cpn
5
+ # Position class.
6
+ class Position
7
+ # @param squares [Array] The list of squares.
8
+ def initialize(*squares)
9
+ @squares = squares
10
+ end
11
+
12
+ # @!attribute [r] squares
13
+ #
14
+ # @return [Array] The list of squares.
15
+ attr_reader :squares
16
+
17
+ # @return [String] A string representation.
18
+ def to_s
19
+ squares.join(',')
20
+ end
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,23 @@
1
+ # Global namespace.
2
+ module Sashite
3
+ # Namespace for the library.
4
+ module Cpn
5
+ # Shape class.
6
+ class Shape
7
+ # @param indexes [Array] The list of indexes.
8
+ def initialize(*indexes)
9
+ @indexes = indexes
10
+ end
11
+
12
+ # @!attribute [r] indexes
13
+ #
14
+ # @return [Array] The list of indexes.
15
+ attr_reader :indexes
16
+
17
+ # @return [String] A string representation.
18
+ def to_s
19
+ indexes.join(',')
20
+ end
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,27 @@
1
+ # Global namespace.
2
+ module Sashite
3
+ # Namespace for the library.
4
+ module Cpn
5
+ # Turn class.
6
+ class Turn
7
+ # @param b [Boolean] The turn to play (topside: true, bottomside: false).
8
+ def initialize(b)
9
+ @b = b
10
+ end
11
+
12
+ # @return [Boolean] Returns false when the turn to play is for bottom.
13
+ def turn_to_topside?
14
+ @b
15
+ end
16
+
17
+ # @return [String] A string representation.
18
+ def to_s
19
+ if turn_to_topside?
20
+ 't'
21
+ else
22
+ 'B'
23
+ end
24
+ end
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,24 @@
1
+ Gem::Specification.new do |spec|
2
+ spec.name = 'sashite-cpn'
3
+ spec.version = File.read('VERSION.semver').chomp
4
+ spec.authors = ['Cyril Wack']
5
+ spec.email = ['contact@cyril.email']
6
+
7
+ spec.summary = 'CPN generator.'
8
+ spec.description = 'A CPN generator for Ruby.'
9
+ spec.homepage = 'https://github.com/sashite/cpn.rb'
10
+ spec.license = 'MIT'
11
+
12
+ spec.files =
13
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^test/}) }
14
+ spec.bindir = 'exe'
15
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
16
+ spec.require_paths = ['lib']
17
+
18
+ spec.add_development_dependency 'bundler', '~> 1.10'
19
+ spec.add_development_dependency 'rake', '~> 10.4'
20
+ spec.add_development_dependency 'yard', '~> 0.8'
21
+ spec.add_development_dependency 'simplecov', '~> 0.10'
22
+ spec.add_development_dependency 'rubocop', '~> 0.35'
23
+ spec.add_development_dependency 'spectus', '~> 3.0'
24
+ end
metadata ADDED
@@ -0,0 +1,145 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: sashite-cpn
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Cyril Wack
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2015-11-10 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.10'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.10'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.4'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.4'
41
+ - !ruby/object:Gem::Dependency
42
+ name: yard
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '0.8'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '0.8'
55
+ - !ruby/object:Gem::Dependency
56
+ name: simplecov
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '0.10'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '0.10'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rubocop
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '0.35'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '0.35'
83
+ - !ruby/object:Gem::Dependency
84
+ name: spectus
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: '3.0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: '3.0'
97
+ description: A CPN generator for Ruby.
98
+ email:
99
+ - contact@cyril.email
100
+ executables: []
101
+ extensions: []
102
+ extra_rdoc_files: []
103
+ files:
104
+ - ".gitignore"
105
+ - ".travis.yml"
106
+ - CODE_OF_CONDUCT.md
107
+ - Gemfile
108
+ - LICENSE.md
109
+ - README.md
110
+ - Rakefile
111
+ - VERSION.semver
112
+ - bin/console
113
+ - bin/setup
114
+ - lib/sashite/cpn.rb
115
+ - lib/sashite/cpn/pieces_in_hand.rb
116
+ - lib/sashite/cpn/position.rb
117
+ - lib/sashite/cpn/shape.rb
118
+ - lib/sashite/cpn/turn.rb
119
+ - sashite-cpn.gemspec
120
+ homepage: https://github.com/sashite/cpn.rb
121
+ licenses:
122
+ - MIT
123
+ metadata: {}
124
+ post_install_message:
125
+ rdoc_options: []
126
+ require_paths:
127
+ - lib
128
+ required_ruby_version: !ruby/object:Gem::Requirement
129
+ requirements:
130
+ - - ">="
131
+ - !ruby/object:Gem::Version
132
+ version: '0'
133
+ required_rubygems_version: !ruby/object:Gem::Requirement
134
+ requirements:
135
+ - - ">="
136
+ - !ruby/object:Gem::Version
137
+ version: '0'
138
+ requirements: []
139
+ rubyforge_project:
140
+ rubygems_version: 2.4.5.1
141
+ signing_key:
142
+ specification_version: 4
143
+ summary: CPN generator.
144
+ test_files: []
145
+ has_rdoc: