sashite-cgsn 0.2.1 → 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 3013f074440a18a711503672a4ea6e37307692d3c58b64742530e267330e9ca6
4
- data.tar.gz: 68864b081fbf338eb2bec945295695064f0d19acac1a4ac37ec313f99bb7f09d
3
+ metadata.gz: 4a4b0e4315400be9e2678b80d4ab0cc80376084f7884a6b2b83f90807a948fad
4
+ data.tar.gz: 3cd371946d9525c43335fc552383b349a96e18b6532f5e58997a7af9f61e84fa
5
5
  SHA512:
6
- metadata.gz: 86d1393ca014e448c7ca00193e3faba5968da1599783ea21a88575584a13dbf8669aabdeb44fb5aea45f0b0165e08365141411117320317189152bf984c8c2d1
7
- data.tar.gz: e0745151074883807146c8114856f3675b75417676821baedf5e7e29d79994c0340e4ffe977243e71ad0c3e17dab1e91c7f2e8814b02c938aa04b5b87556ab44
6
+ metadata.gz: cb1a3c4c580bbb1ba11692629e2288a4279cddd43d59341d72e7a4e65e4c932a02d918cfb6abf2a165f9e8ea482b44256b3e5a5665d3ec169f8f06a5f1983cd3
7
+ data.tar.gz: bb97f53eaf9f3818cd3c865ee773c8aab292e5bef628e3bd0ba77ccd3ce2c3eb919be41f288872cc93cd03af3d80aa3b28eff63f472d0919d79c7e61a1ef20e9
data/LICENSE ADDED
@@ -0,0 +1,201 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ APPENDIX: How to apply the Apache License to your work.
179
+
180
+ To apply the Apache License to your work, attach the following
181
+ boilerplate notice, with the fields enclosed by brackets "[]"
182
+ replaced with your own identifying information. (Don't include
183
+ the brackets!) The text should be enclosed in the appropriate
184
+ comment syntax for the file format. We also recommend that a
185
+ file or class name and description of purpose be included on the
186
+ same "printed page" as the copyright notice for easier
187
+ identification within third-party archives.
188
+
189
+ Copyright 2025 Cyril Kato
190
+
191
+ Licensed under the Apache License, Version 2.0 (the "License");
192
+ you may not use this file except in compliance with the License.
193
+ You may obtain a copy of the License at
194
+
195
+ http://www.apache.org/licenses/LICENSE-2.0
196
+
197
+ Unless required by applicable law or agreed to in writing, software
198
+ distributed under the License is distributed on an "AS IS" BASIS,
199
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200
+ See the License for the specific language governing permissions and
201
+ limitations under the License.
data/README.md CHANGED
@@ -1,17 +1,15 @@
1
- # Cgsn.rb
1
+ # cgsn.rb
2
2
 
