Class: Sashite::Pan::Action::Pass

Inherits:
Object
  • Object
show all
Includes:
Singleton
Defined in:
lib/sashite/pan/action/pass.rb

Overview

Pass action class

Represents a pass action where the active player voluntarily ends their turn without performing any movement or transformation.

This class is implemented as a singleton since all pass actions are identical.

Format: “…”

Constant Summary collapse

TYPE =

Action type

:pass
NOTATION =

Pass notation constant

"..."
ERROR_INVALID_PASS =

Error messages

"Invalid pass notation: %s"

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.parse(pan_string) ⇒ Pass

Parse a pass notation string into a Pass instance

Examples:

Pass.parse("...")  # => #<Pass>

Parameters:

  • pan_string (String)

    pass notation string

Returns:

  • (Pass)

    the singleton pass action instance

Raises:

  • (ArgumentError)

    if the string is not a valid pass notation



48
49
50
51
52
# File 'lib/sashite/pan/action/pass.rb', line 48

def self.parse(pan_string)
  raise ::ArgumentError, format(ERROR_INVALID_PASS, pan_string) unless valid?(pan_string)

  instance
end

.valid?(pan_string) ⇒ Boolean

Check if a string represents a valid pass action

Examples:

Pass.valid?("...")       # => true
Pass.valid?("e2-e4")     # => false

Parameters:

  • pan_string (String)

    the string to validate

Returns:

  • (Boolean)

    true if valid pass notation



36
37
38
# File 'lib/sashite/pan/action/pass.rb', line 36

def self.valid?(pan_string)
  pan_string == NOTATION
end

Instance Method Details

#==(other) ⇒ Boolean Also known as: eql?

Custom equality comparison

Parameters:

  • other (Object)

    object to compare with

Returns:

  • (Boolean)

    true if other is also the Pass singleton



173
174
175
# File 'lib/sashite/pan/action/pass.rb', line 173

def ==(other)
  other.equal?(self)
end

#capture?Boolean

Check if this is a capture action

Returns:

  • (Boolean)

    false



116
117
118
# File 'lib/sashite/pan/action/pass.rb', line 116

def capture?
  false
end

#destinationnil

Get the destination coordinate

Returns:

  • (nil)

    pass actions have no destination



71
72
73
# File 'lib/sashite/pan/action/pass.rb', line 71

def destination
  nil
end

#drop?Boolean

Check if this is a drop action

Returns:

  • (Boolean)

    false



137
138
139
# File 'lib/sashite/pan/action/pass.rb', line 137

def drop?
  false
end

#drop_action?Boolean

Check if this is a drop action (drop or drop_capture)

Returns:

  • (Boolean)

    false



165
166
167
# File 'lib/sashite/pan/action/pass.rb', line 165

def drop_action?
  false
end

#drop_capture?Boolean

Check if this is a drop capture action

Returns:

  • (Boolean)

    false



144
145
146
# File 'lib/sashite/pan/action/pass.rb', line 144

def drop_capture?
  false
end

#hashInteger

Custom hash implementation for use in collections

Returns:

  • (Integer)

    hash value



183
184
185
# File 'lib/sashite/pan/action/pass.rb', line 183

def hash
  [self.class, TYPE].hash
end

#modify?Boolean

Check if this is a modify action

Returns:

  • (Boolean)

    false



151
152
153
# File 'lib/sashite/pan/action/pass.rb', line 151

def modify?
  false
end

#move?Boolean

Check if this is a move action

Returns:

  • (Boolean)

    false



109
110
111
# File 'lib/sashite/pan/action/pass.rb', line 109

def move?
  false
end

#movement?Boolean

Check if this is a movement action

Returns:

  • (Boolean)

    false



158
159
160
# File 'lib/sashite/pan/action/pass.rb', line 158

def movement?
  false
end

#pass?Boolean

Check if this is a pass action

Returns:

  • (Boolean)

    true



102
103
104
# File 'lib/sashite/pan/action/pass.rb', line 102

def pass?
  true
end

#piecenil

Get the piece identifier

Returns:

  • (nil)

    pass actions have no piece



78
79
80
# File 'lib/sashite/pan/action/pass.rb', line 78

def piece
  nil
end

#sourcenil

Get the source coordinate

Returns:

  • (nil)

    pass actions have no source



64
65
66
# File 'lib/sashite/pan/action/pass.rb', line 64

def source
  nil
end

#special?Boolean

Check if this is a special action

Returns:

  • (Boolean)

    false



123
124
125
# File 'lib/sashite/pan/action/pass.rb', line 123

def special?
  false
end

#static_capture?Boolean

Check if this is a static capture action

Returns:

  • (Boolean)

    false



130
131
132
# File 'lib/sashite/pan/action/pass.rb', line 130

def static_capture?
  false
end

#to_sString

Convert the action to its PAN string representation

Examples:

action.to_s  # => "..."

Returns:

  • (String)

    pass notation “…”



95
96
97
# File 'lib/sashite/pan/action/pass.rb', line 95

def to_s
  NOTATION
end

#transformationnil

Get the transformation piece

Returns:

  • (nil)

    pass actions have no transformation



85
86
87
# File 'lib/sashite/pan/action/pass.rb', line 85

def transformation
  nil
end

#typeSymbol

Get the action type

Returns:

  • (Symbol)

    :pass



57
58
59
# File 'lib/sashite/pan/action/pass.rb', line 57

def type
  TYPE
end