sashite-gan 4.0.0 → 5.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.
data/lib/sashite/gan.rb CHANGED
@@ -1,88 +1,76 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require "sashite/snn"
4
- require "pnn"
5
3
  require_relative "gan/actor"
6
4
 
7
5
  module Sashite
8
- # General Actor Notation (GAN) module
6
+ # GAN (General Actor Notation) implementation for Ruby
9
7
  #
10
- # GAN provides a consistent and rule-agnostic format for identifying game actors
11
- # in abstract strategy board games. It combines Style Name Notation (SNN) with
12
- # Piece Name Notation (PNN) to create unambiguous actor identification that
13
- # eliminates collision problems when multiple piece styles are present.
8
+ # Provides a rule-agnostic format for identifying game actors in abstract strategy board games
9
+ # by combining Style Name Notation (SNN) and Piece Identifier Notation (PIN) with a colon separator
10
+ # and consistent case encoding.
14
11
  #
15
- # @see https://sashite.dev/documents/gan/1.0.0/ GAN Specification v1.0.0
12
+ # GAN represents all four fundamental piece attributes from the Game Protocol:
13
+ # - Type → PIN component (ASCII letter choice)
14
+ # - Side → Consistent case encoding across both SNN and PIN components
15
+ # - State → PIN component (optional prefix modifier)
16
+ # - Style → SNN component (explicit style identifier)
17
+ #
18
+ # Format: <snn>:<pin>
19
+ # - SNN component: Style identifier with case-based side encoding
20
+ # - Colon separator: Literal ":"
21
+ # - PIN component: Piece with optional state and case-based ownership
22
+ # - Case consistency: SNN and PIN components must have matching case
23
+ #
24
+ # Examples:
25
+ # "CHESS:K" - First player chess king
26
+ # "chess:k" - Second player chess king
27
+ # "SHOGI:+P" - First player enhanced shōgi pawn
28
+ # "xiangqi:-g" - Second player diminished xiangqi general
29
+ #
30
+ # See: https://sashite.dev/specs/gan/1.0.0/
16
31
  module Gan
17
- # GAN validation regular expression
18
- # Matches: <snn>:<pnn> where snn and pnn follow their respective specifications
19
- VALIDATION_REGEX = /\A([A-Z][A-Z0-9]*|[a-z][a-z0-9]*):[-+]?[a-zA-Z]'?\z/
20
-
21
32
  # Check if a string is valid GAN notation
22
33
  #
23
34
  # @param gan_string [String] The string to validate
24
- # @return [Boolean] true if the string is valid GAN notation, false otherwise
35
+ # @return [Boolean] true if valid GAN, false otherwise
25
36
  #
26
- # @example
37
+ # @example Validate various GAN formats
27
38
  # Sashite::Gan.valid?("CHESS:K") # => true
28
- # Sashite::Gan.valid?("shogi:+p'") # => true
39
+ # Sashite::Gan.valid?("shogi:+p") # => true
29
40
  # Sashite::Gan.valid?("Chess:K") # => false (mixed case in style)
41
+ # Sashite::Gan.valid?("CHESS:k") # => false (case mismatch)
30
42
  # Sashite::Gan.valid?("CHESS") # => false (missing piece)
31
43
  # Sashite::Gan.valid?("") # => false (empty string)
32
44
  def self.valid?(gan_string)
33
- return false unless gan_string.is_a?(String)
34
- return false if gan_string.empty?
35
-
36
- # Quick regex check first
37
- return false unless VALIDATION_REGEX.match?(gan_string)
38
-
39
- # Split and validate components individually for more precise validation
40
- parts = gan_string.split(":", 2)
41
- return false unless parts.length == 2
42
-
43
- style_part, piece_part = parts
44
-
45
- # Validate SNN and PNN components using their respective libraries
46
- Snn.valid?(style_part) && Pnn.valid?(piece_part)
45
+ Actor.valid?(gan_string)
47
46
  end
48
47
 
