Class: JustBackgammon::CombinedMove
- Inherits:
-
Object
- Object
- JustBackgammon::CombinedMove
- Extended by:
- Forwardable
- Defined in:
- lib/just_backgammon/combined_move.rb
Overview
CombinedMove
A combined move is a move where one piece moves multiple times.
Instance Attribute Summary collapse
-
#legs ⇒ Array<Move>
readonly
The legs of the combined move.
Instance Method Summary collapse
-
#empty? ⇒ Boolean
Checks if the combined move start with an empty point.
-
#from_point? ⇒ Boolean
Checks if the combined move start from a point.
-
#initialize(legs:) ⇒ CombinedMove
constructor
A new instance of CombinedMove.
-
#multi_leg? ⇒ Boolean
Checks if the combined move have pieces owned by the opponent.
-
#owned_by_opponent?(player_number) ⇒ Boolean
Checks if the combined move have pieces owned by the opponent.
Constructor Details
#initialize(legs:) ⇒ CombinedMove
A new instance of CombinedMove.
Example:
# Instantiates a new CombinedMove
JustBackgammon::CombinedMove.new({
legs: [move_a, move_b]
})
21 22 23 |
# File 'lib/just_backgammon/combined_move.rb', line 21 def initialize(legs:) @legs = legs end |
Instance Attribute Details
#legs ⇒ Array<Move> (readonly)
Returns the legs of the combined move.
26 27 28 |
# File 'lib/just_backgammon/combined_move.rb', line 26 def legs @legs end |
Instance Method Details
#empty? ⇒ Boolean
Checks if the combined move start with an empty point.
38 39 40 |
# File 'lib/just_backgammon/combined_move.rb', line 38 def empty? first_leg.empty? if first_leg end |
#from_point? ⇒ Boolean
Checks if the combined move start from a point.
31 32 33 |
# File 'lib/just_backgammon/combined_move.rb', line 31 def from_point? first_leg.instance_of?(JustBackgammon::Point) if first_leg end |
#multi_leg? ⇒ Boolean
Checks if the combined move have pieces owned by the opponent.
52 53 54 |
# File 'lib/just_backgammon/combined_move.rb', line 52 def multi_leg? legs.size > 2 end |
#owned_by_opponent?(player_number) ⇒ Boolean
Checks if the combined move have pieces owned by the opponent.
45 46 47 |
# File 'lib/just_backgammon/combined_move.rb', line 45 def owned_by_opponent?(player_number) first_leg.owned_by_opponent?(player_number) if first_leg end |