Module: Sashite::Pnn

Defined in:
lib/sashite/pnn.rb,
lib/sashite/pnn/piece.rb

Overview

PNN (Piece Name Notation) implementation for Ruby

Extends PIN to provide style-aware piece representation in abstract strategy board games. PNN adds a derivation marker that distinguishes pieces by their style origin, enabling cross-style game scenarios and piece origin tracking.

Format: <pin>

  • PIN component: [<state>]<letter> (state modifier + letter)

  • Suffix: “‘” for foreign style, none for native style

Examples:

"K"   - First player king (native style)
"K'"  - First player king (foreign style)
"+R"  - First player rook, enhanced state (native style)
"+R'" - First player rook, enhanced state (foreign style)
"-p'" - Second player pawn, diminished state (foreign style)

See: sashite.dev/specs/pnn/1.0.0/

Defined Under Namespace

Classes: Piece

Constant Summary collapse

PNN_REGEX =

Regular expression for PNN validation Matches: optional state modifier, letter, optional derivation marker

/\A[-+]?[A-Za-z]'?\z/

Class Method Summary collapse

Class Method Details

.parse(pnn_string) ⇒ Pnn::Piece

Parse a PNN string into a Piece object

Examples:

Sashite::Pnn.parse("K")     # => #<Pnn::Piece letter="K" native=true>
Sashite::Pnn.parse("K'")    # => #<Pnn::Piece letter="K" native=false>
Sashite::Pnn.parse("+R'")   # => #<Pnn::Piece letter="R" enhanced=true native=false>

Parameters:

  • pnn_string (String)

    PNN notation string

Returns:

Raises:

  • (ArgumentError)

    if the PNN string is invalid



56
57
58
# File 'lib/sashite/pnn.rb', line 56

def self.parse(pnn_string)
  Piece.parse(pnn_string)
end

.valid?(pnn) ⇒ Boolean

Check if a string is a valid PNN notation

Examples:

Sashite::Pnn.valid?("K")    # => true
Sashite::Pnn.valid?("K'")   # => true
Sashite::Pnn.valid?("+R'")  # => true
Sashite::Pnn.valid?("-p'")  # => true
Sashite::Pnn.valid?("K''")  # => false
Sashite::Pnn.valid?("++K'") # => false

Parameters:

  • pnn (String)

    The string to validate

Returns:

  • (Boolean)

    true if valid PNN, false otherwise



41
42
43
44
45
# File 'lib/sashite/pnn.rb', line 41

def self.valid?(pnn)
  return false unless pnn.is_a?(::String)

  pnn.match?(PNN_REGEX)
end