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

Checks if the combined move start with an empty point.

Returns:

  • (Boolean)


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.

Returns:

  • (Boolean)


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.

Returns:

  • (Boolean)


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.

Returns:

  • (Boolean)


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