49
- # Convenience method to create an actor object
50
- #
51
- # @param style [String, Sashite::Snn::Style] The style identifier or style object
52
- # @param piece [String, Pnn::Piece] The piece identifier or piece object
53
- # @return [Sashite::Gan::Actor] A new actor object
54
- # @raise [ArgumentError] if the parameters are invalid
48
+ # Parse a GAN string into an Actor object
55
49
  #
56
- # @example
57
- # actor = Sashite::Gan.actor("CHESS", "K")
58
- # # => #<Sashite::Gan::Actor:0x... style="CHESS" piece="K">
59
- #
60
- # # With objects
61
- # style = Sashite::Snn::Style.new("CHESS")
62
- # piece = Pnn::Piece.new("K")
63
- # actor = Sashite::Gan.actor(style, piece)
64
- def self.actor(style, piece)
65
- Actor.new(style, piece)
50
+ # @param gan_string [String] GAN notation string
51
+ # @return [Gan::Actor] new actor instance
52
+ # @raise [ArgumentError] if the GAN string is invalid
53
+ # @example Parse different GAN formats
54
+ # Sashite::Gan.parse("CHESS:K") # => #<Gan::Actor name=:Chess type=:K side=:first state=:normal>
55
+ # Sashite::Gan.parse("shogi:+p") # => #<Gan::Actor name=:Shogi type=:P side=:second state=:enhanced>
56
+ # Sashite::Gan.parse("XIANGQI:-G") # => #<Gan::Actor name=:Xiangqi type=:G side=:first state=:diminished>
57
+ def self.parse(gan_string)
58
+ Actor.parse(gan_string)
66
59
  end
67
60
 
68
- # Parse a GAN string into component parts
69
- #
70
- # @param gan_string [String] The GAN string to parse
71
- # @return [Array<String>] An array containing [style_string, piece_string]
72
- # @raise [ArgumentError] if the string is invalid GAN notation
61
+ # Create a new actor instance
73
62
  #
74
- # @example
75
- # Sashite::Gan.parse_components("CHESS:K")
76
- # # => ["CHESS", "K"]
77
- #
78
- # Sashite::Gan.parse_components("shogi:+p'")
79
- # # => ["shogi", "+p'"]
80
- #
81
- # @api private
82
- def self.parse_components(gan_string)
83
- raise ArgumentError, "Invalid GAN format: #{gan_string.inspect}" unless valid?(gan_string)
84
-
85
- gan_string.split(":", 2)
63
+ # @param name [Symbol] style name (with proper capitalization)
64
+ # @param type [Symbol] piece type (:A to :Z)
65
+ # @param side [Symbol] player side (:first or :second)
66
+ # @param state [Symbol] piece state (:normal, :enhanced, or :diminished)
67
+ # @return [Gan::Actor] new actor instance
68
+ # @raise [ArgumentError] if parameters are invalid
69
+ # @example Create actors directly
70
+ # Sashite::Gan.actor(:Chess, :K, :first, :normal) # => #<Gan::Actor name=:Chess type=:K side=:first state=:normal>
71
+ # Sashite::Gan.actor(:Shogi, :P, :second, :enhanced) # => #<Gan::Actor name=:Shogi type=:P side=:second state=:enhanced>
72
+ def self.actor(name, type, side, state = :normal)
73
+ Actor.new(name, type, side, state)
86
74
  end
87
75
  end
88
76
  end
data/lib/sashite-gan.rb CHANGED
@@ -1,18 +1,14 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require_relative "sashite/gan"
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 Game Protocol specifications.
9
+ #
10
+ # @see https://sashite.dev/game-protocol/ Game Protocol Foundation
11
+ # @see https://sashite.dev/specs/ Sashité Specifications
12
+ # @author Sashité
4
13
  module Sashite
