class JustBackgammon::PointSet
PointSet
¶ ↑
A collection of points.
Attributes
points[R]
@return [Array<Point>] all the points in the set
Public Class Methods
new(points:)
click to toggle source
Public Instance Methods
as_json()
click to toggle source
A hashed serialized representation of the bar.
@return [Hash]
# File lib/just_backgammon/point_set.rb, line 77 def as_json points.map(&:as_json) end
destinations(from, dice, player_number)
click to toggle source
Finds all destinations points from a point with a dice roll for the specified player.
@return [PointSet]
# File lib/just_backgammon/point_set.rb, line 68 def destinations(from, dice, player_number) in_range = dice.map { |d| destination(from, d, player_number) }.compact possible = in_range.select { |p| p.empty? || p.owned_by_player?(player_number) || p.blot? } self.class.new(points: possible) end
find_by_number(number)
click to toggle source
Finds a point with the matching number.
@return [Point]
# File lib/just_backgammon/point_set.rb, line 38 def find_by_number(number) points.find { |p| p.number == number } end
not_home(player_number)
click to toggle source
Finds all points with pieces that are not yet home for the specified player.
@return [PointSet]
# File lib/just_backgammon/point_set.rb, line 45 def not_home(player_number) not_home_points = points.select { |p| p.owned_by_player?(player_number) && !p.home?(player_number) } self.class.new(points: not_home_points) end
owned_by_player(player_number)
click to toggle source
Finds all points owned by the specified player.
@return [PointSet]
# File lib/just_backgammon/point_set.rb, line 60 def owned_by_player(player_number) owned = @points.select { |p| p.owned_by_player?(player_number) } self.class.new(points: owned) end
some_pieces_not_home?(player_number)
click to toggle source
Checks if any pieces are not yet home for the specified player.
@return [Boolean]
# File lib/just_backgammon/point_set.rb, line 53 def some_pieces_not_home?(player_number) not_home(player_number).any? end