Class: HandRankingGenerator
- Inherits:
-
Object
- Object
- HandRankingGenerator
- Defined in:
- lib/rora/utils/hand_ranking_generator.rb
Constant Summary collapse
- HEART_FLUSH =
32
- DIAMOND_FLUSH =
243
- SPADE_FLUSH =
3125
- CLUB_FLUSH =
16807
Instance Method Summary collapse
- #generate_flush_hand_rankings ⇒ Object
- #generate_flush_map ⇒ Object
- #generate_non_flush_hand_rankings ⇒ Object
-
#initialize ⇒ HandRankingGenerator
constructor
A new instance of HandRankingGenerator.
Constructor Details
#initialize ⇒ HandRankingGenerator
Returns a new instance of HandRankingGenerator.
10 11 12 13 14 |
# File 'lib/rora/utils/hand_ranking_generator.rb', line 10 def initialize @total = 133784560 @count = 0 @scores = {} end |
Instance Method Details
#generate_flush_hand_rankings ⇒ Object
79 80 81 82 83 84 85 86 |
# File 'lib/rora/utils/hand_ranking_generator.rb', line 79 def generate_flush_hand_rankings file = File.new("7_card_flush_hands.csv", "w") Suit.values().each do |suit| generate_hand_rankings(suit, 6, 1, file) generate_hand_rankings(suit, 7, 0, file) end file.close end |
#generate_flush_map ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/rora/utils/hand_ranking_generator.rb', line 16 def generate_flush_map file = File.new("flushes.csv", "w") Suit.values().each do |suit_1| Suit.values().each do |suit_2| Suit.values().each do |suit_3| Suit.values().each do |suit_4| Suit.values().each do |suit_5| Suit.values().each do |suit_6| Suit.values().each do |suit_7| key = suit_1.id * suit_2.id * suit_3.id * suit_4.id * suit_5.id * suit_6.id * suit_7.id if(!@scores.has_key?(key)) @scores[key] = key suit = flush_suit(key) if(!suit.nil?) count = flush_count([suit_1, suit_2, suit_3, suit_4, suit_5, suit_6, suit_7], suit) file.write("#{key},#{count},#{suit}\n") end end end end end end end end end file.close end |
#generate_non_flush_hand_rankings ⇒ Object
46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 |
# File 'lib/rora/utils/hand_ranking_generator.rb', line 46 def generate_non_flush_hand_rankings file = File.new("7_card_non_flush_hands.csv", "w") cds = Deck.new.cards (0..45).each do |index_1| ((index_1 + 1)..46).each do |index_2| ((index_2 + 1)..47).each do |index_3| ((index_3 + 1)..48).each do |index_4| ((index_4 + 1)..49).each do |index_5| ((index_5 + 1)..50).each do |index_6| ((index_6 + 1)..51).each do |index_7| cards = [cds[index_1], cds[index_2], cds[index_3], cds[index_4], cds[index_5], cds[index_6], cds[index_7]].sort hand = get_best_hand(cards) key = get_key(cards, hand) if(!@scores.has_key?(key) && !hand.flush?) @scores[key] = hand.score file.write("#{hand.score},#{key}\n") end @count = @count + 1 if(@count % 1000 == 0) puts "#{DateTime.now.strftime('%Y-%m-%d %H:%M:%S')} :: #{@count} records processed #{sprintf("%05.3f", (Float(@count)/Float(@total)) * 100.0)}% complete, #{@scores.size} records captured" end end end end end end end end file.close end |