Module: Sashite::Pin

Defined in:
lib/sashite/pin.rb,
lib/sashite/pin/identifier.rb

Overview

PIN (Piece Identifier Notation) implementation for Ruby

Provides ASCII-based format for representing pieces in abstract strategy board games. PIN translates piece attributes from the Game Protocol into a compact, portable notation system.

Format: [<state>]<letter>

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

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

Examples:

"K"  - First player king (normal state)
"k"  - Second player king (normal state)
"+R" - First player rook (enhanced state)
"-p" - Second player pawn (diminished state)

Defined Under Namespace

Classes: Identifier

Class Method Summary collapse

Class Method Details

.identifier(type, side, state) ⇒ Pin::Identifier

Create a new identifier instance

Examples:

Sashite::Pin.identifier(:K, :first, :normal)     # => #<Pin::Identifier type=:K side=:first state=:normal>
Sashite::Pin.identifier(:R, :first, :enhanced)   # => #<Pin::Identifier type=:R side=:first state=:enhanced>
Sashite::Pin.identifier(:P, :second, :diminished) # => #<Pin::Identifier type=:P side=:second state=:diminished>

Parameters:

  • type (Symbol)

    piece type (:A to :Z)

  • side (Symbol)

    player side (:first or :second)

  • state (Symbol)

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

Returns:

Raises:

  • (ArgumentError)

    if parameters are invalid



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

def self.identifier(type, side, state)
  Identifier.new(type, side, state)
end

.parse(pin_string) ⇒ Pin::Identifier

Parse a PIN string into an Identifier object

Examples:

Sashite::Pin.parse("K")     # => #<Pin::Identifier type=:K side=:first state=:normal>
Sashite::Pin.parse("+R")    # => #<Pin::Identifier type=:R side=:first state=:enhanced>
Sashite::Pin.parse("-p")    # => #<Pin::Identifier type=:P side=:second state=:diminished>

Parameters:

  • pin_string (String)

    PIN notation string

Returns:

Raises:

  • (ArgumentError)

    if the PIN string is invalid



47
48
49
# File 'lib/sashite/pin.rb', line 47

def self.parse(pin_string)
  Identifier.parse(pin_string)
end

.valid?(pin_string) ⇒ Boolean

Check if a string is a valid PIN notation

Examples:

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

Parameters:

  • pin_string (String)

    The string to validate

Returns:

  • (Boolean)

    true if valid PIN, false otherwise



34
35
36
# File 'lib/sashite/pin.rb', line 34

def self.valid?(pin_string)
  Identifier.valid?(pin_string)
end