sashite-sin 2.1.0 → 3.1.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 +115 -274
- data/lib/sashite/sin/constants.rb +38 -0
- data/lib/sashite/sin/errors/argument/messages.rb +45 -0
- data/lib/sashite/sin/errors/argument.rb +21 -0
- data/lib/sashite/sin/errors.rb +19 -0
- data/lib/sashite/sin/identifier.rb +113 -330
- data/lib/sashite/sin/parser.rb +137 -0
- data/lib/sashite/sin.rb +48 -166
- data/lib/sashite-sin.rb +0 -11
- metadata +14 -12
- 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: '080b65573c2e27e8efe5c2ed79009daf31124b35c88ddc7bbe4023e6fe553acf'
|
|
4
|
+
data.tar.gz: fc25ce0ac44111a41d764aa8badac8ca2727a163e00accd5d8bf52ca301198d0
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 93caf9df6d423fa40562f43971b8ea1c1a0c1bba1d4de9d11ee59184d2906638e2d4aa25639ed40010090dfa2929a658e9ba52f714bb46d1616639b6f2983685
|
|
7
|
+
data.tar.gz: 3d8c978b778d1210e71c288a41daf9f80a750a5a1f975c22a1536f8499f280a7302f0a51c6641d72522b3cc18b88bca5bb94ab7fdac5f8c7de1920b5444fc700
|
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-2026 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
|
-
#
|
|
1
|
+
# sin.rb
|
|
2
2
|
|
|
3
3
|
[](https://github.com/sashite/sin.rb/tags)
|
|
4
4
|
[](https://rubydoc.info/github/sashite/sin.rb/main)
|
|
5
|
-
](https://github.com/sashite/sin.rb/raw/main/LICENSE
|
|
5
|
+
[](https://github.com/sashite/sin.rb/actions)
|
|
6
|
+
[](https://github.com/sashite/sin.rb/raw/main/LICENSE)
|
|
7
7
|
|
|
8
|
-
> **SIN** (Style Identifier Notation) implementation for
|
|
8
|
+
> **SIN** (Style Identifier Notation) implementation for Ruby.
|
|
9
9
|
|
|
10
|
-
##
|
|
10
|
+
## Overview
|
|
11
11
|
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
This gem implements the [SIN Specification v1.0.0](https://sashite.dev/specs/sin/1.0.0/) exactly, providing a rule-agnostic notation system for style identification in board games.
|
|
12
|
+
This library implements the [SIN Specification v1.0.0](https://sashite.dev/specs/sin/1.0.0/).
|
|
15
13
|
|
|
16
14
|
## Installation
|
|
17
15
|
|
|
@@ -28,321 +26,164 @@ gem install sashite-sin
|
|
|
28
26
|
|
|
29
27
|
## Usage
|
|
30
28
|
|
|
31
|
-
###
|
|
32
|
-
|
|
33
|
-
```ruby
|
|
34
|
-
require "sashite/sin"
|
|
35
|
-
|
|
36
|
-
# Parse SIN strings into identifier objects
|
|
37
|
-
identifier = Sashite::Sin.parse("C") # Family=:C, Side=:first
|
|
38
|
-
identifier.to_s # => "C"
|
|
39
|
-
identifier.family # => :C
|
|
40
|
-
identifier.side # => :first
|
|
41
|
-
identifier.letter # => "C" (combined representation)
|
|
42
|
-
|
|
43
|
-
# Create identifiers directly
|
|
44
|
-
identifier = Sashite::Sin.identifier(:C, :first) # Family=:C, Side=:first
|
|
45
|
-
identifier = Sashite::Sin::Identifier.new(:C, :second) # Family=:C, Side=:second
|
|
46
|
-
|
|
47
|
-
# Validate SIN strings
|
|
48
|
-
Sashite::Sin.valid?("C") # => true
|
|
49
|
-
Sashite::Sin.valid?("c") # => true
|
|
50
|
-
Sashite::Sin.valid?("1") # => false (not a letter)
|
|
51
|
-
Sashite::Sin.valid?("CC") # => false (not single character)
|
|
52
|
-
```
|
|
29
|
+
### Parsing (String → Identifier)
|
|
53
30
|
|
|
54
|
-
|
|
31
|
+
Convert a SIN string into an `Identifier` object.
|
|
55
32
|
|
|
56
33
|
```ruby
|
|
57
|
-
|
|
58
|
-
identifier = Sashite::Sin.parse("C")
|
|
59
|
-
|
|
60
|
-
# Flip player assignment
|
|
61
|
-
flipped = identifier.flip # Family=:C, Side=:second
|
|
62
|
-
flipped.to_s # => "c"
|
|
34
|
+
require "sashite/sin"
|
|
63
35
|
|
|
64
|
-
#
|
|
65
|
-
|
|
66
|
-
|
|
36
|
+
# Standard parsing (raises on error)
|
|
37
|
+
sin = Sashite::Sin.parse("C")
|
|
38
|
+
sin.abbr # => :C
|
|
39
|
+
sin.side # => :first
|
|
67
40
|
|
|
68
|
-
#
|
|
69
|
-
|
|
70
|
-
|
|
41
|
+
# Lowercase indicates second player
|
|
42
|
+
sin = Sashite::Sin.parse("c")
|
|
43
|
+
sin.abbr # => :C
|
|
44
|
+
sin.side # => :second
|
|
71
45
|
|
|
72
|
-
#
|
|
73
|
-
|
|
74
|
-
|
|
46
|
+
# Invalid input raises ArgumentError
|
|
47
|
+
Sashite::Sin.parse("") # => raises ArgumentError
|
|
48
|
+
Sashite::Sin.parse("CC") # => raises ArgumentError
|
|
75
49
|
```
|
|
76
50
|
|
|
77
|
-
###
|
|
51
|
+
### Formatting (Identifier → String)
|
|
78
52
|
|
|
79
|
-
|
|
80
|
-
identifier = Sashite::Sin.parse("C")
|
|
81
|
-
opposite = Sashite::Sin.parse("s")
|
|
82
|
-
|
|
83
|
-
# Player identification
|
|
84
|
-
identifier.first_player? # => true
|
|
85
|
-
identifier.second_player? # => false
|
|
86
|
-
opposite.first_player? # => false
|
|
87
|
-
opposite.second_player? # => true
|
|
88
|
-
|
|
89
|
-
# Family and side comparison
|
|
90
|
-
chess1 = Sashite::Sin.parse("C")
|
|
91
|
-
chess2 = Sashite::Sin.parse("c")
|
|
92
|
-
shogi = Sashite::Sin.parse("S")
|
|
93
|
-
|
|
94
|
-
chess1.same_family?(chess2) # => true (both Chess family)
|
|
95
|
-
chess1.same_side?(shogi) # => true (both first player)
|
|
96
|
-
chess1.same_family?(shogi) # => false (different families)
|
|
97
|
-
```
|
|
98
|
-
|
|
99
|
-
### Identifier Collections
|
|
53
|
+
Convert an `Identifier` back to a SIN string.
|
|
100
54
|
|
|
101
55
|
```ruby
|
|
102
|
-
#
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
# Filter by player
|
|
106
|
-
first_player_identifiers = identifiers.select(&:first_player?)
|
|
107
|
-
first_player_identifiers.map(&:to_s) # => ["C", "S", "M"]
|
|
56
|
+
# From Identifier object
|
|
57
|
+
sin = Sashite::Sin::Identifier.new(:C, :first)
|
|
58
|
+
sin.to_s # => "C"
|
|
108
59
|
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
by_family[:C].size # => 2 (both C and c)
|
|
112
|
-
|
|
113
|
-
# Find specific families
|
|
114
|
-
chess_identifiers = identifiers.select { |i| i.family == :C }
|
|
115
|
-
chess_identifiers.map(&:to_s) # => ["C", "c"]
|
|
60
|
+
sin = Sashite::Sin::Identifier.new(:C, :second)
|
|
61
|
+
sin.to_s # => "c"
|
|
116
62
|
```
|
|
117
63
|
|
|
118
|
-
|
|
64
|
+
### Validation
|
|
119
65
|
|
|
120
|
-
### Structure
|
|
121
|
-
```
|
|
122
|
-
<style-letter>
|
|
123
|
-
```
|
|
124
|
-
|
|
125
|
-
### Grammar (BNF)
|
|
126
|
-
```bnf
|
|
127
|
-
<sin> ::= <uppercase-letter> | <lowercase-letter>
|
|
128
|
-
|
|
129
|
-
<uppercase-letter> ::= "A" | "B" | "C" | ... | "Z"
|
|
130
|
-
<lowercase-letter> ::= "a" | "b" | "c" | ... | "z"
|
|
131
|
-
```
|
|
132
|
-
|
|
133
|
-
### Regular Expression
|
|
134
66
|
```ruby
|
|
135
|
-
|
|
67
|
+
# Boolean check
|
|
68
|
+
Sashite::Sin.valid?("C") # => true
|
|
69
|
+
Sashite::Sin.valid?("c") # => true
|
|
70
|
+
Sashite::Sin.valid?("") # => false
|
|
71
|
+
Sashite::Sin.valid?("CC") # => false
|
|
72
|
+
Sashite::Sin.valid?("1") # => false
|
|
136
73
|
```
|
|
137
74
|
|
|
138
|
-
###
|
|
139
|
-
|
|
140
|
-
SIN encodes style attributes using the following correspondence:
|
|
141
|
-
|
|
142
|
-
| Style Attribute | SIN Encoding | Examples |
|
|
143
|
-
|-----------------|--------------|----------|
|
|
144
|
-
| **Family** | Style family symbol | `:C`, `:S`, `:X` |
|
|
145
|
-
| **Side** | Player assignment | `:first`, `:second` |
|
|
146
|
-
| **Letter** | Combined representation | `"C"`, `"c"`, `"S"`, `"s"` |
|
|
147
|
-
|
|
148
|
-
#### Dual-Purpose Encoding
|
|
149
|
-
|
|
150
|
-
The **Letter** combines two distinct semantic components:
|
|
151
|
-
- **Style Family**: The underlying family symbol (:A-:Z), representing the game tradition or rule system
|
|
152
|
-
- **Player Assignment**: The side (:first or :second), encoded as case in the letter representation
|
|
153
|
-
|
|
154
|
-
**Examples**:
|
|
155
|
-
- Family `:C` + Side `:first` → Letter `"C"` (Chess, First player)
|
|
156
|
-
- Family `:C` + Side `:second` → Letter `"c"` (Chess, Second player)
|
|
157
|
-
- Family `:S` + Side `:first` → Letter `"S"` (Shōgi, First player)
|
|
158
|
-
- Family `:S` + Side `:second` → Letter `"s"` (Shōgi, Second player)
|
|
159
|
-
|
|
160
|
-
## Traditional Game Style Examples
|
|
161
|
-
|
|
162
|
-
The SIN specification is rule-agnostic and does not define specific letter assignments. However, here are common usage patterns following [SIN Examples](https://sashite.dev/specs/sin/1.0.0/examples/):
|
|
75
|
+
### Queries
|
|
163
76
|
|
|
164
77
|
```ruby
|
|
165
|
-
|
|
166
|
-
chess_white = Sashite::Sin.parse("C") # First player (White pieces)
|
|
167
|
-
chess_black = Sashite::Sin.parse("c") # Second player (Black pieces)
|
|
78
|
+
sin = Sashite::Sin.parse("C")
|
|
168
79
|
|
|
169
|
-
#
|
|
170
|
-
|
|
171
|
-
|
|
80
|
+
# Side queries
|
|
81
|
+
sin.first_player? # => true
|
|
82
|
+
sin.second_player? # => false
|
|
172
83
|
|
|
173
|
-
#
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
# Makruk (8×8 board)
|
|
178
|
-
makruk_white = Sashite::Sin.parse("M") # First player (White pieces)
|
|
179
|
-
makruk_black = Sashite::Sin.parse("m") # Second player (Black pieces)
|
|
180
|
-
|
|
181
|
-
# Janggi (9×10 board)
|
|
182
|
-
janggi_cho = Sashite::Sin.parse("J") # First player (Cho 초)
|
|
183
|
-
janggi_han = Sashite::Sin.parse("j") # Second player (Han 한)
|
|
84
|
+
# Comparison queries
|
|
85
|
+
other = Sashite::Sin.parse("c")
|
|
86
|
+
sin.same_abbr?(other) # => true
|
|
87
|
+
sin.same_side?(other) # => false
|
|
184
88
|
```
|
|
185
89
|
|
|
186
|
-
##
|
|
90
|
+
## API Reference
|
|
91
|
+
|
|
92
|
+
### Types
|
|
187
93
|
|
|
188
94
|
```ruby
|
|
189
|
-
#
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
#
|
|
194
|
-
|
|
195
|
-
[
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
95
|
+
# Identifier represents a parsed SIN identifier with abbreviation and side.
|
|
96
|
+
class Sashite::Sin::Identifier
|
|
97
|
+
# Creates an Identifier from abbreviation and side.
|
|
98
|
+
# Raises ArgumentError if attributes are invalid.
|
|
99
|
+
#
|
|
100
|
+
# @param abbr [Symbol] Style abbreviation (:A through :Z)
|
|
101
|
+
# @param side [Symbol] Player side (:first or :second)
|
|
102
|
+
# @return [Identifier]
|
|
103
|
+
def initialize(abbr, side)
|
|
104
|
+
|
|
105
|
+
# Returns the style abbreviation as an uppercase symbol.
|
|
106
|
+
#
|
|
107
|
+
# @return [Symbol]
|
|
108
|
+
def abbr
|
|
109
|
+
|
|
110
|
+
# Returns the player side.
|
|
111
|
+
#
|
|
112
|
+
# @return [Symbol] :first or :second
|
|
113
|
+
def side
|
|
114
|
+
|
|
115
|
+
# Returns the SIN string representation.
|
|
116
|
+
#
|
|
117
|
+
# @return [String]
|
|
118
|
+
def to_s
|
|
199
119
|
end
|
|
200
|
-
|
|
201
|
-
identifiers = create_hybrid_match
|
|
202
|
-
identifiers[0].same_side?(identifiers[1]) # => false (different players)
|
|
203
|
-
identifiers[0].same_family?(identifiers[1]) # => false (different families)
|
|
204
120
|
```
|
|
205
121
|
|
|
206
|
-
## System Constraints
|
|
207
|
-
|
|
208
|
-
### Character Limitation
|
|
209
|
-
SIN provides **26 possible identifiers** per player using ASCII letters (A-Z, a-z).
|
|
210
|
-
|
|
211
|
-
### Player Limitation
|
|
212
|
-
SIN supports exactly **two players** through case distinction:
|
|
213
|
-
- **First player**: Uppercase letters (A-Z) → `:first`
|
|
214
|
-
- **Second player**: Lowercase letters (a-z) → `:second`
|
|
215
|
-
|
|
216
|
-
### Context Dependency
|
|
217
|
-
The specific SIN assignment for a style may vary between different game contexts based on collision avoidance, historical precedence, and community conventions.
|
|
218
|
-
|
|
219
|
-
## API Reference
|
|
220
|
-
|
|
221
|
-
### Main Module Methods
|
|
222
|
-
|
|
223
|
-
- `Sashite::Sin.valid?(sin_string)` - Check if string is valid SIN notation
|
|
224
|
-
- `Sashite::Sin.parse(sin_string)` - Parse SIN string into Identifier object
|
|
225
|
-
- `Sashite::Sin.identifier(family, side)` - Create identifier instance directly
|
|
226
|
-
|
|
227
|
-
### Identifier Class
|
|
228
|
-
|
|
229
|
-
#### Creation and Parsing
|
|
230
|
-
- `Sashite::Sin::Identifier.new(family, side)` - Create identifier instance
|
|
231
|
-
- `Sashite::Sin::Identifier.parse(sin_string)` - Parse SIN string
|
|
232
|
-
|
|
233
|
-
#### Attribute Access
|
|
234
|
-
- `#family` - Get style family (symbol :A through :Z)
|
|
235
|
-
- `#side` - Get player side (:first or :second)
|
|
236
|
-
- `#letter` - Get combined letter representation (string)
|
|
237
|
-
- `#to_s` - Convert to SIN string representation
|
|
238
|
-
|
|
239
|
-
#### Player Queries
|
|
240
|
-
- `#first_player?` - Check if first player identifier
|
|
241
|
-
- `#second_player?` - Check if second player identifier
|
|
242
|
-
|
|
243
|
-
#### Transformations (immutable - return new instances)
|
|
244
|
-
- `#flip` - Switch player assignment
|
|
245
|
-
- `#with_family(new_family)` - Create identifier with different family
|
|
246
|
-
- `#with_side(new_side)` - Create identifier with different side
|
|
247
|
-
|
|
248
|
-
#### Comparison Methods
|
|
249
|
-
- `#same_family?(other)` - Check if same style family
|
|
250
|
-
- `#same_side?(other)` - Check if same player side
|
|
251
|
-
- `#==(other)` - Full equality comparison
|
|
252
|
-
- `#same_letter?(other)` - Alias for `same_family?` (deprecated)
|
|
253
|
-
|
|
254
122
|
### Constants
|
|
255
123
|
|
|
256
|
-
- `Sashite::Sin::Identifier::FIRST_PLAYER` - Symbol for first player (`:first`)
|
|
257
|
-
- `Sashite::Sin::Identifier::SECOND_PLAYER` - Symbol for second player (`:second`)
|
|
258
|
-
- `Sashite::Sin::Identifier::VALID_FAMILIES` - Array of valid families (`:A` to `:Z`)
|
|
259
|
-
- `Sashite::Sin::Identifier::VALID_SIDES` - Array of valid sides
|
|
260
|
-
- `Sashite::Sin::Identifier::SIN_PATTERN` - Regular expression for SIN validation
|
|
261
|
-
|
|
262
|
-
## Advanced Usage
|
|
263
|
-
|
|
264
|
-
### Family and Side Separation
|
|
265
|
-
|
|
266
124
|
```ruby
|
|
267
|
-
#
|
|
268
|
-
|
|
269
|
-
identifier.family # => :C (Style Family - invariant)
|
|
270
|
-
identifier.side # => :first (Player Assignment)
|
|
271
|
-
identifier.letter # => "C" (Combined representation)
|
|
272
|
-
|
|
273
|
-
# Transformations are explicit
|
|
274
|
-
chess_white = Sashite::Sin.identifier(:C, :first)
|
|
275
|
-
shogi_white = chess_white.with_family(:S) # Change family, keep side
|
|
276
|
-
chess_black = chess_white.with_side(:second) # Change side, keep family
|
|
125
|
+
Sashite::Sin::Identifier::VALID_ABBRS # => [:A, :B, ..., :Z]
|
|
126
|
+
Sashite::Sin::Identifier::VALID_SIDES # => [:first, :second]
|
|
277
127
|
```
|
|
278
128
|
|
|
279
|
-
###
|
|
129
|
+
### Parsing
|
|
280
130
|
|
|
281
131
|
```ruby
|
|
282
|
-
#
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
#
|
|
288
|
-
|
|
289
|
-
flipped.to_s # => "c"
|
|
290
|
-
changed_family.to_s # => "S"
|
|
291
|
-
|
|
292
|
-
# Transformations can be chained
|
|
293
|
-
result = original.flip.with_family(:M).flip
|
|
294
|
-
result.to_s # => "M"
|
|
132
|
+
# Parses a SIN string into an Identifier.
|
|
133
|
+
# Raises ArgumentError if the string is not valid.
|
|
134
|
+
#
|
|
135
|
+
# @param string [String] SIN string
|
|
136
|
+
# @return [Identifier]
|
|
137
|
+
# @raise [ArgumentError] if invalid
|
|
138
|
+
def Sashite::Sin.parse(string)
|
|
295
139
|
```
|
|
296
140
|
|
|
297
|
-
|
|
141
|
+
### Validation
|
|
298
142
|
|
|
299
|
-
|
|
143
|
+
```ruby
|
|
144
|
+
# Reports whether string is a valid SIN identifier.
|
|
145
|
+
#
|
|
146
|
+
# @param string [String] SIN string
|
|
147
|
+
# @return [Boolean]
|
|
148
|
+
def Sashite::Sin.valid?(string)
|
|
149
|
+
```
|
|
300
150
|
|
|
301
|
-
|
|
302
|
-
- **Rule-agnostic**: Independent of specific game mechanics
|
|
303
|
-
- **Minimal overhead**: Single character per style-player combination
|
|
304
|
-
- **Flexible collision resolution**: Systematic approaches for identifier conflicts
|
|
305
|
-
- **Semantic clarity**: Distinct concepts for Family, Side, and Letter
|
|
306
|
-
- **SNN coordination**: Works harmoniously with formal style naming
|
|
307
|
-
- **Context-aware**: Adapts to avoid conflicts within specific game scenarios
|
|
308
|
-
- **Canonical representation**: Each style-player combination has exactly one SIN identifier
|
|
309
|
-
- **Immutable**: All identifier instances are frozen and transformations return new objects
|
|
310
|
-
- **Functional**: Pure functions with no side effects
|
|
151
|
+
### Queries
|
|
311
152
|
|
|
312
|
-
|
|
153
|
+
```ruby
|
|
154
|
+
# Side queries
|
|
155
|
+
def first_player? # => Boolean
|
|
156
|
+
def second_player? # => Boolean
|
|
313
157
|
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
158
|
+
# Comparison queries
|
|
159
|
+
def same_abbr?(other) # => Boolean
|
|
160
|
+
def same_side?(other) # => Boolean
|
|
161
|
+
```
|
|
318
162
|
|
|
319
|
-
|
|
163
|
+
### Errors
|
|
320
164
|
|
|
321
|
-
|
|
322
|
-
- [SIN Examples Documentation](https://sashite.dev/specs/sin/1.0.0/examples/)
|
|
323
|
-
- [API Documentation](https://rubydoc.info/github/sashite/sin.rb/main)
|
|
165
|
+
All parsing and validation errors raise `ArgumentError` with descriptive messages:
|
|
324
166
|
|
|
325
|
-
|
|
167
|
+
| Message | Cause |
|
|
168
|
+
|---------|-------|
|
|
169
|
+
| `"empty input"` | String length is 0 |
|
|
170
|
+
| `"input exceeds 1 character"` | String too long |
|
|
171
|
+
| `"must be a letter"` | Character is not A-Z or a-z |
|
|
326
172
|
|
|
327
|
-
|
|
328
|
-
# Clone the repository
|
|
329
|
-
git clone https://github.com/sashite/sin.rb.git
|
|
330
|
-
cd sin.rb
|
|
173
|
+
## Design Principles
|
|
331
174
|
|
|
332
|
-
|
|
333
|
-
|
|
175
|
+
- **Bounded values**: Explicit validation of abbreviations and sides
|
|
176
|
+
- **Object-oriented**: `Identifier` class enables methods and encapsulation
|
|
177
|
+
- **Ruby idioms**: `valid?` predicate, `to_s` conversion, `ArgumentError` for invalid input
|
|
178
|
+
- **Immutable identifiers**: Instances are frozen after creation
|
|
179
|
+
- **No dependencies**: Pure Ruby standard library only
|
|
334
180
|
|
|
335
|
-
|
|
336
|
-
ruby test.rb
|
|
181
|
+
## Related Specifications
|
|
337
182
|
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
183
|
+
- [Game Protocol](https://sashite.dev/game-protocol/) — Conceptual foundation
|
|
184
|
+
- [SIN Specification](https://sashite.dev/specs/sin/1.0.0/) — Official specification
|
|
185
|
+
- [SIN Examples](https://sashite.dev/specs/sin/1.0.0/examples/) — Usage examples
|
|
341
186
|
|
|
342
187
|
## License
|
|
343
188
|
|
|
344
|
-
Available as open source under the [
|
|
345
|
-
|
|
346
|
-
## About
|
|
347
|
-
|
|
348
|
-
Maintained by [Sashité](https://sashite.com/) — promoting chess variants and sharing the beauty of board game cultures.
|
|
189
|
+
Available as open source under the [Apache License 2.0](https://opensource.org/licenses/Apache-2.0).
|