Drop.rb

Version Yard documentation Ruby License

DROP (Droppable Reserve Operations Placement) support for the Ruby language.

What is DROP?

DROP (Droppable Reserve Operations Placement) is a simple, standardized notation for representing piece reserve locations in board games where captured pieces can be held and/or placed onto the board. This applies to games like shōgi, crazyhouse, go, and other games featuring capture-and-drop mechanics.

This gem implements the DROP Specification v1.0.0, providing a Ruby interface for working with reserve locations through a functional and minimalist API.

Installation

# In your Gemfile
gem "sashite-drop"

Or install manually:

gem install sashite-drop

DROP Format

DROP uses a single character to represent all off-board reserve locations:

Reserve Location: * (asterisk)

  • Unicode: U+002A
  • ASCII: 42
  • UTF-8: 0x2A

Basic Usage

Basic Usage

The primary functionality is checking if a location represents the reserve:

require "sashite/drop"

# Check if a string represents the reserve location
Sashite::Drop.reserve?("*")    # => true
Sashite::Drop.reserve?("a1")   # => false
Sashite::Drop.reserve?("**")   # => false
Sashite::Drop.reserve?("")     # => false

# Alias for convenience
Drop = Sashite::Drop
Drop.reserve?("*") # => true

String Representation

# Get the canonical DROP representation
Sashite::Drop.to_s # => "*"

Usage Examples

Movement Notation

# Representing moves with DROP notation
source = "*"           # From reserve
destination = "e4"     # To board position (using CELL coordinates)

# Check if move involves reserve
Sashite::Drop.reserve?(source)      # => true (drop move)
Sashite::Drop.reserve?(destination) # => false (board position)

Game Context Examples

Shōgi

# Reserve operations
reserve = "*"
board_position = "5e"

# Drop move: place piece from reserve to board
puts "Dropping piece from reserve to #{board_position}" if Sashite::Drop.reserve?(reserve)

Crazyhouse

# Capture to reserve
captured_position = "e4"
reserve = "*"

# Capture move: piece goes to reserve
puts "Piece captured to reserve from #{captured_position}" if Sashite::Drop.reserve?(reserve)

Integration with CELL

DROP complements the CELL specification for complete location coverage:

# Combined location validation
def valid_location?(location)
  Sashite::Drop.reserve?(location) || Cell.valid?(location)
end

valid_location?("*")   # => true (reserve)
valid_location?("a1")  # => true (board position)
valid_location?("xx")  # => false (invalid)

API Reference

Module Methods

  • Sashite::Drop.reserve?(string) - Check if string represents the reserve location
  • Sashite::Drop.to_s - Get the canonical DROP representation ("*")

Constants

  • Sashite::Drop::RESERVE - The reserve location character ("*")

Properties of DROP

  • Minimalist: Uses only a single character (*) for all reserve operations
  • Universal: Works across different board game types and rule systems
  • Complementary: Designed to work alongside CELL coordinates for complete game notation
  • Functional: Provides a clean, stateless API for reserve location operations

Constraints

  • DROP represents only off-board reserve locations
  • The asterisk (*) is the only valid DROP character
  • Context determines the specific meaning (player's reserve, captured pieces, stone supply, etc.)
  • For on-board positions, use CELL coordinates instead

Examples in Different Games

Shogi

# Piece in hand (reserve)
reserve = "*"
Sashite::Drop.reserve?(reserve) # => true

# Drop to board
destination = "5e"
puts "#{reserve} → #{destination}" # "* → 5e"

Go

# Stone supply (reserve)
supply = "*"
Sashite::Drop.reserve?(supply) # => true

# Place stone
position = "dd"
puts "#{supply} → #{position}" # "* → dd"

Crazyhouse

# Captured piece reserve
reserve = "*"
Sashite::Drop.reserve?(reserve) # => true

# Drop piece
square = "e4"
puts "#{reserve} → #{square}" # "* → e4"

Documentation

License

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

About Sashité

This project is maintained by Sashité — promoting chess variants and sharing the beauty of Chinese, Japanese, and Western chess cultures.