GithubHelp home page GithubHelp logo

sashite / pmn.cr Goto Github PK

View Code? Open in Web Editor NEW
0.0 2.0 0.0 6 KB

A Crystal interface for data serialization in PMN format.

Home Page: https://developer.sashite.com/specs/portable-move-notation

License: MIT License

Crystal 100.00%
chess data-serialization shogi xiangqi pmn-format

pmn.cr's Introduction

Portable Move Notation

Build Status

A Crystal interface for data serialization in PMN format.

Installation

  1. Add the dependency to your shard.yml:

    dependencies:
      pmn:
        github: sashite/pmn.cr
  2. Run shards install

Usage

Working with PMN can be very simple, for example:

require "pmn"

# Emit a PMN string

some_moves = [
  [52, 36, "", nil],
  [12, 28, "", nil],
  [53, 37, "", nil]
]

PMN.dump(*some_moves) # => "52,36,♙.12,28,♟.53,37,♙"

# Parse a PMN string

PMN.parse("52,36,♙.12,28,♟.53,37,♙") # => [[52, 36, "♙", nil], [12, 28, "♟", nil], [53, 37, "♙", nil]]

Examples

# Black castles on king-side

PMN.dump([60, 62, "", nil, 63, 61, "", nil]) # => "60,62,♔;63,61,♖"
PMN.parse("60,62,♔;63,61,♖") # => [[60, 62, "♔", nil, 63, 61, "♖", nil]]

# Promoting a chess pawn into a knight

PMN.dump([12, 4, "", nil]) # => "12,4,♘"
PMN.parse("12,4,♘") # => [[12, 4, "♘", nil]]

# Capturing a rook and promoting a shogi pawn

PMN.dump([33, 24, "+P", "R"]) # => "33,24,+P,R"
PMN.parse("33,24,+P,R") # => [[33, 24, "+P", "R"]]

# Dropping a shogi pawn

PMN.dump([nil, 42, "P", nil]) # => "*,42,P"
PMN.parse("*,42,P") # => [[nil, 42, "P", nil]]

# Capturing a white chess pawn en passant

PMN.dump([48, 32, "", nil], [33, 32, "", nil, 32, 40, "", nil]) # => "48,32,♙.33,32,♟;32,40,♟"
PMN.parse('48,32,♙.33,32,♟;32,40,♟') # => [[48, 32, "♙", nil], [33, 32, "♟", nil, 32, 40, "♟", nil]]

License

This library is available as open source under the terms of the MIT License.

About Sashite

This library is maintained by Sashite.

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

pmn.cr'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.