Module: Sashite::Pnn

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

Overview

PNN (Piece Name Notation) implementation for Ruby

Provides style-aware ASCII-based format for representing pieces in abstract strategy board games. PNN extends PIN by adding derivation markers that distinguish pieces by their style origin, enabling cross-style game scenarios and piece origin tracking.

Format: [<state>]<letter>

  • State modifier: “+” (enhanced), “-” (diminished), or none (normal)

  • Letter: A-Z (first player), a-z (second player)

  • Derivation marker: “‘” (foreign style), or none (native style)

Examples:

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

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

Defined Under Namespace

Classes: Piece

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 type=:K side=:first state=:normal native=true>
Sashite::Pnn.parse("+R'")   # => #<Pnn::Piece type=:R side=:first state=:enhanced native=false>
Sashite::Pnn.parse("-p")    # => #<Pnn::Piece type=:P side=:second state=:diminished native=true>

Parameters:

  • pnn_string (String)

    PNN notation string

Returns:

Raises:

  • (ArgumentError)

    if the PNN string is invalid



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

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

.piece(type, side, state = Sashite::Pin::Piece::NORMAL_STATE, native = Piece::NATIVE) ⇒ Pnn::Piece

Create a new piece instance

Examples:

Sashite::Pnn.piece(:K, :first, :normal, true)      # => #<Pnn::Piece type=:K side=:first state=:normal native=true>
Sashite::Pnn.piece(:R, :first, :enhanced, false)   # => #<Pnn::Piece type=:R side=:first state=:enhanced native=false>
Sashite::Pnn.piece(:P, :second, :diminished, true) # => #<Pnn::Piece type=:P side=:second state=:diminished native=true>

Parameters:

  • type (Symbol)

    piece type (:A to :Z)

  • side (Symbol)

    player side (:first or :second)

  • state (Symbol) (defaults to: Sashite::Pin::Piece::NORMAL_STATE)

    piece state (:normal, :enhanced, or :diminished)

  • native (Boolean) (defaults to: Piece::NATIVE)

    style derivation (true for native, false for foreign)

Returns:

Raises:

  • (ArgumentError)

    if parameters are invalid



65
66
67
# File 'lib/sashite/pnn.rb', line 65

def self.piece(type, side, state = Sashite::Pin::Piece::NORMAL_STATE, native = Piece::NATIVE)
  Piece.new(type, side, state, native)
end

.valid?(pnn_string) ⇒ Boolean

Check if a string is a valid PNN notation

Examples:

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

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)
  Piece.valid?(pnn_string)
end