Module: Sashite::Pnn

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

Overview

PNN (Piece Name Notation) implementation for Ruby

Provides a formal naming system for identifying pieces in abstract strategy board games. PNN uses canonical, human-readable ASCII names with optional state modifiers and case encoding for player assignment. It supports unlimited unique piece identifiers with consistent, rule-agnostic semantics.

Format: [<state-modifier>]<case-consistent-name>

Examples:

"KING"        - First player king (normal state)
"queen"       - Second player queen (normal state)
"+ROOK"       - First player rook (enhanced state)
"-pawn"       - Second player pawn (diminished state)
"BISHOP"      - First player bishop (normal state)

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

Defined Under Namespace

Classes: Name

Class Method Summary collapse

Class Method Details

.name(value) ⇒ Pnn::Name

Create a new Name instance directly

Examples:

Sashite::Pnn.name("BISHOP") # => #<Pnn::Name value="BISHOP">
Sashite::Pnn.name(:queen)   # => #<Pnn::Name value="queen">

Parameters:

  • value (String, Symbol)

    piece name to construct

Returns:

Raises:

  • (ArgumentError)

    if name format is invalid



62
63
64
# File 'lib/sashite/pnn.rb', line 62

def self.name(value)
  Name.new(value)
end

.parse(pnn_string) ⇒ Pnn::Name

Parse a PNN string into a Name object

Examples:

Parse valid PNN names

Sashite::Pnn.parse("KING")    # => #<Pnn::Name value="KING">
Sashite::Pnn.parse("+queen")  # => #<Pnn::Name value="+queen">

Parameters:

  • pnn_string (String)

    the piece name string

Returns:

Raises:

  • (ArgumentError)

    if the name is invalid



49
50
51
# File 'lib/sashite/pnn.rb', line 49

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

.valid?(pnn_string) ⇒ Boolean

Check if a string is valid PNN notation

Examples:

Validate PNN strings

Sashite::Pnn.valid?("KING")     # => true
Sashite::Pnn.valid?("queen")    # => true
Sashite::Pnn.valid?("+ROOK")    # => true
Sashite::Pnn.valid?("-pawn")    # => true
Sashite::Pnn.valid?("King")     # => false (mixed case)
Sashite::Pnn.valid?("KING1")    # => false (contains digit)

Parameters:

  • pnn_string (String)

    the string to validate

Returns:

  • (Boolean)

    true if valid PNN, false otherwise



36
37
38
# File 'lib/sashite/pnn.rb', line 36

def self.valid?(pnn_string)
  Name.valid?(pnn_string)
end