Module: FEEN

Defined in:
lib/feen.rb,
lib/feen/dumper.rb,
lib/feen/parser.rb,
lib/feen/dumper/turn.rb,
lib/feen/parser/turn.rb,
lib/feen/parser/shape.rb,
lib/feen/dumper/square.rb,
lib/feen/parser/square.rb,
lib/feen/dumper/in_hand.rb,
lib/feen/parser/in_hand.rb

Overview

This module provides a Ruby interface for data serialization and deserialization in FEEN format.

Defined Under Namespace

Modules: Dumper, Parser

Class Method Summary collapse

Class Method Details

.dump(in_hand:, shape:, side_id:, square:) ⇒ String

Dumps position params into a FEEN string.

Examples:

Dump a classic Tsume Shogi problem

dump(
  "in_hand": %w[S r r b g g g g s n n n n p p p p p p p p p p p p p p p p p],
  "shape": [9, 9],
  "side_id": 0,
  "square": {
     3 => "s",
     4 => "k",
     5 => "s",
    22 => "+P",
    43 => "+B"
  }
)
# => "3,s,k,s,3/9/4,+P,4/9/7,+B,1/9/9/9/9 0 S,b,g,g,g,g,n,n,n,n,p,p,p,p,p,p,p,p,p,p,p,p,p,p,p,p,p,r,r,s"

Parameters:

  • in_hand (Array)

    The list of pieces in hand.

  • shape (Array)

    The shape of the board.

  • side_id (Integer)

    The identifier of the player who must play.

  • square (Hash)

    The index of each piece on the board.

Returns:

  • (String)

    The FEEN string representing the position.



34
35
36
37
38
39
40
41
# File 'lib/feen.rb', line 34

def self.dump(in_hand:, shape:, side_id:, square:)
  Dumper.call(
    in_hand:,
    shape:,
    side_id:,
    square:
  )
end

.parse(feen) ⇒ Hash

Parses a FEEN string into position params.

Examples:

Parse a classic Tsume Shogi problem

parse("3,s,k,s,3/9/4,+P,4/9/7,+B,1/9/9/9/9 0 S,b,g,g,g,g,n,n,n,n,p,p,p,p,p,p,p,p,p,p,p,p,p,p,p,p,p,r,r,s")
# => {
#      "in_hand": ["S", "b", "g", "g", "g", "g", "n", "n", "n", "n", "p", "p", "p", "p", "p", "p", "p", "p", "p", "p", "p", "p", "p", "p", "p", "p", "p", "r", "r", "s"],
#      "shape": [9, 9],
#      "side_id": 0,
#      "square": {
#         3 => "s",
#         4 => "k",
#         5 => "s",
#        22 => "+P",
#        43 => "+B"
#      }

Parameters:

  • feen (String)

    The FEEN string representing a position.

Returns:

  • (Hash)

    The position params representing the position.



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

def self.parse(feen)
  Parser.call(feen)
end