sashite-cgsn 0.3.0 → 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 +4 -4
- data/LICENSE +201 -0
- data/README.md +132 -78
- data/lib/sashite/cgsn.rb +114 -126
- metadata +10 -15
- data/LICENSE.md +0 -22
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 4a4b0e4315400be9e2678b80d4ab0cc80376084f7884a6b2b83f90807a948fad
|
|
4
|
+
data.tar.gz: 3cd371946d9525c43335fc552383b349a96e18b6532f5e58997a7af9f61e84fa
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
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,27 +1,20 @@
|
|
|
1
|
-
#
|
|
1
|
+
# cgsn.rb
|
|
2
2
|
|
|
3
3
|
[](https://github.com/sashite/cgsn.rb/tags)
|
|
4
4
|
[](https://rubydoc.info/github/sashite/cgsn.rb/main)
|
|
5
|
-
](https://github.com/sashite/cgsn.rb/actions)
|
|
6
|
+
[](https://github.com/sashite/cgsn.rb/blob/main/LICENSE)
|
|
7
7
|
|
|
8
|
-
> **CGSN** (Chess Game Status Notation)
|
|
8
|
+
> **CGSN** (Chess Game Status Notation) implementation for Ruby.
|
|
9
9
|
|
|
10
|
-
##
|
|
10
|
+
## Overview
|
|
11
11
|
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
CGSN focuses on *what can be observed or verified*, not on *how a status impacts the result* (win/loss/draw), which remains Rule System– or competition-defined.
|
|
15
|
-
|
|
16
|
-
This library implements the **CGSN Specification v1.0.0**:
|
|
17
|
-
- https://sashite.dev/specs/cgsn/1.0.0/
|
|
18
|
-
- Examples: https://sashite.dev/specs/cgsn/1.0.0/examples/
|
|
12
|
+
This library implements the [CGSN Specification v1.0.0](https://sashite.dev/specs/cgsn/1.0.0/).
|
|
19
13
|
|
|
20
14
|
## Installation
|
|
21
15
|
|
|
22
|
-
Add to your Gemfile:
|
|
23
|
-
|
|
24
16
|
```ruby
|
|
17
|
+
# In your Gemfile
|
|
25
18
|
gem "sashite-cgsn"
|
|
26
19
|
```
|
|
27
20
|
|
|
@@ -31,98 +24,159 @@ Or install manually:
|
|
|
31
24
|
gem install sashite-cgsn
|
|
32
25
|
```
|
|
33
26
|
|
|
34
|
-
##
|
|
27
|
+
## Usage
|
|
35
28
|
|
|
36
|
-
|
|
29
|
+
### Parsing (String → Symbol)
|
|
37
30
|
|
|
38
|
-
CGSN
|
|
31
|
+
Convert a CGSN string into a symbol.
|
|
39
32
|
|
|
40
|
-
|
|
33
|
+
```ruby
|
|
34
|
+
require "sashite/cgsn"
|
|
35
|
+
|
|
36
|
+
# Standard parsing (raises on error)
|
|
37
|
+
Sashite::Cgsn.parse("checkmate") # => :checkmate
|
|
38
|
+
Sashite::Cgsn.parse("resignation") # => :resignation
|
|
41
39
|
|
|
42
|
-
|
|
43
|
-
|
|
40
|
+
# Invalid input raises ArgumentError
|
|
41
|
+
Sashite::Cgsn.parse("invalid") # => raises ArgumentError
|
|
42
|
+
Sashite::Cgsn.parse("") # => raises ArgumentError
|
|
43
|
+
```
|
|
44
44
|
|
|
45
|
-
|
|
46
|
-
| ----------- | ------------------------------------------------------------------------------------------------------------------- |
|
|
47
|
-
| `check` | A specific Terminal Piece of the active player's side can be captured by an opponent's Pseudo-Legal Move |
|
|
48
|
-
| `stale` | A specific Terminal Piece of the active player's side cannot be captured by any opponent's Pseudo-Legal Move |
|
|
49
|
-
| `checkmate` | That same Terminal Piece is in `check`, and every Pseudo-Legal Move by the active player still leaves it in `check` |
|
|
50
|
-
| `stalemate` | That same Terminal Piece is `stale`, but every Pseudo-Legal Move by the active player would put it in `check` |
|
|
45
|
+
### Validation
|
|
51
46
|
|
|
52
|
-
|
|
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
|
+
```
|
|
53
55
|
|
|
54
|
-
###
|
|
56
|
+
### Classification
|
|
55
57
|
|
|
56
|
-
|
|
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
|
+
```
|
|
57
69
|
|
|
58
|
-
|
|
59
|
-
| -------------- | ----------------------------------------------------------------------------------------------------------------------- |
|
|
60
|
-
| `nomove` | No Pseudo-Legal Moves exist for the active player |
|
|
61
|
-
| `bareking` | At least one side has **exactly one piece on the Board**, and that piece is a Terminal Piece (Hands are not considered) |
|
|
62
|
-
| `mareking` | At least one side has **no Terminal Pieces on the Board** |
|
|
63
|
-
| `insufficient` | Under the Rule System's insufficiency rules, neither side can force a decisive outcome with the available material |
|
|
70
|
+
### Accessing Statuses
|
|
64
71
|
|
|
65
|
-
|
|
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}>
|
|
66
78
|
|
|
67
|
-
|
|
79
|
+
# Position-inferable statuses
|
|
80
|
+
Sashite::Cgsn.inferable_statuses
|
|
81
|
+
# => #<Set: {:check, :stale, :checkmate, :stalemate, :nomove, :bareking,
|
|
82
|
+
# :mareking, :insufficient}>
|
|
68
83
|
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
| `movelimit` | The match reached a move-count limit defined by rules or competition regulations |
|
|
75
|
-
| `repetition` | A position repeated according to the Rule System's repetition policy |
|
|
76
|
-
| `agreement` | Both players mutually agreed to end the match |
|
|
84
|
+
# Explicit-only statuses
|
|
85
|
+
Sashite::Cgsn.explicit_only_statuses
|
|
86
|
+
# => #<Set: {:resignation, :illegalmove, :timelimit, :movelimit, :repetition,
|
|
87
|
+
# :agreement}>
|
|
88
|
+
```
|
|
77
89
|
|
|
78
|
-
##
|
|
90
|
+
## API Reference
|
|
91
|
+
|
|
92
|
+
### Constants
|
|
79
93
|
|
|
80
94
|
```ruby
|
|
81
|
-
|
|
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
|
|
98
|
+
```
|
|
82
99
|
|
|
83
|
-
|
|
84
|
-
Sashite::Cgsn.valid?("checkmate") # => true
|
|
85
|
-
Sashite::Cgsn.valid?("resignation") # => true
|
|
86
|
-
Sashite::Cgsn.valid?("invalid") # => false
|
|
87
|
-
Sashite::Cgsn.valid?("") # => false
|
|
100
|
+
### Parsing
|
|
88
101
|
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
102
|
+
```ruby
|
|
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)
|
|
110
|
+
```
|
|
92
111
|
|
|
93
|
-
|
|
94
|
-
Sashite::Cgsn.explicit_only?("stalemate") # => false
|
|
112
|
+
### Validation
|
|
95
113
|
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
#
|
|
99
|
-
#
|
|
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
|
+
```
|
|
100
121
|
|
|
101
|
-
|
|
102
|
-
# => ["check", "stale", "checkmate", "stalemate", "nomove", "bareking", "mareking", "insufficient"]
|
|
122
|
+
### Classification
|
|
103
123
|
|
|
104
|
-
|
|
105
|
-
#
|
|
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
|
+
```
|
|
137
|
+
|
|
138
|
+
### Listing
|
|
139
|
+
|
|
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
|
|
106
155
|
```
|
|
107
156
|
|
|
108
|
-
|
|
157
|
+
### Errors
|
|
109
158
|
|
|
110
|
-
|
|
159
|
+
All parsing errors raise `ArgumentError` with descriptive messages:
|
|
111
160
|
|
|
112
|
-
|
|
161
|
+
| Message | Cause |
|
|
162
|
+
|---------|-------|
|
|
163
|
+
| `"invalid status"` | Input is not a valid CGSN status |
|
|
113
164
|
|
|
114
|
-
##
|
|
165
|
+
## Design Principles
|
|
115
166
|
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
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
|
|
121
173
|
|
|
122
|
-
##
|
|
174
|
+
## Related Specifications
|
|
123
175
|
|
|
124
|
-
|
|
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
|
|
125
179
|
|
|
126
|
-
##
|
|
180
|
+
## License
|
|
127
181
|
|
|
128
|
-
|
|
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,180 +1,168 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
+
require "set"
|
|
4
|
+
|
|
3
5
|
module Sashite
|
|
4
|
-
# CGSN (Chess Game Status Notation)
|
|
5
|
-
#
|
|
6
|
-
# This module exposes the CGSN v1.0.0 standard status identifiers (as strings)
|
|
7
|
-
# and helpers to validate / classify them.
|
|
8
|
-
#
|
|
9
|
-
# CGSN statuses are categorized as either:
|
|
10
|
-
#
|
|
11
|
-
# - *position-inferable*: can be determined from Position + Rule System,
|
|
12
|
-
# - *explicit-only*: require extra context (history, clocks, declarations, etc.).
|
|
13
|
-
#
|
|
14
|
-
# This implementation is intentionally *rule-agnostic* and *does not compute*
|
|
15
|
-
# game statuses. It only provides a stable vocabulary and membership checks.
|
|
16
|
-
#
|
|
17
|
-
# Specification:
|
|
18
|
-
# https://sashite.dev/specs/cgsn/1.0.0/
|
|
6
|
+
# CGSN (Chess Game Status Notation) implementation for Ruby.
|
|
19
7
|
#
|
|
20
|
-
#
|
|
21
|
-
#
|
|
8
|
+
# Provides a rule-agnostic vocabulary for identifying game statuses
|
|
9
|
+
# in abstract strategy board games with symbol-based identifiers.
|
|
22
10
|
#
|
|
23
|
-
# @
|
|
11
|
+
# @example Parsing
|
|
12
|
+
# Sashite::Cgsn.parse("checkmate") # => :checkmate
|
|
24
13
|
#
|
|
25
14
|
# @example Validation
|
|
26
15
|
# Sashite::Cgsn.valid?("checkmate") # => true
|
|
27
16
|
# Sashite::Cgsn.valid?("invalid") # => false
|
|
28
17
|
#
|
|
29
18
|
# @example Classification
|
|
30
|
-
# Sashite::Cgsn.inferable?(
|
|
31
|
-
# Sashite::Cgsn.explicit_only?(
|
|
19
|
+
# Sashite::Cgsn.inferable?(:checkmate) # => true
|
|
20
|
+
# Sashite::Cgsn.explicit_only?(:resignation) # => true
|
|
32
21
|
#
|
|
33
|
-
# @see https://sashite.dev/specs/cgsn/1.0.0/
|
|
34
|
-
# @see https://sashite.dev/game-protocol/ Game Protocol
|
|
35
|
-
# @see https://sashite.dev/glossary/ Glossary
|
|
22
|
+
# @see https://sashite.dev/specs/cgsn/1.0.0/
|
|
36
23
|
module Cgsn
|
|
37
|
-
# Position-inferable status
|
|
38
|
-
#
|
|
39
|
-
#
|
|
40
|
-
#
|
|
41
|
-
#
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
insufficient
|
|
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
|
|
52
38
|
].freeze
|
|
53
39
|
|
|
54
|
-
# Explicit-only status
|
|
55
|
-
#
|
|
56
|
-
#
|
|
57
|
-
#
|
|
58
|
-
#
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
agreement
|
|
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
|
|
67
52
|
].freeze
|
|
68
53
|
|
|
69
|
-
# All CGSN v1.0.0 status
|
|
54
|
+
# All CGSN v1.0.0 status symbols.
|
|
70
55
|
#
|
|
71
|
-
# @return [
|
|
72
|
-
STATUSES = (INFERABLE_STATUSES
|
|
73
|
-
|
|
74
|
-
# Fast membership lookup sets (private implementation detail).
|
|
75
|
-
INFERABLE_SET = INFERABLE_STATUSES.to_set.freeze
|
|
76
|
-
EXPLICIT_ONLY_SET = EXPLICIT_ONLY_STATUSES.to_set.freeze
|
|
77
|
-
STATUS_SET = STATUSES.to_set.freeze
|
|
56
|
+
# @return [Set<Symbol>] frozen set of all status symbols
|
|
57
|
+
STATUSES = (INFERABLE_STATUSES | EXPLICIT_ONLY_STATUSES).freeze
|
|
78
58
|
|
|
79
|
-
|
|
59
|
+
# Valid status strings for parsing (private implementation detail).
|
|
60
|
+
VALID_STRINGS = STATUSES.map(&:to_s).to_set.freeze
|
|
61
|
+
private_constant :VALID_STRINGS
|
|
80
62
|
|
|
81
|
-
#
|
|
63
|
+
# Parses a CGSN string into a symbol.
|
|
82
64
|
#
|
|
83
|
-
# The
|
|
84
|
-
#
|
|
85
|
-
# @
|
|
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
|
|
86
68
|
#
|
|
87
69
|
# @example
|
|
88
|
-
# Sashite::Cgsn.
|
|
89
|
-
# # =>
|
|
90
|
-
#
|
|
91
|
-
|
|
92
|
-
|
|
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}"
|
|
93
80
|
end
|
|
94
81
|
|
|
95
|
-
#
|
|
82
|
+
# Reports whether the input is a valid CGSN status string.
|
|
96
83
|
#
|
|
97
|
-
#
|
|
98
|
-
#
|
|
99
|
-
#
|
|
100
|
-
# @return [Array<String>] inferable status identifiers
|
|
84
|
+
# @param input [Object] The value to check
|
|
85
|
+
# @return [Boolean] true if valid, false otherwise
|
|
101
86
|
#
|
|
102
87
|
# @example
|
|
103
|
-
# Sashite::Cgsn.
|
|
104
|
-
# # =>
|
|
105
|
-
|
|
106
|
-
|
|
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)
|
|
107
97
|
end
|
|
108
98
|
|
|
109
|
-
#
|
|
99
|
+
# Reports whether the status is position-inferable.
|
|
110
100
|
#
|
|
111
|
-
#
|
|
112
|
-
#
|
|
101
|
+
# Position-inferable statuses can be determined from Position + Rule System
|
|
102
|
+
# without external context (history, clocks, declarations).
|
|
113
103
|
#
|
|
114
|
-
# @
|
|
104
|
+
# @param status [Symbol] The status to check
|
|
105
|
+
# @return [Boolean] true if position-inferable, false otherwise
|
|
115
106
|
#
|
|
116
107
|
# @example
|
|
117
|
-
# Sashite::Cgsn.
|
|
118
|
-
# # =>
|
|
119
|
-
|
|
120
|
-
|
|
108
|
+
# Sashite::Cgsn.inferable?(:checkmate) # => true
|
|
109
|
+
# Sashite::Cgsn.inferable?(:stalemate) # => true
|
|
110
|
+
# Sashite::Cgsn.inferable?(:repetition) # => false
|
|
111
|
+
def self.inferable?(status)
|
|
112
|
+
return false unless ::Symbol === status
|
|
113
|
+
|
|
114
|
+
INFERABLE_STATUSES.include?(status)
|
|
121
115
|
end
|
|
122
116
|
|
|
123
|
-
#
|
|
117
|
+
# Reports whether the status is explicit-only.
|
|
124
118
|
#
|
|
125
|
-
#
|
|
126
|
-
#
|
|
119
|
+
# Explicit-only statuses require external context (history, clocks,
|
|
120
|
+
# declarations) and cannot be derived from Position + Rule System alone.
|
|
127
121
|
#
|
|
128
|
-
# @param status [
|
|
129
|
-
# @return [Boolean] true if
|
|
122
|
+
# @param status [Symbol] The status to check
|
|
123
|
+
# @return [Boolean] true if explicit-only, false otherwise
|
|
130
124
|
#
|
|
131
125
|
# @example
|
|
132
|
-
# Sashite::Cgsn.
|
|
133
|
-
# Sashite::Cgsn.
|
|
134
|
-
# Sashite::Cgsn.
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
return false unless status.is_a?(::String)
|
|
140
|
-
|
|
141
|
-
STATUS_SET.include?(status)
|
|
126
|
+
# Sashite::Cgsn.explicit_only?(:resignation) # => true
|
|
127
|
+
# Sashite::Cgsn.explicit_only?(:timelimit) # => true
|
|
128
|
+
# Sashite::Cgsn.explicit_only?(:checkmate) # => false
|
|
129
|
+
def self.explicit_only?(status)
|
|
130
|
+
return false unless ::Symbol === status
|
|
131
|
+
|
|
132
|
+
EXPLICIT_ONLY_STATUSES.include?(status)
|
|
142
133
|
end
|
|
143
134
|
|
|
144
|
-
#
|
|
145
|
-
#
|
|
146
|
-
# @param status [Object] the value to check
|
|
147
|
-
# @return [Boolean] true if the status is position-inferable, false otherwise
|
|
135
|
+
# Returns all CGSN v1.0.0 status symbols.
|
|
148
136
|
#
|
|
149
|
-
# @
|
|
137
|
+
# @return [Set<Symbol>] frozen set of all status symbols
|
|
150
138
|
#
|
|
151
139
|
# @example
|
|
152
|
-
# Sashite::Cgsn.
|
|
153
|
-
#
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
def self.inferable?(status)
|
|
157
|
-
return false unless status.is_a?(::String)
|
|
158
|
-
|
|
159
|
-
INFERABLE_SET.include?(status)
|
|
140
|
+
# Sashite::Cgsn.statuses
|
|
141
|
+
# # => #<Set: {:check, :stale, :checkmate, ...}>
|
|
142
|
+
def self.statuses
|
|
143
|
+
STATUSES
|
|
160
144
|
end
|
|
161
145
|
|
|
162
|
-
#
|
|
163
|
-
#
|
|
164
|
-
# @param status [Object] the value to check
|
|
165
|
-
# @return [Boolean] true if the status is explicit-only, false otherwise
|
|
146
|
+
# Returns position-inferable status symbols.
|
|
166
147
|
#
|
|
167
|
-
# @
|
|
148
|
+
# @return [Set<Symbol>] frozen set of inferable status symbols
|
|
168
149
|
#
|
|
169
150
|
# @example
|
|
170
|
-
# Sashite::Cgsn.
|
|
171
|
-
#
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
return false unless status.is_a?(::String)
|
|
151
|
+
# Sashite::Cgsn.inferable_statuses
|
|
152
|
+
# # => #<Set: {:check, :stale, :checkmate, :stalemate, ...}>
|
|
153
|
+
def self.inferable_statuses
|
|
154
|
+
INFERABLE_STATUSES
|
|
155
|
+
end
|
|
176
156
|
|
|
177
|
-
|
|
157
|
+
# Returns explicit-only status symbols.
|
|
158
|
+
#
|
|
159
|
+
# @return [Set<Symbol>] frozen set of explicit-only status symbols
|
|
160
|
+
#
|
|
161
|
+
# @example
|
|
162
|
+
# Sashite::Cgsn.explicit_only_statuses
|
|
163
|
+
# # => #<Set: {:resignation, :illegalmove, :timelimit, ...}>
|
|
164
|
+
def self.explicit_only_statuses
|
|
165
|
+
EXPLICIT_ONLY_STATUSES
|
|
178
166
|
end
|
|
179
167
|
end
|
|
180
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.
|
|
4
|
+
version: 1.0.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Cyril Kato
|
|
@@ -9,27 +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
|
-
|
|
14
|
-
|
|
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
|
|
20
|
+
- LICENSE
|
|
27
21
|
- README.md
|
|
28
22
|
- lib/sashite-cgsn.rb
|
|
29
23
|
- lib/sashite/cgsn.rb
|
|
30
24
|
homepage: https://github.com/sashite/cgsn.rb
|
|
31
25
|
licenses:
|
|
32
|
-
-
|
|
26
|
+
- Apache-2.0
|
|
33
27
|
metadata:
|
|
34
28
|
bug_tracker_uri: https://github.com/sashite/cgsn.rb/issues
|
|
35
29
|
documentation_uri: https://rubydoc.info/github/sashite/cgsn.rb/main
|
|
@@ -37,6 +31,7 @@ metadata:
|
|
|
37
31
|
source_code_uri: https://github.com/sashite/cgsn.rb
|
|
38
32
|
specification_uri: https://sashite.dev/specs/cgsn/1.0.0/
|
|
39
33
|
wiki_uri: https://sashite.dev/specs/cgsn/1.0.0/examples/
|
|
34
|
+
funding_uri: https://github.com/sponsors/sashite
|
|
40
35
|
rubygems_mfa_required: 'true'
|
|
41
36
|
rdoc_options: []
|
|
42
37
|
require_paths:
|
|
@@ -52,8 +47,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
52
47
|
- !ruby/object:Gem::Version
|
|
53
48
|
version: '0'
|
|
54
49
|
requirements: []
|
|
55
|
-
rubygems_version:
|
|
50
|
+
rubygems_version: 4.0.3
|
|
56
51
|
specification_version: 4
|
|
57
|
-
summary: CGSN (Chess Game Status Notation) implementation for Ruby with
|
|
58
|
-
status
|
|
52
|
+
summary: CGSN (Chess Game Status Notation) implementation for Ruby with symbol-based
|
|
53
|
+
status vocabulary
|
|
59
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.
|