# File lib/quiz1/t/solutions/Bill Guindon/solitaire.rb, line 177 def next_key shift_card('A', :Joker, 1) shift_card('B', :Joker, 2) # find the 2 jokers, and sort them for the cut. jokers = [@deck.find_card('A', :Joker), @deck.find_card('B', :Joker)].sort # increment the 2nd joker pos -- cut uses 'up to, but not including' jokers[1] += 1 # reverse works nicely for the triple cut. @deck.cards = @deck.cut_cards(jokers).reverse # get the value from the last card, and cut up to it. cuts = @deck.cut_cards([@deck.cards.last.rank, @deck.cards.length - 1]) @deck.cards = cuts[1] + cuts[0] + cuts[2] # read top card value, count down that many cards + 1 key = @deck.cards[@deck.cards[0].rank].rank # convert it to a letter, adjust if needed. key -= 26 if key > 26 # if key is still > 26, then it's a joker! return (key) unless key > 26 # try again if it's a joker! next_key end