Module: PortableMoveNotation

Defined in:
lib/portable_move_notation.rb,
lib/portable_move_notation/move.rb,
lib/portable_move_notation/action.rb

Overview

Portable Move Notation module

PMN v1.0.0 implementation providing rule-agnostic representation of state-changing actions in abstract strategy board games.

This implementation follows the PMN v1.0.0 specification which uses an array-of-arrays format: each action is a 4-element array containing [source_square, destination_square, piece_name, captured_piece].

Defined Under Namespace

Classes: Action, Move

Constant Summary collapse

SCHEMA_URL =

Schema URL for validation

"https://sashite.dev/schemas/pmn/1.0.0/schema.json"

Class Method Summary collapse

Class Method Details

.generate(move) ⇒ String

Generate PMN JSON from a Move object

Parameters:

  • move (Move)

    Move object to serialize

Returns:

  • (String)

    JSON string in PMN v1.0.0 format



40
41
42
# File 'lib/portable_move_notation.rb', line 40

def self.generate(move)
  move.to_json
end

.parse(json_string) ⇒ Move

Parse PMN JSON string into a Move object

Parameters:

  • json_string (String)

    JSON string containing PMN data

Returns:

  • (Move)

    Parsed move object

Raises:

  • (JSON::ParserError)

    If JSON is invalid

  • (ArgumentError)

    If PMN structure is invalid



32
33
34
# File 'lib/portable_move_notation.rb', line 32

def self.parse(json_string)
  Move.from_json(json_string)
end

.valid?(pmn_data) ⇒ Boolean

Quick validation method for PMN data

Parameters:

  • pmn_data (Array)

    Array of action arrays to validate

Returns:

  • (Boolean)

    true if data conforms to PMN v1.0.0 format



22
23
24
# File 'lib/portable_move_notation.rb', line 22

def self.valid?(pmn_data)
  Move.valid?(pmn_data)
end