Module: Sashite::Feen

Defined in:
lib/sashite/feen.rb,
lib/sashite/feen/error.rb,
lib/sashite/feen/hands.rb,
lib/sashite/feen/dumper.rb,
lib/sashite/feen/parser.rb,
lib/sashite/feen/styles.rb,
lib/sashite/feen/position.rb,
lib/sashite/feen/placement.rb,
lib/sashite/feen/dumper/style_turn.rb,
lib/sashite/feen/parser/style_turn.rb,
lib/sashite/feen/dumper/pieces_in_hand.rb,
lib/sashite/feen/parser/pieces_in_hand.rb,
lib/sashite/feen/dumper/piece_placement.rb,
lib/sashite/feen/parser/piece_placement.rb

Overview

FEEN (Forsyth–Edwards Enhanced Notation) module provides parsing and dumping functionality for board game positions.

FEEN is a universal, rule-agnostic notation for representing board game positions. It extends traditional FEN to support multiple game systems, cross-style games, multi-dimensional boards, and captured pieces.

A FEEN string consists of three space-separated fields:

  1. Piece placement: Board configuration using EPIN notation

  2. Pieces in hand: Captured pieces held by each player

  3. Style-turn: Game styles and active player

Defined Under Namespace

Modules: Dumper, Parser Classes: Error, Hands, Placement, Position, Styles

Class Method Summary collapse

Class Method Details

.dump(position) ⇒ String

Dump a Position object into its canonical FEEN string representation.

Generates a deterministic FEEN string from a position object. The same position will always produce the same canonical string, ensuring position equality can be tested via string comparison.

Examples:

Dump a position to FEEN

feen_string = Sashite::Feen.dump(position)
# => "+rnbq+kbn+r/+p+p+p+p+p+p+p+p/8/8/8/8/+P+P+P+P+P+P+P+P/+RNBQ+KBN+R / C/c"

Round-trip parsing and dumping

original = "+rnbq+kbn+r/+p+p+p+p+p+p+p+p/8/8/8/8/+P+P+P+P+P+P+P+P/+RNBQ+KBN+R / C/c"
position = Sashite::Feen.parse(original)
Sashite::Feen.dump(position) == original  # => true

Parameters:

  • position (Position)

    A position object with placement, hands, and styles

Returns:

  • (String)

    Canonical FEEN notation string



38
39
40
# File 'lib/sashite/feen.rb', line 38

def self.dump(position)
  Dumper.dump(position)
end

.parse(string) ⇒ Position

Parse a FEEN string into an immutable Position object.

This method parses the three FEEN fields and constructs an immutable position object with placement, hands, and styles components.

Examples:

Parse a chess starting position

position = Sashite::Feen.parse("+rnbq+kbn+r/+p+p+p+p+p+p+p+p/8/8/8/8/+P+P+P+P+P+P+P+P/+RNBQ+KBN+R / C/c")
position.placement  # => Placement object (board configuration)
position.hands      # => Hands object (pieces in hand)
position.styles     # => Styles object (style-turn information)

Parse a shogi position with captured pieces

position = Sashite::Feen.parse("lnsgkgsnl/1r5b1/ppppppppp/9/9/9/PPPPPPPPP/1B5R1/LNSGKGSNL P/p S/s")

Parameters:

  • string (String)

    A FEEN notation string with three space-separated fields

Returns:

  • (Position)

    Immutable position object

Raises:



63
64
65
# File 'lib/sashite/feen.rb', line 63

def self.parse(string)
  Parser.parse(string)
end