sashite-cgsn 0.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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 5130413add3619290ba1adcb1240d3e924510277ebd1361e25860a23846a4013
4
+ data.tar.gz: 2a614fa5d19b477db200774bc617e4d55e061232a74bbcd8566a4063930403c8
5
+ SHA512:
6
+ metadata.gz: 41dddcc173c4d1315668c8179ba8023122bd38a430dd90d62ec7f202d478a6bec09c154deac1867307af53cb0eeb5aca91d9a16e6126f407cfe08d3d71b5ed69
7
+ data.tar.gz: 3c45298716d464f82383a91f99ef27a06ae17c999df42443445eff2afb628ce36eb998a9500eb3c1085b58f7059b057818ec97e72d8886e0e63fb9443463c487
data/LICENSE.md ADDED
@@ -0,0 +1,22 @@
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.
data/README.md ADDED
@@ -0,0 +1,175 @@
1
+ # Cgsn.rb
2
+
3
+ [![Version](https://img.shields.io/github/v/tag/sashite/cgsn.rb?label=Version&logo=github)](https://github.com/sashite/cgsn.rb/tags)
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)
7
+
8
+ > **CGSN** (Chess Game Status Notation) implementation for the Ruby language.
9
+
10
+ ## What is CGSN?
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.
15
+
16
+ ## Installation
17
+
18
+ ```ruby
19
+ # In your Gemfile
20
+ gem "sashite-cgsn"
21
+ ```
22
+
23
+ Or install manually:
24
+
25
+ ```sh
26
+ gem install sashite-cgsn
27
+ ```
28
+
29
+ ## Format
30
+
31
+ CGSN status values are lowercase strings using underscore separators:
32
+
33
+ ```ruby
34
+ "checkmate"
35
+ "bare_king"
36
+ "time_limit"
37
+ "in_progress"
38
+ ```
39
+
40
+ ## API Reference
41
+
42
+ ### Status Class
43
+
44
+ #### Creation and Parsing
45
+
46
+ * `Sashite::Cgsn::Status.new(value)` - Create status instance from string
47
+ * `Sashite::Cgsn.parse(value)` - Parse status value (module convenience method)
48
+
49
+ #### Instance Methods
50
+
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
56
+
57
+ ### Module Methods
58
+
59
+ #### Validation
60
+
61
+ * `Sashite::Cgsn.valid?(status)` - Check if string is a valid CGSN status value
62
+
63
+ #### Categorization
64
+
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
67
+
68
+ #### Status Lists
69
+
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
73
+
74
+ ### Constants
75
+
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
+ ```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
100
+ ```
101
+
102
+ ### Functional Approach
103
+
104
+ ```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?("time_limit") # => true
114
+
115
+ # Get all statuses
116
+ Sashite::Cgsn.statuses
117
+ # => ["in_progress", "checkmate", "stalemate", ...]
118
+ ```
119
+
120
+ ## Properties
121
+
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
129
+
130
+ ## Related Specifications
131
+
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
135
+
136
+ ## Documentation
137
+
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)
141
+
142
+ ## Development
143
+
144
+ ```sh
145
+ # Clone the repository
146
+ git clone https://github.com/sashite/cgsn.rb.git
147
+ cd cgsn.rb
148
+
149
+ # Install dependencies
150
+ bundle install
151
+
152
+ # Run tests
153
+ ruby test.rb
154
+
155
+ # Generate documentation
156
+ yard doc
157
+ ```
158
+
159
+ ## Contributing
160
+
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
168
+
169
+ ## License
170
+
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.
@@ -0,0 +1,85 @@
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
@@ -0,0 +1,140 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "cgsn/status"
4
+
5
+ module Sashite
6
+ # CGSN (Chess Game Status Notation) implementation for Ruby
7
+ #
8
+ # Provides functionality for working with rule-agnostic game status values
9
+ # for abstract strategy board games.
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
13
+ module Cgsn
14
+ # Complete list of all defined CGSN status values
15
+ STATUSES = %w[
16
+ in_progress
17
+ checkmate
18
+ stalemate
19
+ bare_king
20
+ mare_king
21
+ insufficient
22
+ resignation
23
+ illegal_move
24
+ time_limit
25
+ move_limit
26
+ repetition
27
+ agreement
28
+ ].freeze
29
+
30
+ # Statuses that can be inferred from position analysis
31
+ INFERABLE_STATUSES = %w[
32
+ in_progress
33
+ checkmate
34
+ stalemate
35
+ bare_king
36
+ mare_king
37
+ insufficient
38
+ ].freeze
39
+
40
+ # Statuses that require explicit declaration
41
+ EXPLICIT_ONLY_STATUSES = %w[
42
+ resignation
43
+ illegal_move
44
+ time_limit
45
+ move_limit
46
+ repetition
47
+ agreement
48
+ ].freeze
49
+
50
+ # Check if a string is a valid CGSN status value
51
+ #
52
+ # @param value [String] the status to validate
53
+ # @return [Boolean] true if the status is valid
54
+ #
55
+ # @example
56
+ # Sashite::Cgsn.valid?("checkmate") # => true
57
+ # Sashite::Cgsn.valid?("time_limit") # => true
58
+ # Sashite::Cgsn.valid?("invalid") # => false
59
+ # Sashite::Cgsn.valid?("Checkmate") # => false
60
+ def self.valid?(value)
61
+ STATUSES.include?(value)
62
+ rescue ::TypeError
63
+ false
64
+ end
65
+
66
+ # Parse a status value into a Status object
67
+ #
68
+ # @param value [String] the status value to parse
69
+ # @return [Status] new status instance
70
+ # @raise [ArgumentError] if the status value is invalid
71
+ #
72
+ # @example
73
+ # Sashite::Cgsn.parse("checkmate") # => #<Cgsn::Status value="checkmate">
74
+ # Sashite::Cgsn.parse("resignation") # => #<Cgsn::Status value="resignation">
75
+ def self.parse(value)
76
+ Status.new(value)
77
+ end
78
+
79
+ # Check if a status can be inferred from position analysis
80
+ #
81
+ # @param status [String, Status] the status to check
82
+ # @return [Boolean] true if the status is inferable
83
+ #
84
+ # @example
85
+ # Sashite::Cgsn.inferable?("checkmate") # => true
86
+ # Sashite::Cgsn.inferable?("resignation") # => false
87
+ def self.inferable?(status)
88
+ INFERABLE_STATUSES.include?(status)
89
+ rescue ::TypeError
90
+ false
91
+ end
92
+
93
+ # Check if a status requires explicit declaration
94
+ #
95
+ # @param status [String, Status] the status to check
96
+ # @return [Boolean] true if the status is explicit-only
97
+ #
98
+ # @example
99
+ # Sashite::Cgsn.explicit_only?("resignation") # => true
100
+ # Sashite::Cgsn.explicit_only?("checkmate") # => false
101
+ def self.explicit_only?(status)
102
+ EXPLICIT_ONLY_STATUSES.include?(status)
103
+ rescue ::TypeError
104
+ false
105
+ end
106
+
107
+ # Get the list of all defined CGSN status values
108
+ #
109
+ # @return [Array<String>] array of all status values
110
+ #
111
+ # @example
112
+ # Sashite::Cgsn.statuses
113
+ # # => ["in_progress", "checkmate", "stalemate", ...]
114
+ def self.statuses
115
+ STATUSES.dup
116
+ end
117
+
118
+ # Get the list of inferable status values
119
+ #
120
+ # @return [Array<String>] array of inferable status values
121
+ #
122
+ # @example
123
+ # Sashite::Cgsn.inferable_statuses
124
+ # # => ["in_progress", "checkmate", "stalemate", ...]
125
+ def self.inferable_statuses
126
+ INFERABLE_STATUSES.dup
127
+ end
128
+
129
+ # Get the list of explicit-only status values
130
+ #
131
+ # @return [Array<String>] array of explicit-only status values
132
+ #
133
+ # @example
134
+ # Sashite::Cgsn.explicit_only_statuses
135
+ # # => ["resignation", "illegal_move", "time_limit", ...]
136
+ def self.explicit_only_statuses
137
+ EXPLICIT_ONLY_STATUSES.dup
138
+ end
139
+ end
140
+ end
@@ -0,0 +1,14 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "sashite/cgsn"
4
+
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é
13
+ module Sashite
14
+ end
metadata ADDED
@@ -0,0 +1,60 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: sashite-cgsn
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Cyril Kato
8
+ bindir: bin
9
+ cert_chain: []
10
+ date: 1980-01-02 00:00:00.000000000 Z
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, bare_king,
17
+ mare_king, insufficient), player actions (resignation, agreement, illegal_move), and temporal
18
+ constraints (time_limit, move_limit, 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.
21
+ email: contact@cyril.email
22
+ executables: []
23
+ extensions: []
24
+ extra_rdoc_files: []
25
+ files:
26
+ - LICENSE.md
27
+ - README.md
28
+ - lib/sashite-cgsn.rb
29
+ - lib/sashite/cgsn.rb
30
+ - lib/sashite/cgsn/status.rb
31
+ homepage: https://github.com/sashite/cgsn.rb
32
+ licenses:
33
+ - MIT
34
+ metadata:
35
+ bug_tracker_uri: https://github.com/sashite/cgsn.rb/issues
36
+ documentation_uri: https://rubydoc.info/github/sashite/cgsn.rb/main
37
+ homepage_uri: https://github.com/sashite/cgsn.rb
38
+ source_code_uri: https://github.com/sashite/cgsn.rb
39
+ specification_uri: https://sashite.dev/specs/cgsn/1.0.0/
40
+ wiki_uri: https://sashite.dev/specs/cgsn/1.0.0/examples/
41
+ rubygems_mfa_required: 'true'
42
+ rdoc_options: []
43
+ require_paths:
44
+ - lib
45
+ required_ruby_version: !ruby/object:Gem::Requirement
46
+ requirements:
47
+ - - ">="
48
+ - !ruby/object:Gem::Version
49
+ version: 3.2.0
50
+ required_rubygems_version: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ requirements: []
56
+ rubygems_version: 3.7.1
57
+ specification_version: 4
58
+ summary: CGSN (Chess Game Status Notation) implementation for Ruby with immutable
59
+ status objects
60
+ test_files: []