Skip to content

sashite/feen.rb

Repository files navigation

Feen.rb

Version Yard documentation CI RuboCop License

FEEN (Forsyth–Edwards Expanded Notation) support for the Ruby language.

Overview

This is an implementation of FEEN, a flexible and minimalist format for describing chess variant positions.

Installation

Add this line to your application's Gemfile:

gem "feen", ">= 5.0.0.beta1"

And then execute:

bundle install

Or install it yourself as:

gem install feen --pre

Usage

Serialization

A position can be serialized by filling in these fields:

  • Board shape: An array of integers. For instance, it would be [10, 9] for a Xiangqi board. Or it would be [8, 8] for a Chess board.
  • Piece placement: Describes the placement of pieces on the board with a hash that references each piece on the board.
  • Side to move: A char that indicates who moves next. In chess, "w" would mean that White can play a move.

Example

From a classic Tsume Shogi problem:

require "feen"

Feen.dump(
  board_shape:     [9, 9],
  side_to_move:    "s",
  piece_placement: {
    3  => "s",
    4  => "k",
    5  => "s",
    22 => "+P",
    43 => "+B"
  }
)
# => "3sks3/9/4+P4/9/7+B1/9/9/9/9 s"

Deserialization

Serialized positions can be converted back to fields.

Example

require "feen"

Feen.parse("3sks3/9/4+P4/9/7+B1/9/9/9/9 s")
# {:board_shape=>[9, 9],
#  :piece_placement=>{3=>"s", 4=>"k", 5=>"s", 22=>"+P", 43=>"+B"},
#  :side_to_move=>"s"}

License

The code is available as open source under the terms of the MIT License.

About Sashité

This gem is maintained by Sashité.

With some lines of code, let's share the beauty of Chinese, Japanese and Western cultures through the game of chess!