sashite-cell 2.0.0 → 2.0.1

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: c4fefcdbade2adc694035b6fbff032fb8e03466e35406a67f2a9d1c61b9fd600
4
- data.tar.gz: 42c3150a201310805948eaa2e9e6bf05fc9c198925024d7a203f0093d6ee969a
3
+ metadata.gz: 84228cab7c7155caaec3a2adad475150eb8b272c5c8e67d2dfb1e626b6120e7e
4
+ data.tar.gz: 318c49ae54afbfec1edaeca7a03c23c7cc5a65cec0658d14973f54a203c15914
5
5
  SHA512:
6
- metadata.gz: 185910faaa10494b20d39b58ac3f25007d432d63d230de76cf666762a215ab8177283c0fe167efc28fdc24b4abcc55bdb25211fc9d216856b62d889005e57c8c
7
- data.tar.gz: 43fe0766f8fe932e2a57dec85c89a07db4f30a543319f035b7e893a8122cfaf30ed90a635515bb9867a1509dc9e374ecf3c0b16c6efb39b419413a4811aebfe2
6
+ metadata.gz: afe40400d123291deed966e92943ac01b18195cb1a1d191473ff0c719721288c4bae5c1032b6a524f194c722779818c81d02c4709e115bb7f29916eb3ed1828f
7
+ data.tar.gz: be17bfa93a1db05ddaecc938db407a3788ab565d1254e3f61ff9cdd714a09298c5137d3131e11d374d0c9c2d51725a0720f8e8dac7375b614ad3909e26e8687c
data/README.md CHANGED
@@ -5,13 +5,13 @@
5
5
  ![Ruby](https://github.com/sashite/cell.rb/actions/workflows/main.yml/badge.svg?branch=main)
6
6
  [![License](https://img.shields.io/github/license/sashite/cell.rb?label=License&logo=github)](https://github.com/sashite/cell.rb/raw/main/LICENSE.md)
7
7
 
8
- > **CELL** (Cell Encoding Location Label) support for the Ruby language.
8
+ > **CELL** (Coordinate Encoding for Layered Locations) support for the Ruby language.
9
9
 
10
10
  ## What is CELL?
11
11
 
12
- CELL (Cell Encoding Location Label) is a standardized format for representing coordinates on multi-dimensional game boards using a cyclical ASCII character system. CELL supports unlimited dimensional coordinate systems through the systematic repetition of three distinct character sets.
12
+ CELL (Coordinate Encoding for Layered Locations) is a standardized format for representing coordinates on multi-dimensional game boards using a cyclical ASCII character system. CELL supports unlimited dimensional coordinate systems through the systematic repetition of three distinct character sets.
13
13
 
14
- This gem implements the [CELL Specification v1.0.0](https://sashite.dev/documents/cell/1.0.0/), providing a Ruby interface for working with multi-dimensional game coordinates through a clean, functional API.
14
+ This gem implements the [CELL Specification v1.0.0](https://sashite.dev/specs/cell/1.0.0/), providing a Ruby interface for working with multi-dimensional game coordinates through a clean, functional API.
15
15
 
16
16
  ## Installation
17
17
 
@@ -125,14 +125,16 @@ chess_squares.all? { |square| Sashite::Cell.valid?(square) }
125
125
  # => true
126
126
  ```
127
127
 
128
- ### Shogi Board (9x9)
128
+ ### Shōgi Board (9x9)
129
129
 
130
130
  ```ruby
131
- # Japanese shogi uses 9x9 board
132
- shogi_position = "5e" # 5th file, e rank
133
- Sashite::Cell.valid?(shogi_position) # => true
134
- Sashite::Cell.dimensions(shogi_position) # => 2
135
- Sashite::Cell.to_indices(shogi_position) # => [4, 4]
131
+ # CELL coordinates for shōgi positions
132
+ shogi_positions = %w[a1 e5 i9] # Left corner, center, right corner
133
+ shogi_positions.all? { |pos| Sashite::Cell.valid?(pos) }
134
+ # => true
135
+
136
+ # Convert to indices for board representation
137
+ Sashite::Cell.to_indices("e5") # => [4, 4] (center of 9x9 board)
136
138
  ```
137
139
 
138
140
  ### 3D Tic-Tac-Toe (3x3x3)
@@ -142,6 +144,11 @@ Sashite::Cell.to_indices(shogi_position) # => [4, 4]
142
144
  positions_3d = %w[a1A b2B c3C a2B b3C c1A]
143
145
  positions_3d.all? { |pos| Sashite::Cell.valid?(pos) && Sashite::Cell.dimensions(pos) == 3 }
144
146
  # => true
147
+
148
+ # Winning diagonal across all three dimensions
149
+ diagonal_win = %w[a1A b2B c3C]
150
+ diagonal_win.map { |pos| Sashite::Cell.to_indices(pos) }
151
+ # => [[0,0,0], [1,1,1], [2,2,2]]
145
152
  ```
146
153
 
147
154
  ### Multi-dimensional Coordinates
@@ -179,7 +186,7 @@ Sashite::Cell.parse(coord_5d) # => ["b", "2", "B", "b", "2"]
179
186
 
180
187
  ### Constants
181
188
 
182
- - `Sashite::Cell::REGEX` - Regular expression for CELL validation: `/\A(?:[a-z]+|[1-9]\d*|[A-Z]+)+\z/`
189
+ - `Sashite::Cell::REGEX` - Regular expression for CELL validation per specification v1.0.0
183
190
 
184
191
  ## Properties of CELL
185
192
 
@@ -188,7 +195,7 @@ Sashite::Cell.parse(coord_5d) # => ["b", "2", "B", "b", "2"]
188
195
  * **ASCII-based**: Pure ASCII characters for universal compatibility
189
196
  * **Unambiguous**: Each coordinate maps to exactly one location
190
197
  * **Scalable**: Extends naturally from 1D to unlimited dimensions
191
- * **Functional**: Provides a clean, stateless API for coordinate operations
198
+ * **Rule-agnostic**: Independent of specific game mechanics
192
199
 
193
200
  ## Character Set Details
194
201
 
@@ -234,6 +241,9 @@ end_position = "e4"
234
241
 
235
242
  Sashite::Cell.valid?(start_position) # => true
236
243
  Sashite::Cell.valid?(end_position) # => true
244
+
245
+ # Convert to array indices for board representation
246
+ Sashite::Cell.to_indices("e4") # => [4, 3]
237
247
  ```
238
248
 
239
249
  ### Go (19x19)
@@ -258,17 +268,80 @@ tesseract_pos = "h8Hh8"
258
268
  # Validate high-dimensional coordinates
259
269
  Sashite::Cell.valid?(hypercube_4d) # => true
260
270
  Sashite::Cell.dimensions(tesseract_pos) # => 5
271
+
272
+ # Convert for mathematical operations
273
+ Sashite::Cell.to_indices(hypercube_4d) # => [0, 0, 0, 0]
274
+ ```
275
+
276
+ ## Specification Compliance
277
+
278
+ This implementation strictly follows the [CELL Specification v1.0.0](https://sashite.dev/specs/cell/1.0.0/) and includes:
279
+
280
+ - **Exact regex**: Uses the official validation pattern from the specification
281
+ - **Complete API**: All methods and behaviors defined in the specification
282
+ - **Full test coverage**: Validates against all specification examples
283
+ - **Round-trip safety**: Guaranteed coordinate ↔ indices conversion integrity
284
+
285
+ ### Specification Examples
286
+
287
+ All examples from the CELL specification work correctly:
288
+
289
+ ```ruby
290
+ # Basic Examples from spec
291
+ Sashite::Cell.valid?("a") # => true (1D)
292
+ Sashite::Cell.valid?("a1") # => true (2D)
293
+ Sashite::Cell.valid?("a1A") # => true (3D)
294
+ Sashite::Cell.valid?("a1Aa1A") # => true (6D)
295
+
296
+ # Extended Alphabet Examples from spec
297
+ Sashite::Cell.valid?("aa1AA") # => true
298
+ Sashite::Cell.valid?("z26Z") # => true
299
+ Sashite::Cell.valid?("abc123XYZ") # => true
300
+
301
+ # Invalid Examples from spec
302
+ Sashite::Cell.valid?("") # => false
303
+ Sashite::Cell.valid?("a0") # => false
304
+ Sashite::Cell.valid?("1a") # => false
305
+ Sashite::Cell.valid?("a1a") # => false
261
306
  ```
262
307
 
263
308
  ## Documentation
264
309
 
265
- - [Official CELL Specification](https://sashite.dev/documents/cell/1.0.0/)
310
+ - [Official CELL Specification v1.0.0](https://sashite.dev/specs/cell/1.0.0/)
266
311
  - [API Documentation](https://rubydoc.info/github/sashite/cell.rb/main)
312
+ - [CELL Examples](https://sashite.dev/specs/cell/1.0.0/examples/)
313
+
314
+ ## Development
315
+
316
+ ```sh
317
+ # Clone the repository
318
+ git clone https://github.com/sashite/cell.rb.git
319
+ cd cell.rb
320
+
321
+ # Install dependencies
322
+ bundle install
323
+
324
+ # Run tests
325
+ ruby test.rb
326
+
327
+ # Generate documentation
328
+ yard doc
329
+ ```
330
+
331
+ ## Contributing
332
+
333
+ 1. Fork the repository
334
+ 2. Create a feature branch (`git checkout -b feature/new-feature`)
335
+ 3. Add tests for your changes
336
+ 4. Ensure all tests pass (`ruby test.rb`)
337
+ 5. Commit your changes (`git commit -am 'Add new feature'`)
338
+ 6. Push to the branch (`git push origin feature/new-feature`)
339
+ 7. Create a Pull Request
267
340
 
268
341
  ## License
269
342
 
270
- The [gem](https://rubygems.org/gems/sashite-cell) is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
343
+ Available as open source under the [MIT License](https://opensource.org/licenses/MIT).
271
344
 
272
- ## About Sashité
345
+ ## About
273
346
 
274
- This project is maintained by [Sashité](https://sashite.com/) — promoting chess variants and sharing the beauty of Chinese, Japanese, and Western chess cultures.
347
+ Maintained by [Sashité](https://sashite.com/) — promoting chess variants and sharing the beauty of board game cultures.
data/lib/sashite/cell.rb CHANGED
@@ -1,17 +1,17 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Sashite
4
- # CELL (Cell Encoding Location Label) implementation for Ruby
4
+ # CELL (Coordinate Encoding for Layered Locations) implementation for Ruby
5
5
  #
6
6
  # Provides functionality for working with multi-dimensional game board coordinates
7
7
  # using a cyclical ASCII character system.
8
8
  #
9
- # @see https://sashite.dev/documents/cell/1.0.0/ CELL Specification v1.0.0
9
+ # This implementation is strictly compliant with CELL Specification v1.0.0
10
+ # @see https://sashite.dev/specs/cell/1.0.0/ CELL Specification v1.0.0
10
11
  module Cell
11
- # Regular expression for validating CELL coordinates according to specification
12
- # This is the exact regex from the CELL specification v1.0.0
13
- # Using non-capturing groups to avoid Ruby's nested quantifier warning
14
- REGEX = /\A[a-z]+(?:[1-9]\d*[A-Z]+[a-z]+)*(?:[1-9]\d*(?:[A-Z]*))?\z/
12
+ # Regular expression for validating CELL coordinates according to specification v1.0.0
13
+ # Optimized version with redundant nested repeat operator removed for clean Ruby execution
14
+ REGEX = /\A[a-z]+(?:[1-9]\d*[A-Z]+[a-z]+)*(?:[1-9]\d*[A-Z]*)?\z/
15
15
 
16
16
  # Check if a string represents a valid CELL coordinate
17
17
  #
@@ -27,7 +27,7 @@ module Sashite
27
27
  return false unless string.is_a?(String)
28
28
  return false if string.empty?
29
29
 
30
- # Use the formal regex for validation
30
+ # Use the optimized CELL v1.0.0 regex for validation
31
31
  string.match?(REGEX)
32
32
  end
33
33
 
@@ -104,13 +104,13 @@ module Sashite
104
104
 
105
105
  # Get the validation regular expression
106
106
  #
107
- # @return [Regexp] the CELL validation regex
107
+ # @return [Regexp] the CELL validation regex from specification v1.0.0
108
108
  def self.regex
109
109
  REGEX
110
110
  end
111
111
 
112
112
  # Recursively parse a coordinate string into components
113
- # following the strict CELL specification pattern
113
+ # following the strict CELL specification cyclical pattern
114
114
  #
115
115
  # @param string [String] the remaining string to parse
116
116
  # @param dimension [Integer] the current dimension (1-indexed)
@@ -123,23 +123,21 @@ module Sashite
123
123
 
124
124
  return [] if component.nil?
125
125
 
126
- # Invalid format according to CELL specification
127
-
128
126
  # Extract component and recursively parse the rest
129
127
  remaining = string[component.length..]
130
128
  [component] + parse_recursive(remaining, dimension + 1)
131
129
  end
132
130
 
133
131
  # Determine the character set type for a given dimension
134
- # Following CELL specification: dimension n % 3 determines character set
132
+ # Following CELL specification cyclical system: dimension n % 3 determines character set
135
133
  #
136
134
  # @param dimension [Integer] the dimension number (1-indexed)
137
135
  # @return [Symbol] :lowercase, :numeric, or :uppercase
138
136
  def self.dimension_type(dimension)
139
137
  case dimension % 3
140
- when 1 then :lowercase
141
- when 2 then :numeric
142
- when 0 then :uppercase
138
+ when 1 then :lowercase # n % 3 = 1: Latin lowercase letters
139
+ when 2 then :numeric # n % 3 = 2: Arabic numerals
140
+ when 0 then :uppercase # n % 3 = 0: Latin uppercase letters
143
141
  end
144
142
  end
145
143
 
@@ -152,13 +150,15 @@ module Sashite
152
150
  def self.extract_component(string, type)
153
151
  case type
154
152
  when :lowercase
153
+ # Latin lowercase letters: [a-z]+
155
154
  match = string.match(/\A([a-z]+)/)
156
155
  match ? match[1] : nil
157
156
  when :numeric
158
- # CELL specification requires positive integers only (no zero)
157
+ # Arabic numerals: [1-9]\d* (CELL specification requires positive integers only)
159
158
  match = string.match(/\A([1-9]\d*)/)
160
159
  match ? match[1] : nil
161
160
  when :uppercase
161
+ # Latin uppercase letters: [A-Z]+
162
162
  match = string.match(/\A([A-Z]+)/)
163
163
  match ? match[1] : nil
164
164
  end
@@ -197,7 +197,7 @@ module Sashite
197
197
  end
198
198
 
199
199
  # Convert letter sequence to 0-indexed position
200
- # Extended alphabet: a=0, b=1, ..., z=25, aa=26, ab=27, ..., zz=701, aaa=702, etc.
200
+ # Extended alphabet per CELL specification: a=0, b=1, ..., z=25, aa=26, ab=27, ..., zz=701, aaa=702, etc.
201
201
  #
202
202
  # @param letters [String] the letter sequence
203
203
  # @return [Integer] the 0-indexed position
@@ -219,7 +219,7 @@ module Sashite
219
219
  end
220
220
 
221
221
  # Convert 0-indexed position to letter sequence
222
- # Extended alphabet: 0=a, 1=b, ..., 25=z, 26=aa, 27=ab, ..., 701=zz, 702=aaa, etc.
222
+ # Extended alphabet per CELL specification: 0=a, 1=b, ..., 25=z, 26=aa, 27=ab, ..., 701=zz, 702=aaa, etc.
223
223
  #
224
224
  # @param index [Integer] the 0-indexed position
225
225
  # @return [String] the letter sequence
data/lib/sashite-cell.rb CHANGED
@@ -1,8 +1,14 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require_relative "sashite/cell"
4
+
3
5
  # Sashité namespace for board game notation libraries
6
+ #
7
+ # Sashité provides a collection of libraries for representing and manipulating
8
+ # board game concepts according to the Sashité Protocol specifications.
9
+ #
10
+ # @see https://sashite.dev/protocol/ Sashité Protocol
11
+ # @see https://sashite.dev/specs/ Sashité Specifications
12
+ # @author Sashité
4
13
  module Sashite
5
- # @see https://sashite.dev/documents/cell/1.0.0/ CELL Specification v1.0.0
6
14
  end
7
-
8
- require_relative "sashite/cell"
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sashite-cell
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.0
4
+ version: 2.0.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Cyril Kato
@@ -10,9 +10,9 @@ cert_chain: []
10
10
  date: 1980-01-02 00:00:00.000000000 Z
11
11
  dependencies: []
12
12
  description: CELL defines a standardized format for representing coordinates on multi-dimensional
13
- game boards using diverse writing systems from around the world. This gem provides
14
- a Ruby interface for working with multi-dimensional game coordinates through a clean,
15
- functional API.
13
+ game boards using a cyclical ASCII character system. This gem provides a Ruby interface
14
+ for working with unlimited dimensional game coordinates through a clean, functional
15
+ API that strictly follows the CELL Specification v1.0.0.
16
16
  email: contact@cyril.email
17
17
  executables: []
18
18
  extensions: []
@@ -30,7 +30,9 @@ metadata:
30
30
  documentation_uri: https://rubydoc.info/github/sashite/cell.rb/main
31
31
  homepage_uri: https://github.com/sashite/cell.rb
32
32
  source_code_uri: https://github.com/sashite/cell.rb
33
- specification_uri: https://sashite.dev/documents/cell/1.0.0/
33
+ specification_uri: https://sashite.dev/specs/cell/1.0.0/
34
+ wiki_uri: https://sashite.dev/specs/cell/1.0.0/examples/
35
+ funding_uri: https://github.com/sponsors/sashite
34
36
  rubygems_mfa_required: 'true'
35
37
  rdoc_options: []
36
38
  require_paths:
@@ -48,5 +50,5 @@ required_rubygems_version: !ruby/object:Gem::Requirement
48
50
  requirements: []
49
51
  rubygems_version: 3.6.9
50
52
  specification_version: 4
51
- summary: CELL (Cell Encoding Location Label) implementation for Ruby
53
+ summary: CELL (Coordinate Encoding for Layered Locations) implementation for Ruby
52
54
  test_files: []