Sha256: 995afa87b196a65a4372068d8da13732f5798d7fc38dbfde202948cb74a75465
Contents?: true
Size: 919 Bytes
Versions: 1
Compression:
Stored size: 919 Bytes
Contents
require 'yahtzee' require 'dice' # I will need some kind of UI, Yahtzee::Probability aids in # the decisions an AI will have to make based on their score # card, the dice, and the probability vs possible score module Yahtzee::Probability module_function def small_straight(dice, rolls_left) possibilities = dice.sort.each_cons(3).select do |a,b,c| a+1==b && b+1==c end.flatten straight_possibility_from(dice, possibilities, rolls_left) end def large_straight(dice, rolls_left) possibilities = dice.sort.each_cons(4).select do |a,b,c,d| a+1==b && b+1==c && c+1==d end.flatten straight_possibility_from(dice, possibilities, rolls_left) end private def self.straight_possibility_from(dice, possibilities, rolls_left) dice_left = (dice-possibilities).count possible_faces = dice_left*Yahtzee::Dice::DIE_FACES rolls_left.to_f/possible_faces.to_f end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
functional-yahtzee-0.0.3 | lib/probability.rb |