class Rypto::Hand

A individual hand of Krypto

@!attribute krypto_cards [r]

@return [Array(Fixnum, Fixnum, Fixnum, Fixnum, Fixnum)] the five krypto cards to evaluate

@!attribute target_card [r]

@return [Fixnum] the target card that the expression made from
        the five krypto_cards should equal

Attributes

krypto_cards[R]
target_card[R]

Public Class Methods

new(krypto_cards = nil, target_card = nil) click to toggle source

May be called with 0 or 2 arguments. If called with 0 arguments, will return a random deal from a full {Rypto::Deck}. If called with 2 arguments, will create a hand from the specified values.

@param krypto_cards [Array(Fixnum, Fixnum, Fixnum, Fixnum, Fixnum)]

Array of five krypto card values

@param target_card [Fixnum]

Target card value
# File lib/rypto.rb, line 27
def initialize(krypto_cards = nil, target_card = nil)
  if !krypto_cards.nil? and target_card.nil?
    raise ArgumentError, "Rypto::Hand#new must be called with 0 or 2 arguments"
  end

  if krypto_cards.nil?
    cards = Deck.new.deal_cards
    @krypto_cards = cards[0, 5]
    @target_card  = cards[5]
  else
    unless krypto_cards.is_a?(Array) and krypto_cards.size == 5
      raise ArgumentError, "Expected first argument to be an array of 5 integers"
    end

    tmp_deck = Deck.new
    krypto_cards.each {|card| tmp_deck.draw_card card}
    tmp_deck.draw_card target_card

    @krypto_cards = krypto_cards
    @target_card  = target_card
  end
end

Public Instance Methods

solve() click to toggle source

Get all possible solutions for the hand @return [Solution]

# File lib/rypto.rb, line 52
def solve
  BruteForceSolver.new(self).solve
end