Portable Action Notation
A Ruby interface for data serialization in PAN format.
Installation
Add this line to your application's Gemfile:
gem "sashite-pan"
And then execute:
bundle
Or install it yourself as:
gem install sashite-pan
Usage
Working with PAN can be very simple, for example:
require "sashite/pan"
# Emit a PAN string
actions = [
[52, 36, "♙"]
]
Sashite::PAN.dump(*actions) # => "52,36,♙"
# Parse a PAN string
Sashite::PAN.parse("52,36,♙") # => [[52, 36, "♙", nil]]
Example
Promoting a chess pawn into a knight
Sashite::PAN.dump([12, 4, "♘"]) # => "12,4,♘"
Sashite::PAN.parse("12,4,♘") # => [[12, 4, "♘", nil]]
Capturing a rook and promoting a shogi pawn
Sashite::PAN.dump([33, 24, "+P", "R"]) # => "33,24,+P,R"
Sashite::PAN.parse("33,24,+P,R") # => [[33, 24, "+P", "R"]]
Dropping a shogi pawn
Sashite::PAN.dump([nil, 42, "P"]) # => "*,42,P"
Sashite::PAN.parse("*,42,P") # => [[nil, 42, "P", nil]]
In the context of a game with several possible actions per turn, like in
Western chess, more than one action could be consider like a move, and joined
thanks to the portable_move_notation
gem.
Black castles on king-side
Sashite::PAN.dump([60, 62, "♔"], [63, 61, "♖"]) # => "60,62,♔;63,61,♖"
Sashite::PAN.parse("60,62,♔;63,61,♖") # => [[60, 62, "♔", nil], [63, 61, "♖", nil]]
Capturing a white chess pawn en passant
Sashite::PAN.dump([33, 32, "♟"], [32, 40, "♟"]) # => "33,32,♟;32,40,♟"
Sashite::PAN.parse("33,32,♟;32,40,♟") # => [[33, 32, "♟", nil], [32, 40, "♟", nil]]
License
The code is available as open source under the terms of the MIT License.
About Sashite
This gem 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!