Module: FEEN::Parser

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

Overview

The parser module.

Defined Under Namespace

Modules: InHand, Turn Classes: Shape, Square

Class Method Summary collapse

Class Method Details

.call(feen) ⇒ Hash

Parse a FEEN string into position params.

Examples:

Parse a classic Tsume Shogi problem

call("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.



30
31
32
33
34
35
36
37
38
39
# File 'lib/feen/parser.rb', line 30

def self.call(feen)
  square_str, side_id_str, in_hand_str = feen.split

  {
    in_hand: InHand.parse(in_hand_str),
    shape:   Shape.new(square_str).to_a,
    side_id: Turn.parse(side_id_str),
    square:  Square.new(square_str).to_h
  }
end