Class: JustBackgammon::CombinedMove

Inherits:
Object
  • Object
show all
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

Instance Method Summary collapse

Constructor Details

#initialize(legs:) ⇒ CombinedMove

A new instance of CombinedMove.

Example:

# Instantiates a new CombinedMove
JustBackgammon::CombinedMove.new({
  legs: [move_a, move_b]
})

Parameters:

  • legs (Array<Move>)

    The legs of the combined move.



21
22
23
# File 'lib/just_backgammon/combined_move.rb', line 21

def initialize(legs:)
  @legs = legs
end

Instance Attribute Details

#legsArray<Move> (readonly)

Returns the legs of the combined move.

Returns:

  • (Array<Move>)

    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

Does the combined move start with an empty point?

Returns:

  • (Boolean)


40
41
42
# File 'lib/just_backgammon/combined_move.rb', line 40

def empty?
  first_leg.empty? if first_leg
end

#from_point?Boolean

Does the combined move start from a point?

Returns:

  • (Boolean)


33
34
35
# File 'lib/just_backgammon/combined_move.rb', line 33

def from_point?
  first_leg.instance_of?(JustBackgammon::Point) if first_leg
end

#owned_by_opponent?(player_number) ⇒ Boolean

Does the combined move have pieces owned by the opponent?

Returns:

  • (Boolean)


47
48
49
# File 'lib/just_backgammon/combined_move.rb', line 47

def owned_by_opponent?(player_number)
  first_leg.owned_by_opponent?(player_number) if first_leg
end