Class: Sashite::Pan::Action::StaticCapture
- Inherits:
-
Object
- Object
- Sashite::Pan::Action::StaticCapture
- Defined in:
- lib/sashite/pan/action/static_capture.rb
Overview
Static capture action class
Handles capture actions without movement - removing a piece from the board without the capturing piece moving.
Format: <square> Examples: “d4”, “+e5”
Constant Summary collapse
- TYPE =
Action type
:static_capture- OPERATOR =
Operator constant
"+"- ERROR_INVALID_STATIC_CAPTURE =
Error messages
"Invalid static capture notation: %s"- ERROR_INVALID_SQUARE =
"Invalid square coordinate: %s"
Instance Attribute Summary collapse
-
#destination ⇒ String
readonly
Destination CELL coordinate (square where piece is captured).
Class Method Summary collapse
-
.parse(pan_string) ⇒ StaticCapture
Parse a static capture notation string into a StaticCapture instance.
-
.valid?(pan_string) ⇒ Boolean
Check if a string represents a valid static capture action.
Instance Method Summary collapse
-
#==(other) ⇒ Boolean
(also: #eql?)
Custom equality comparison.
-
#capture? ⇒ Boolean
Check if this is a capture action.
-
#drop? ⇒ Boolean
Check if this is a drop action.
-
#drop_action? ⇒ Boolean
Check if this is a drop action (drop or drop_capture).
-
#drop_capture? ⇒ Boolean
Check if this is a drop capture action.
-
#hash ⇒ Integer
Custom hash implementation for use in collections.
-
#initialize(square) ⇒ StaticCapture
constructor
Create a new static capture action instance.
-
#modify? ⇒ Boolean
Check if this is a modify action.
-
#move? ⇒ Boolean
Check if this is a move action.
-
#movement? ⇒ Boolean
Check if this is a movement action.
-
#pass? ⇒ Boolean
Check if this is a pass action.
-
#piece ⇒ nil
Get the piece identifier.
-
#source ⇒ nil
Get the source coordinate.
-
#special? ⇒ Boolean
Check if this is a special action.
-
#static_capture? ⇒ Boolean
Check if this is a static capture action.
-
#to_s ⇒ String
Convert the action to its PAN string representation.
-
#transformation ⇒ nil
Get the transformation piece.
-
#type ⇒ Symbol
Get the action type.
Constructor Details
#initialize(square) ⇒ StaticCapture
Create a new static capture action instance
69 70 71 72 73 74 75 |
# File 'lib/sashite/pan/action/static_capture.rb', line 69 def initialize(square) raise ::ArgumentError, format(ERROR_INVALID_SQUARE, square) unless ::Sashite::Cell.valid?(square) @destination = square freeze end |
Instance Attribute Details
#destination ⇒ String (readonly)
Returns destination CELL coordinate (square where piece is captured).
27 28 29 |
# File 'lib/sashite/pan/action/static_capture.rb', line 27 def destination @destination end |
Class Method Details
.parse(pan_string) ⇒ StaticCapture
Parse a static capture notation string into a StaticCapture instance
55 56 57 58 59 60 |
# File 'lib/sashite/pan/action/static_capture.rb', line 55 def self.parse(pan_string) raise ::ArgumentError, format(ERROR_INVALID_STATIC_CAPTURE, pan_string) unless valid?(pan_string) square = pan_string[1..] new(square) end |
.valid?(pan_string) ⇒ Boolean
Check if a string represents a valid static capture action
38 39 40 41 42 43 44 45 |
# File 'lib/sashite/pan/action/static_capture.rb', line 38 def self.valid?(pan_string) return false unless pan_string.is_a?(::String) return false unless pan_string.start_with?(OPERATOR) return false if pan_string.length < 2 square = pan_string[1..] ::Sashite::Cell.valid?(square) end |
Instance Method Details
#==(other) ⇒ Boolean Also known as: eql?
Custom equality comparison
189 190 191 192 193 |
# File 'lib/sashite/pan/action/static_capture.rb', line 189 def ==(other) return false unless other.is_a?(self.class) destination == other.destination end |
#capture? ⇒ Boolean
Check if this is a capture action
132 133 134 |
# File 'lib/sashite/pan/action/static_capture.rb', line 132 def capture? false end |
#drop? ⇒ Boolean
Check if this is a drop action
153 154 155 |
# File 'lib/sashite/pan/action/static_capture.rb', line 153 def drop? false end |
#drop_action? ⇒ Boolean
Check if this is a drop action (drop or drop_capture)
181 182 183 |
# File 'lib/sashite/pan/action/static_capture.rb', line 181 def drop_action? false end |
#drop_capture? ⇒ Boolean
Check if this is a drop capture action
160 161 162 |
# File 'lib/sashite/pan/action/static_capture.rb', line 160 def drop_capture? false end |
#hash ⇒ Integer
Custom hash implementation for use in collections
201 202 203 |
# File 'lib/sashite/pan/action/static_capture.rb', line 201 def hash [self.class, destination].hash end |
#modify? ⇒ Boolean
Check if this is a modify action
167 168 169 |
# File 'lib/sashite/pan/action/static_capture.rb', line 167 def modify? false end |
#move? ⇒ Boolean
Check if this is a move action
125 126 127 |
# File 'lib/sashite/pan/action/static_capture.rb', line 125 def move? false end |
#movement? ⇒ Boolean
Check if this is a movement action
174 175 176 |
# File 'lib/sashite/pan/action/static_capture.rb', line 174 def movement? false end |
#pass? ⇒ Boolean
Check if this is a pass action
118 119 120 |
# File 'lib/sashite/pan/action/static_capture.rb', line 118 def pass? false end |
#piece ⇒ nil
Get the piece identifier
94 95 96 |
# File 'lib/sashite/pan/action/static_capture.rb', line 94 def piece nil end |
#source ⇒ nil
Get the source coordinate
87 88 89 |
# File 'lib/sashite/pan/action/static_capture.rb', line 87 def source nil end |
#special? ⇒ Boolean
Check if this is a special action
139 140 141 |
# File 'lib/sashite/pan/action/static_capture.rb', line 139 def special? false end |
#static_capture? ⇒ Boolean
Check if this is a static capture action
146 147 148 |
# File 'lib/sashite/pan/action/static_capture.rb', line 146 def static_capture? true end |
#to_s ⇒ String
Convert the action to its PAN string representation
111 112 113 |
# File 'lib/sashite/pan/action/static_capture.rb', line 111 def to_s "#{OPERATOR}#{destination}" end |
#transformation ⇒ nil
Get the transformation piece
101 102 103 |
# File 'lib/sashite/pan/action/static_capture.rb', line 101 def transformation nil end |
#type ⇒ Symbol
Get the action type
80 81 82 |
# File 'lib/sashite/pan/action/static_capture.rb', line 80 def type TYPE end |