5
- # General Actor Notation (GAN) implementation for Ruby
6
- #
7
- # GAN defines a consistent and rule-agnostic format for identifying game actors
8
- # in abstract strategy board games. GAN provides unambiguous identification of
9
- # pieces by combining Style Name Notation (SNN) with Piece Name Notation (PNN),
10
- # eliminating collision problems when multiple piece styles are present in the
11
- # same context.
12
- #
13
- # @see https://sashite.dev/documents/gan/1.0.0/ GAN Specification v1.0.0
14
- # @author Sashité
15
- # @since 1.0.0
16
14
  end
17
-
18
- require_relative "sashite/gan"
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sashite-gan
3
3
  version: !ruby/object:Gem::Version
4
- version: 4.0.0
4
+ version: 5.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Cyril Kato
@@ -10,37 +10,40 @@ cert_chain: []
10
10
  date: 1980-01-02 00:00:00.000000000 Z
11
11
  dependencies:
12
12
  - !ruby/object:Gem::Dependency
13
- name: pnn
13
+ name: sashite-pin
14
14
  requirement: !ruby/object:Gem::Requirement
15
15
  requirements:
16
16
  - - "~>"
17
17
  - !ruby/object:Gem::Version
18
- version: 2.0.0
18
+ version: 2.0.2
19
19
  type: :runtime
20
20
  prerelease: false
21
21
  version_requirements: !ruby/object:Gem::Requirement
22
22
  requirements:
23
23
  - - "~>"
24
24
  - !ruby/object:Gem::Version
25
- version: 2.0.0
25
+ version: 2.0.2
26
26
  - !ruby/object:Gem::Dependency
27
27
  name: sashite-snn
28
28
  requirement: !ruby/object:Gem::Requirement
29
29
  requirements:
30
30
  - - "~>"
31
31
  - !ruby/object:Gem::Version
32
- version: 1.0.0
32
+ version: 1.1.1
33
33
  type: :runtime
34
34
  prerelease: false
35
35
  version_requirements: !ruby/object:Gem::Requirement
36
36
  requirements:
37
37
  - - "~>"
38
38
  - !ruby/object:Gem::Version
39
- version: 1.0.0
40
- description: A Ruby interface for serialization and deserialization of game actors
41
- in GAN format. GAN is a consistent and rule-agnostic format for representing game
42
- actors in abstract strategy board games, providing a standardized way to identify
43
- pieces with their originating game.
39
+ version: 1.1.1
40
+ description: 'A Ruby implementation of GAN (General Actor Notation) v1.0.0 specification
41
+ for identifying game actors in abstract strategy board games. GAN combines Style
42
+ Name Notation (SNN) and Piece Identifier Notation (PIN) with a colon separator to
43
+ provide complete, unambiguous piece identification. Represents all four fundamental
44
+ piece attributes: Type, Side, State, and Style. Enables cross-style gaming, immutable
45
+ transformations, and component extraction with to_pin/to_snn methods. Built on sashite-snn
46
+ and sashite-pin gems.'
44
47
  email: contact@cyril.email
45
48
  executables: []
46
49
  extensions: []
@@ -59,7 +62,7 @@ metadata:
59
62
  documentation_uri: https://rubydoc.info/github/sashite/gan.rb/main
60
63
  homepage_uri: https://github.com/sashite/gan.rb
61
64
  source_code_uri: https://github.com/sashite/gan.rb
62
- specification_uri: https://sashite.dev/documents/gan/1.0.0/
65
+ specification_uri: https://sashite.dev/specs/gan/1.0.0/
63
66
  rubygems_mfa_required: 'true'
64
67
  rdoc_options: []
65
68
  require_paths:
@@ -75,7 +78,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
75
78
  - !ruby/object:Gem::Version
76
79
  version: '0'
77
80
  requirements: []
78
- rubygems_version: 3.6.7
81
+ rubygems_version: 3.6.9
79
82
  specification_version: 4
80
- summary: GAN (General Actor Notation) support for the Ruby language.
83
+ summary: GAN (General Actor Notation) implementation for Ruby - board game piece identification
81
84
  test_files: []