3
3
  [![Version](https://img.shields.io/github/v/tag/sashite/cgsn.rb?label=Version&logo=github)](https://github.com/sashite/cgsn.rb/tags)
4
4
  [![Yard documentation](https://img.shields.io/badge/Yard-documentation-blue.svg?logo=github)](https://rubydoc.info/github/sashite/cgsn.rb/main)
5
- ![Ruby](https://github.com/sashite/cgsn.rb/actions/workflows/main.yml/badge.svg?branch=main)
6
- [![License](https://img.shields.io/github/license/sashite/cgsn.rb?label=License&logo=github)](https://github.com/sashite/cgsn.rb/raw/main/LICENSE.md)
5
+ [![CI](https://github.com/sashite/cgsn.rb/actions/workflows/ruby.yml/badge.svg?branch=main)](https://github.com/sashite/cgsn.rb/actions)
6
+ [![License](https://img.shields.io/github/license/sashite/cgsn.rb)](https://github.com/sashite/cgsn.rb/blob/main/LICENSE)
7
7
 
8
- > **CGSN** (Chess Game Status Notation) implementation for the Ruby language.
8
+ > **CGSN** (Chess Game Status Notation) implementation for Ruby.
9
9
 
10
- ## What is CGSN?
10
+ ## Overview
11
11
 
12
- CGSN (Chess Game Status Notation) provides a **rule-agnostic** taxonomy of observable game status values for abstract strategy board games. CGSN defines standardized identifiers for terminal conditions, player actions, and game progression states that can be recorded independently of competitive interpretation.
13
-
14
- This gem implements the [CGSN Specification v1.0.0](https://sashite.dev/specs/cgsn/1.0.0/), providing a minimal Ruby interface for status validation and categorization with immutable status objects.
12
+ This library implements the [CGSN Specification v1.0.0](https://sashite.dev/specs/cgsn/1.0.0/).
15
13
 
16
14
  ## Installation
17
15
 
@@ -26,150 +24,159 @@ Or install manually:
26
24
  gem install sashite-cgsn
27
25
  ```
28
26
 
29
- ## Format
30
-
31
- CGSN status values are lowercase strings using underscore separators:
32
-
33
- ```ruby
34
- "checkmate"
35
- "bareking"
36
- "timelimit"
37
- "stale"
38
- ```
39
-
40
- ## API Reference
27
+ ## Usage
41
28
 
42
- ### Status Class
29
+ ### Parsing (String → Symbol)
43
30
 
44
- #### Creation and Parsing
31
+ Convert a CGSN string into a symbol.
45
32
 
46
- * `Sashite::Cgsn::Status.new(value)` - Create status instance from string
47
- * `Sashite::Cgsn.parse(value)` - Parse status value (module convenience method)
33
+ ```ruby
34
+ require "sashite/cgsn"
48
35
 
49
- #### Instance Methods
36
+ # Standard parsing (raises on error)
37
+ Sashite::Cgsn.parse("checkmate") # => :checkmate
38
+ Sashite::Cgsn.parse("resignation") # => :resignation
50
39
 
51
- * `#inferable?` - Check if status can be inferred from position analysis
52
- * `#explicit_only?` - Check if status requires explicit declaration
53
- * `#to_s` - Convert to string representation
54
- * `#==(other)` - Equality comparison
55
- * `#hash` - Hash value for use in collections
40
+ # Invalid input raises ArgumentError
41
+ Sashite::Cgsn.parse("invalid") # => raises ArgumentError
42
+ Sashite::Cgsn.parse("") # => raises ArgumentError
43
+ ```
56
44
 
57
- ### Module Methods
45
+ ### Validation
58
46
 
59
- #### Validation
47
+ ```ruby
48
+ # Boolean check
49
+ Sashite::Cgsn.valid?("checkmate") # => true
50
+ Sashite::Cgsn.valid?("resignation") # => true
51
+ Sashite::Cgsn.valid?("invalid") # => false
52
+ Sashite::Cgsn.valid?("") # => false
53
+ Sashite::Cgsn.valid?(nil) # => false
54
+ ```
60
55
 
61
- * `Sashite::Cgsn.valid?(status)` - Check if string is a valid CGSN status value
56
+ ### Classification
62
57
 
63
- #### Categorization
58
+ ```ruby
59
+ # Position-inferable: can be determined from Position + Rule System
60
+ Sashite::Cgsn.inferable?(:checkmate) # => true
61
+ Sashite::Cgsn.inferable?(:stalemate) # => true
62
+ Sashite::Cgsn.inferable?(:repetition) # => false
63
+
64
+ # Explicit-only: requires external context (history, clocks, declarations)
65
+ Sashite::Cgsn.explicit_only?(:resignation) # => true
66
+ Sashite::Cgsn.explicit_only?(:timelimit) # => true
67
+ Sashite::Cgsn.explicit_only?(:checkmate) # => false
68
+ ```
64
69
 
65
- * `Sashite::Cgsn.inferable?(status)` - Check if status can be inferred from position analysis
66
- * `Sashite::Cgsn.explicit_only?(status)` - Check if status requires explicit declaration
70
+ ### Accessing Statuses
67
71
 
68
- #### Status Lists
72
+ ```ruby
73
+ # All statuses (unordered)
74
+ Sashite::Cgsn.statuses
75
+ # => #<Set: {:check, :stale, :checkmate, :stalemate, :nomove, :bareking,
76
+ # :mareking, :insufficient, :resignation, :illegalmove, :timelimit,
77
+ # :movelimit, :repetition, :agreement}>
78
+
79
+ # Position-inferable statuses
80
+ Sashite::Cgsn.inferable_statuses
81
+ # => #<Set: {:check, :stale, :checkmate, :stalemate, :nomove, :bareking,
82
+ # :mareking, :insufficient}>
83
+
84
+ # Explicit-only statuses
85
+ Sashite::Cgsn.explicit_only_statuses
86
+ # => #<Set: {:resignation, :illegalmove, :timelimit, :movelimit, :repetition,
87
+ # :agreement}>
88
+ ```
69
89
 
70
- * `Sashite::Cgsn.statuses` - Array of all defined CGSN status values
71
- * `Sashite::Cgsn.inferable_statuses` - Array of position-derivable statuses
72
- * `Sashite::Cgsn.explicit_only_statuses` - Array of statuses requiring explicit recording
90
+ ## API Reference
73
91
 
74
92
  ### Constants
75
93
 
76
- * `Sashite::Cgsn::STATUSES` - Frozen array of all defined status values
77
- * `Sashite::Cgsn::INFERABLE_STATUSES` - Frozen array of inferable status values
78
- * `Sashite::Cgsn::EXPLICIT_ONLY_STATUSES` - Frozen array of explicit-only status values
79
-
80
- ## Usage
81
-
82
- ### Object-Oriented Approach
83
-
84
94
  ```ruby
85
- require "sashite/cgsn"
86
-
87
- # Parse status into object
88
- status = Sashite::Cgsn.parse("checkmate")
89
- status.inferable? # => true
90
- status.explicit_only? # => false
91
- status.to_s # => "checkmate"
92
-
93
- # Create from string
94
- status = Sashite::Cgsn::Status.new("resignation")
95
- status.inferable? # => false
96
- status.explicit_only? # => true
97
-
98
- # Immutable objects
99
- status.frozen? # => true
95
+ Sashite::Cgsn::STATUSES # Set of all 14 status symbols
96
+ Sashite::Cgsn::INFERABLE_STATUSES # Set of 8 position-inferable symbols
97
+ Sashite::Cgsn::EXPLICIT_ONLY_STATUSES # Set of 6 explicit-only symbols
100
98
  ```
101
99
 
102
- ### Functional Approach
100
+ ### Parsing
103
101
 
104
102
  ```ruby
105
- require "sashite/cgsn"
106
-
107
- # Validate status strings
108
- Sashite::Cgsn.valid?("checkmate") # => true
109
- Sashite::Cgsn.valid?("invalid") # => false
110
-
111
- # Check inference capability
112
- Sashite::Cgsn.inferable?("stalemate") # => true
113
- Sashite::Cgsn.explicit_only?("timelimit") # => true
114
-
115
- # Get all statuses
116
- Sashite::Cgsn.statuses
117
- # => ["stale", "checkmate", "stalemate", ...]
103
+ # Parses a CGSN string into a symbol.
104
+ # Raises ArgumentError if the string is not valid.
105
+ #
106
+ # @param input [String] CGSN status string
107
+ # @return [Symbol]
108
+ # @raise [ArgumentError] if invalid
109
+ def Sashite::Cgsn.parse(input)
118
110
  ```
119
111
 
120
- ## Properties
112
+ ### Validation
121
113
 
122
- * **Rule-agnostic**: Independent of specific game mechanics or outcome interpretation
123
- * **Observable-focused**: Records verifiable facts without competitive judgment
124
- * **Inference-aware**: Distinguishes position-derivable from explicit-only statuses
125
- * **String-based**: Simple string representation for broad compatibility
126
- * **Functional**: Pure functions with no side effects
127
- * **Immutable**: All status instances and data structures are frozen
128
- * **Object-oriented**: Status objects with query methods
114
+ ```ruby
115
+ # Reports whether string is a valid CGSN status identifier.
116
+ #
117
+ # @param input [String] The value to check
118
+ # @return [Boolean]
119
+ def Sashite::Cgsn.valid?(input)
120
+ ```
129
121
 
130
- ## Related Specifications
122
+ ### Classification
131
123
 
132
- - [CGSN](https://sashite.dev/specs/cgsn/) - Chess Game Status Notation (this specification)
133
- - [PCN](https://sashite.dev/specs/pcn/) - Portable Chess Notation (uses CGSN for status field)
134
- - [Game Protocol](https://sashite.dev/protocol/) - Conceptual foundation for abstract strategy games
124
+ ```ruby
125
+ # Reports whether status is position-inferable.
126
+ #
127
+ # @param status [Symbol] The status to check
128
+ # @return [Boolean]
129
+ def Sashite::Cgsn.inferable?(status)
130
+
131
+ # Reports whether status is explicit-only.
132
+ #
133
+ # @param status [Symbol] The status to check
134
+ # @return [Boolean]
135
+ def Sashite::Cgsn.explicit_only?(status)
136
+ ```
135
137
 
136
- ## Documentation
138
+ ### Listing
137
139
 
138
- - [Official CGSN Specification v1.0.0](https://sashite.dev/specs/cgsn/1.0.0/)
139
- - [CGSN Examples](https://sashite.dev/specs/cgsn/1.0.0/examples/)
140
- - [API Documentation](https://rubydoc.info/github/sashite/cgsn.rb/main)
140
+ ```ruby
141
+ # Returns all CGSN v1.0.0 status symbols.
142
+ #
143
+ # @return [Set<Symbol>]
144
+ def Sashite::Cgsn.statuses
145
+
146
+ # Returns position-inferable status symbols.
147
+ #
148
+ # @return [Set<Symbol>]
149
+ def Sashite::Cgsn.inferable_statuses
150
+
151
+ # Returns explicit-only status symbols.
152
+ #
153
+ # @return [Set<Symbol>]
154
+ def Sashite::Cgsn.explicit_only_statuses
155
+ ```
141
156
 
142
- ## Development
157
+ ### Errors
143
158
 
144
- ```sh
145
- # Clone the repository
146
- git clone https://github.com/sashite/cgsn.rb.git
147
- cd cgsn.rb
159
+ All parsing errors raise `ArgumentError` with descriptive messages:
148
160
 
149
- # Install dependencies
150
- bundle install
161
+ | Message | Cause |
162
+ |---------|-------|
163
+ | `"invalid status"` | Input is not a valid CGSN status |
151
164
 
152
- # Run tests
153
- ruby test.rb
165
+ ## Design Principles
154
166
 
155
- # Generate documentation
156
- yard doc
157
- ```
167
+ - **Symbol-based**: Statuses represented as Ruby symbols for identity semantics
168
+ - **Set-based**: Unordered collections reflect vocabulary nature
169
+ - **Strict validation**: Only standard v1.0.0 vocabulary accepted
170
+ - **Rule-agnostic**: Records conditions without defining outcomes
171
+ - **Immutable constants**: All sets are frozen
172
+ - **No dependencies**: Pure Ruby standard library only
158
173
 
159
- ## Contributing
174
+ ## Related Specifications
160
175
 
161
- 1. Fork the repository
162
- 2. Create a feature branch (`git checkout -b feature/new-feature`)
163
- 3. Add tests for your changes
164
- 4. Ensure all tests pass (`ruby test.rb`)
165
- 5. Commit your changes (`git commit -am 'Add new feature'`)
166
- 6. Push to the branch (`git push origin feature/new-feature`)
167
- 7. Create a Pull Request
176
+ - [Game Protocol](https://sashite.dev/game-protocol/) Conceptual foundation
177
+ - [CGSN Specification](https://sashite.dev/specs/cgsn/1.0.0/) Official specification
178
+ - [CGSN Examples](https://sashite.dev/specs/cgsn/1.0.0/examples/) Usage examples
168
179
 
169
180
  ## License
170
181
 
171
- Available as open source under the [MIT License](https://opensource.org/licenses/MIT).
172
-
173
- ## About
174
-
175
- Maintained by [Sashité](https://sashite.com/) — promoting chess variants and sharing the beauty of board game cultures.
182
+ Available as open source under the [Apache License 2.0](https://opensource.org/licenses/Apache-2.0).
data/lib/sashite/cgsn.rb CHANGED
@@ -1,150 +1,168 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require_relative "cgsn/status"
3
+ require "set"
4
4
 
5
5
  module Sashite
6
- # CGSN (Chess Game Status Notation) implementation for Ruby
6
+ # CGSN (Chess Game Status Notation) implementation for Ruby.
7
7
  #
8
- # Provides functionality for working with rule-agnostic game status values
9
- # for abstract strategy board games.
8
+ # Provides a rule-agnostic vocabulary for identifying game statuses
9
+ # in abstract strategy board games with symbol-based identifiers.
10
10
  #
11
- # This implementation is strictly compliant with CGSN Specification v1.0.0
12
- # @see https://sashite.dev/specs/cgsn/1.0.0/ CGSN Specification v1.0.0
11
+ # @example Parsing
12
+ # Sashite::Cgsn.parse("checkmate") # => :checkmate
13
+ #
14
+ # @example Validation
15
+ # Sashite::Cgsn.valid?("checkmate") # => true
16
+ # Sashite::Cgsn.valid?("invalid") # => false
17
+ #
18
+ # @example Classification
19
+ # Sashite::Cgsn.inferable?(:checkmate) # => true
20
+ # Sashite::Cgsn.explicit_only?(:resignation) # => true
21
+ #
22
+ # @see https://sashite.dev/specs/cgsn/1.0.0/
13
23
  module Cgsn
14
- # Complete list of all defined CGSN status values
15
- STATUSES = %w[
16
- stale
17
- checkmate
18
- stalemate
19
- nomove
20
- bareking
21
- mareking
22
- insufficient
23
- resignation
24
- illegalmove
25
- timelimit
26
- movelimit
27
- repetition
28
- agreement
24
+ # Position-inferable status symbols.
25
+ #
26
+ # These can be determined from Position + Rule System alone.
27
+ #
28
+ # @return [Set<Symbol>] frozen set of inferable status symbols
29
+ INFERABLE_STATUSES = Set[
30
+ :check,
31
+ :stale,
32
+ :checkmate,
33
+ :stalemate,
34
+ :nomove,
35
+ :bareking,
36
+ :mareking,
37
+ :insufficient
29
38
  ].freeze
30
39
 
31
- # Statuses that can be inferred from position analysis
32
- INFERABLE_STATUSES = %w[
33
- stale
34
- checkmate
35
- stalemate
36
- nomove
37
- bareking
38
- mareking
39
- insufficient
40
+ # Explicit-only status symbols.
41
+ #
42
+ # These require external context (history, clocks, declarations).
43
+ #
44
+ # @return [Set<Symbol>] frozen set of explicit-only status symbols
45
+ EXPLICIT_ONLY_STATUSES = Set[
46
+ :resignation,
47
+ :illegalmove,
48
+ :timelimit,
49
+ :movelimit,
50
+ :repetition,
51
+ :agreement
40
52
  ].freeze
41
53
 
42
- # Statuses that require explicit declaration
43
- EXPLICIT_ONLY_STATUSES = %w[
44
- resignation
45
- illegalmove
46
- timelimit
47
- movelimit
48
- repetition
49
- agreement
50
- ].freeze
54
+ # All CGSN v1.0.0 status symbols.
55
+ #
56
+ # @return [Set<Symbol>] frozen set of all status symbols
57
+ STATUSES = (INFERABLE_STATUSES | EXPLICIT_ONLY_STATUSES).freeze
51
58
 
52
- # Check if a string is a valid CGSN status value
59
+ # Valid status strings for parsing (private implementation detail).
60
+ VALID_STRINGS = STATUSES.map(&:to_s).to_set.freeze
61
+ private_constant :VALID_STRINGS
62
+
63
+ # Parses a CGSN string into a symbol.
53
64
  #
54
- # @param value [String] the status to validate
55
- # @return [Boolean] true if the status is valid
65
+ # @param input [String] The CGSN status string to parse
66
+ # @return [Symbol] The corresponding status symbol
67
+ # @raise [ArgumentError] If the input is not a valid CGSN status
56
68
  #
57
69
  # @example
58
- # Sashite::Cgsn.valid?("checkmate") # => true
59
- # Sashite::Cgsn.valid?("nomove") # => true
60
- # Sashite::Cgsn.valid?("timelimit") # => true
61
- # Sashite::Cgsn.valid?("invalid") # => false
62
- # Sashite::Cgsn.valid?("Checkmate") # => false
63
- # Sashite::Cgsn.valid?(:checkmate) # => true (converts to "checkmate")
64
- def self.valid?(value)
65
- status_string = String(value)
66
- STATUSES.include?(status_string)
67
- rescue ::TypeError
68
- false
70
+ # Sashite::Cgsn.parse("checkmate") # => :checkmate
71
+ # Sashite::Cgsn.parse("resignation") # => :resignation
72
+ #
73
+ # @example Invalid input
74
+ # Sashite::Cgsn.parse("invalid") # => raises ArgumentError
75
+ # Sashite::Cgsn.parse("") # => raises ArgumentError
76
+ def self.parse(input)
77
+ raise ::ArgumentError, "invalid status" unless valid?(input)
78
+
79
+ :"#{input}"
69
80
  end
70
81
 
71
- # Parse a status value into a Status object
82
+ # Reports whether the input is a valid CGSN status string.
72
83
  #
73
- # @param value [String] the status value to parse
74
- # @return [Status] new status instance
75
- # @raise [ArgumentError] if the status value is invalid
84
+ # @param input [Object] The value to check
85
+ # @return [Boolean] true if valid, false otherwise
76
86
  #
77
87
  # @example
78
- # Sashite::Cgsn.parse("checkmate") # => #<Cgsn::Status value="checkmate">
79
- # Sashite::Cgsn.parse("nomove") # => #<Cgsn::Status value="nomove">
80
- # Sashite::Cgsn.parse("resignation") # => #<Cgsn::Status value="resignation">
81
- def self.parse(value)
82
- Status.new(value)
88
+ # Sashite::Cgsn.valid?("checkmate") # => true
89
+ # Sashite::Cgsn.valid?("resignation") # => true
90
+ # Sashite::Cgsn.valid?("invalid") # => false
91
+ # Sashite::Cgsn.valid?("") # => false
92
+ # Sashite::Cgsn.valid?(nil) # => false
93
+ def self.valid?(input)
94
+ return false unless ::String === input
95
+
96
+ VALID_STRINGS.include?(input)
83
97
  end
84
98
 
85
- # Check if a status can be inferred from position analysis
99
+ # Reports whether the status is position-inferable.
86
100
  #
87
- # @param status [String, Status] the status to check
88
- # @return [Boolean] true if the status is inferable
101
+ # Position-inferable statuses can be determined from Position + Rule System
102
+ # without external context (history, clocks, declarations).
103
+ #
104
+ # @param status [Symbol] The status to check
105
+ # @return [Boolean] true if position-inferable, false otherwise
89
106
  #
90
107
  # @example
91
- # Sashite::Cgsn.inferable?("checkmate") # => true
92
- # Sashite::Cgsn.inferable?("nomove") # => true
93
- # Sashite::Cgsn.inferable?("resignation") # => false
108
+ # Sashite::Cgsn.inferable?(:checkmate) # => true
109
+ # Sashite::Cgsn.inferable?(:stalemate) # => true
110
+ # Sashite::Cgsn.inferable?(:repetition) # => false
94
111
  def self.inferable?(status)
95
- status_string = String(status)
96
- INFERABLE_STATUSES.include?(status_string)
97
- rescue ::TypeError
98
- false
112
+ return false unless ::Symbol === status
113
+
114
+ INFERABLE_STATUSES.include?(status)
99
115
  end
100
116
 
101
- # Check if a status requires explicit declaration
117
+ # Reports whether the status is explicit-only.
102
118
  #
103
- # @param status [String, Status] the status to check
104
- # @return [Boolean] true if the status is explicit-only
119
+ # Explicit-only statuses require external context (history, clocks,
120
+ # declarations) and cannot be derived from Position + Rule System alone.
121
+ #
122
+ # @param status [Symbol] The status to check
123
+ # @return [Boolean] true if explicit-only, false otherwise
105
124
  #
106
125
  # @example
107
- # Sashite::Cgsn.explicit_only?("resignation") # => true
108
- # Sashite::Cgsn.explicit_only?("checkmate") # => false
109
- # Sashite::Cgsn.explicit_only?("nomove") # => false
126
+ # Sashite::Cgsn.explicit_only?(:resignation) # => true
127
+ # Sashite::Cgsn.explicit_only?(:timelimit) # => true
128
+ # Sashite::Cgsn.explicit_only?(:checkmate) # => false
110
129
  def self.explicit_only?(status)
111
- status_string = String(status)
112
- EXPLICIT_ONLY_STATUSES.include?(status_string)
113
- rescue ::TypeError
114
- false
130
+ return false unless ::Symbol === status
131
+
132
+ EXPLICIT_ONLY_STATUSES.include?(status)
115
133
  end
116
134
 
117
- # Get the list of all defined CGSN status values
135
+ # Returns all CGSN v1.0.0 status symbols.
118
136
  #
119
- # @return [Array<String>] array of all status values
137
+ # @return [Set<Symbol>] frozen set of all status symbols
120
138
  #
121
139
  # @example
122
140
  # Sashite::Cgsn.statuses
123
- # # => ["stale", "checkmate", "stalemate", "nomove", ...]
141
+ # # => #<Set: {:check, :stale, :checkmate, ...}>
124
142
  def self.statuses
125
- STATUSES.dup
143
+ STATUSES
126
144
  end
127
145
 
128
- # Get the list of inferable status values
146
+ # Returns position-inferable status symbols.
129
147
  #
130
- # @return [Array<String>] array of inferable status values
148
+ # @return [Set<Symbol>] frozen set of inferable status symbols
131
149
  #
132
150
  # @example
133
151
  # Sashite::Cgsn.inferable_statuses
134
- # # => ["stale", "checkmate", "stalemate", "nomove", ...]
152
+ # # => #<Set: {:check, :stale, :checkmate, :stalemate, ...}>
135
153
  def self.inferable_statuses
136
- INFERABLE_STATUSES.dup
154
+ INFERABLE_STATUSES
137
155
  end
138
156
 
139
- # Get the list of explicit-only status values
157
+ # Returns explicit-only status symbols.
140
158
  #
141
- # @return [Array<String>] array of explicit-only status values
159
+ # @return [Set<Symbol>] frozen set of explicit-only status symbols
142
160
  #
143
161
  # @example
144
162
  # Sashite::Cgsn.explicit_only_statuses
145
- # # => ["resignation", "illegalmove", "timelimit", ...]
163
+ # # => #<Set: {:resignation, :illegalmove, :timelimit, ...}>
146
164
  def self.explicit_only_statuses
147
- EXPLICIT_ONLY_STATUSES.dup
165
+ EXPLICIT_ONLY_STATUSES
148
166
  end
149
167
  end
150
168
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sashite-cgsn
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.1
4
+ version: 1.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Cyril Kato
@@ -9,28 +9,21 @@ bindir: bin
9
9
  cert_chain: []
10
10
  date: 1980-01-02 00:00:00.000000000 Z
11
11
  dependencies: []
12
- description: |
13
- CGSN (Chess Game Status Notation) provides a rule-agnostic taxonomy of observable game status
14
- values for abstract strategy board games. This gem implements the CGSN Specification v1.0.0 with
15
- a minimal Ruby interface featuring immutable status objects and functional programming principles.
16
- CGSN defines standardized identifiers for terminal conditions (checkmate, stalemate, bareking,
17
- mareking, insufficient), player actions (resignation, agreement, illegalmove), and temporal
18
- constraints (timelimit, movelimit, repetition), enabling precise and portable status identification
19
- across multiple games and variants. Perfect for game engines, notation systems, and hybrid gaming
20
- platforms requiring consistent, rule-agnostic game state representation.
12
+ description: CGSN (Chess Game Status Notation) implementation for Ruby. Provides a
13
+ rule-agnostic vocabulary for identifying game statuses in abstract strategy board
14
+ games with symbol-based identifiers and immutable sets.
21
15
  email: contact@cyril.email
22
16
  executables: []
23
17
  extensions: []
24
18
  extra_rdoc_files: []
25
19
  files:
26
- - LICENSE.md
20
+ - LICENSE
27
21
  - README.md
28
22
  - lib/sashite-cgsn.rb
29
23
  - lib/sashite/cgsn.rb
30
- - lib/sashite/cgsn/status.rb
31
24
  homepage: https://github.com/sashite/cgsn.rb
32
25
  licenses:
33
- - MIT
26
+ - Apache-2.0
34
27
  metadata:
35
28
  bug_tracker_uri: https://github.com/sashite/cgsn.rb/issues
36
29
  documentation_uri: https://rubydoc.info/github/sashite/cgsn.rb/main
@@ -38,6 +31,7 @@ metadata:
38
31
  source_code_uri: https://github.com/sashite/cgsn.rb
39
32
  specification_uri: https://sashite.dev/specs/cgsn/1.0.0/
40
33
  wiki_uri: https://sashite.dev/specs/cgsn/1.0.0/examples/
34
+ funding_uri: https://github.com/sponsors/sashite
41
35
  rubygems_mfa_required: 'true'
42
36
  rdoc_options: []
43
37
  require_paths:
@@ -53,8 +47,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
53
47
  - !ruby/object:Gem::Version
54
48
  version: '0'
55
49
  requirements: []
56
- rubygems_version: 3.7.2
50
+ rubygems_version: 4.0.3
57
51
  specification_version: 4
58
- summary: CGSN (Chess Game Status Notation) implementation for Ruby with immutable
59
- status objects
52
+ summary: CGSN (Chess Game Status Notation) implementation for Ruby with symbol-based
53
+ status vocabulary
60
54
  test_files: []
data/LICENSE.md DELETED
@@ -1,22 +0,0 @@
1
- Copyright (c) 2025 Cyril Kato
2
-
3
- MIT License
4
-
5
- Permission is hereby granted, free of charge, to any person obtaining
6
- a copy of this software and associated documentation files (the
7
- "Software"), to deal in the Software without restriction, including
8
- without limitation the rights to use, copy, modify, merge, publish,
9
- distribute, sublicense, and/or sell copies of the Software, and to
10
- permit persons to whom the Software is furnished to do so, subject to
11
- the following conditions:
12
-
13
- The above copyright notice and this permission notice shall be
14
- included in all copies or substantial portions of the Software.
15
-
16
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
- EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
- MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
- NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
- LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
- OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
- WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -1,85 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Sashite
4
- module Cgsn
5
- # Represents a status value in CGSN (Chess Game Status Notation) format.
6
- #
7
- # A status consists of a lowercase string with optional underscore separators.
8
- # Each status represents an observable game state that can be recorded
9
- # independently of competitive interpretation.
10
- #
11
- # All instances are immutable.
12
- class Status
13
- # Error message for invalid status values
14
- ERROR_INVALID_STATUS = "Invalid CGSN status: %s"
15
-
16
- # Create a new status instance
17
- #
18
- # @param value [String] status value
19
- # @raise [ArgumentError] if the value is invalid
20
- #
21
- # @example
22
- # Status.new("checkmate") # => #<Cgsn::Status value="checkmate">
23
- # Status.new("resignation") # => #<Cgsn::Status value="resignation">
24
- def initialize(value)
25
- @value = String(value)
26
-
27
- raise ::ArgumentError, format(ERROR_INVALID_STATUS, @value) unless Cgsn::STATUSES.include?(@value)
28
-
29
- freeze
30
- end
31
-
32
- # Check if the status can be inferred from position analysis
33
- #
34
- # @return [Boolean] true if inferable
35
- #
36
- # @example
37
- # Status.new("checkmate").inferable? # => true
38
- # Status.new("resignation").inferable? # => false
39
- def inferable?
40
- Cgsn::INFERABLE_STATUSES.include?(@value)
41
- end
42
-
43
- # Check if the status requires explicit declaration
44
- #
45
- # @return [Boolean] true if explicit-only
46
- #
47
- # @example
48
- # Status.new("resignation").explicit_only? # => true
49
- # Status.new("checkmate").explicit_only? # => false
50
- def explicit_only?
51
- Cgsn::EXPLICIT_ONLY_STATUSES.include?(@value)
52
- end
53
-
54
- # Convert the status to its string representation
55
- #
56
- # @return [String] status value
57
- #
58
- # @example
59
- # Status.new("checkmate").to_s # => "checkmate"
60
- def to_s
61
- @value
62
- end
63
-
64
- # Custom equality comparison
65
- #
66
- # @param other [Object] object to compare with
67
- # @return [Boolean] true if statuses are equal
68
- def ==(other)
69
- return false unless other.is_a?(self.class)
70
-
71
- to_s == other.to_s
72
- end
73
-
74
- # Alias for == to ensure Set functionality works correctly
75
- alias eql? ==
76
-
77
- # Custom hash implementation for use in collections
78
- #
79
- # @return [Integer] hash value
80
- def hash
81
- [self.class, @value].hash
82
- end
83
- end
84
- end
85
- end