class CwCardUtils::SynergyProbability
Public: Calculates probability of drawing specific card combinations. 日本語: 特定カードの組み合わせを引く確率を計算します。
Public Class Methods
Source
# File lib/cw_card_utils/synergy_probability.rb, line 13 def initialize(deck, deck_size: 60) @deck = deck @deck_size = deck_size end
Public: Initialize with a deck and its size. 日本語: デッキとそのサイズで初期化します。
@param deck [CwCardUtils::DecklistParser::Deck] @param deck_size [Integer] @return [void]
Public Instance Methods
Source
# File lib/cw_card_utils/synergy_probability.rb, line 56 def prob_combo(target_names, draws) targets = Array(target_names).uniq case targets.size when 1 prob_single(targets, draws) when 2 prob_two_card_combo(targets, draws) when 3 prob_three_card_combo(targets, draws) else # For >3 cards, fallback to approximation approx_combo(targets, draws) end end
Probability of drawing ALL cards in the targets list (synergy pair/trio) Public: Probability of drawing all targets in given draws. 日本語: 指定枚数のドローで対象の全カードを揃える確率。
How it works (EN): For 1/2/3-card combos, uses exact inclusion–exclusion with hypergeometric terms. For 4+ cards, uses a conservative approximation by summing miss-probabilities.
仕組み (JA): 1/2/3 枚コンボは超幾何項の包除原理で厳密に算出。4 枚以上では各カードの不在確率を合算する保守的近似を用います。
@param target_names [Array<String>] @param draws [Integer] @return [Float] 0.0..1.0
Source
# File lib/cw_card_utils/synergy_probability.rb, line 33 def prob_single(target_names, draws) targets = Array(target_names).uniq draws_clamped = clamp_draws(draws) total_copies = count_copies(targets) total = hypergeometric(@deck_size, draws_clamped).to_f prob = 1 - hypergeometric(@deck_size - total_copies, draws_clamped).to_f / total prob.clamp(0.0, 1.0) end
Probability of drawing at least one of the target cards Public: Probability of drawing at least one of targets in given draws. 日本語: 指定枚数のドローで、対象のいずれか1枚以上を引く確率。
How it works (EN): Uses the complement rule with hypergeometric coefficients: 1 - C(N - T, d) / C(N, d), where N is deck size, T is total copies of targets, and d is draws (clamped).
仕組み (JA): 超幾何係数の補集合を用います。N をデッキ枚数、T を対象の総枚数、d をドロー枚数 (クランプ済み) とすると、1 - C(N - T, d) / C(N, d) で計算します。
@param target_names [Array<String>] @param draws [Integer] @return [Float] 0.0..1.0