Code Monkey home page Code Monkey logo

feen.rb's Introduction

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!

feen.rb's People

Contributors

cyril avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.