# File 'lib/yahtzee.rb', line 172defcalculate_dicedice,jokercats={:aces=>0,:twos=>0,:threes=>0,:fours=>0,:fives=>0,:sixes=>0,:three_of_a_kind=>0,:four_of_a_kind=>0,:full_house=>0,:small_straight=>0,:large_straight=>0,:yahtzee=>0,:chance=>0}# upper section
dice.eachdo|i|caseiwhen1cats[:aces]+=1when2cats[:twos]+=2when3cats[:threes]+=3when4cats[:fours]+=4when5cats[:fives]+=5when6cats[:sixes]+=6endend# lower section
freq=[0,0,0,0,0,0]sum=0dice.size.timesdo|i|sum+=dice[i]freq[dice[i]-1]+=1endsfreq=freq.sort.reversemax=sfreq[0]# number of most frequent dice
smax=sfreq[1]# number of second most frequent
small=falselarge=falsessum=0sdice=dice.sort.uniqsdice.size.timesdo|i|ssum+=sdice[i]endlarge=trueifsdice.length>=5and(ssum==15orssum==20)small=trueifsdice.length>=4and(ssum==10orssum==14orssum==18)orlargecats[:three_of_a_kind]=sumif(max>=3||joker)cats[:four_of_a_kind]=sumif(max>=4||joker)cats[:full_house]=@@full_house_valueif((max==3andsmax==2)||joker)cats[:small_straight]=@@small_straight_valueif(small||joker)cats[:large_straight]=@@large_straight_valueif(large||joker)cats[:yahtzee]=@@yahtzee_valueif(max>=5||joker)cats[:chance]=sumreturncatsend