public CardsDistributionShowForm(CardsDistribution cd) { this.cd = cd; InitializeComponent(); }
public CardsDistributionForm(CardsDistribution cd) { this.cd = new CardsDistribution(cd); InitializeComponent(); }
//Онеры (для роббера) public static void GetOners(OnersSwitcher oners, Contract contract, CardsDistribution cd) { // Определить масть, запомнить старую масть CardTrump old_trump = oners.trump; if (contract == null || !contract.IsDefined() || contract.NoContract) { oners.trump = CardTrump.NotYetDefined; } else { oners.trump = contract.Trump; } // Если масть неизвестна, то отменить онеры if (oners.trump == CardTrump.NotYetDefined) { oners.Choise = 0; //- } // Взять из распределения карт if (cd != null && cd.IsDefined()) { oners.Choise = CountOners(cd, oners.trump); } //Использовать введенное пользователем значение else { if (old_trump != oners.trump) //масть изменилась, отменить онеры oners.Choise = 0; //- } }
public static void GetCompensation(SimpleScore out_comp, CardsDistribution cd, IntData fig, ZoneSwitcher zone, bool useReletivePair, PairSwitcher pair, int type_of_compens) { if (out_comp == null) return; // Определить тип компенсации и соотв. функцию TypeOfCompensation comp_type = (TypeOfCompensation)type_of_compens; CompensFunction comp_f; switch (comp_type) { case TypeOfCompensation.Chicago: comp_f = Compens_Chicago; break; case TypeOfCompensation.Moscow: comp_f = Compens_Moscow; break; case TypeOfCompensation.Milton_York: comp_f = Compens_MiltonYork; break; default: throw new Exception("Не могу определить тип компесации: " + type_of_compens.ToString()); } if (zone != null && zone.IsDefined() && cd != null && cd.IsDefined()) //распределение приоритетнее, чем поле "фигуры" { int NS_figs, EW_figs; NS_figs = CountFigurs(cd, Pairs.NS); EW_figs = 40 - NS_figs; int iNS_comp = comp_f(NS_figs, ZoneSwitcher.IsPairInZone(Pairs.NS, zone.Zone)); int iEW_comp = comp_f(EW_figs, ZoneSwitcher.IsPairInZone(Pairs.EW, zone.Zone)); out_comp.SetScore(iEW_comp, iNS_comp); } else if (zone != null && zone.IsDefined() && fig != null && fig.IsDefined() && (pair != null && pair.IsDefined() || useReletivePair)) { int NS_figs, EW_figs; if (!useReletivePair && pair.Pair == Pairs.NS || useReletivePair && RelativePair == Pairs.NS) //!!!! { NS_figs = fig.Value; EW_figs = 40 - NS_figs; } else { EW_figs = fig.Value; NS_figs = 40 - EW_figs; } int iNS_comp = comp_f(NS_figs, ZoneSwitcher.IsPairInZone(Pairs.NS, zone.Zone)); int iEW_comp = comp_f(EW_figs, ZoneSwitcher.IsPairInZone(Pairs.EW, zone.Zone)); out_comp.SetScore(iEW_comp, iNS_comp); } else { out_comp.Born = false; } }
//Компенсация !!!!! С ФИТАМИ !!!!! public static void GetCompensation_WithFits(SimpleScore out_comp, CardsDistribution cd, IntData fig, ZoneSwitcher zone, bool useReletivePair, PairSwitcher pair, /*fits:*/ FitsSwitcher fits, BoolData strongest, bool TenCardsIsTwoFits, bool LessCompFor2Fits23PC) { if (out_comp == null) return; if (zone != null && zone.IsDefined() && cd != null && cd.IsDefined()) //распределение приоритетнее, чем поле "фигуры" и "фиты" { Pairs pairStrongest = Pairs.NotDefinedYet; int figs_NS = CountFigurs(cd, Pairs.NS); int figs_EW = 40 - figs_NS; if(figs_NS > figs_EW) pairStrongest = Pairs.NS; else if(figs_NS < figs_EW) pairStrongest = Pairs.EW; else pairStrongest = DefineStrongest(cd); int fitsOfStrongPair = CountFits(cd, pairStrongest, TenCardsIsTwoFits); int iNS_comp = 0, iEW_comp = 0; if(pairStrongest == Pairs.NS) iNS_comp = Compens_Europe(figs_NS, fitsOfStrongPair, ZoneSwitcher.IsPairInZone(Pairs.NS, zone.Zone), LessCompFor2Fits23PC); else iEW_comp = Compens_Europe(figs_EW, fitsOfStrongPair, ZoneSwitcher.IsPairInZone(Pairs.EW, zone.Zone), LessCompFor2Fits23PC); out_comp.SetScore(iEW_comp, iNS_comp); } else if (zone != null && zone.IsDefined() && fig != null && fig.IsDefined() && (pair != null && pair.IsDefined() || useReletivePair) && fits != null && fits.IsDefined() && (fig.Value != 20 || fig.Value == 20 && strongest != null && strongest.IsDefined())) { int NS_figs, EW_figs; if (!useReletivePair && pair.Pair == Pairs.NS || useReletivePair && RelativePair == Pairs.NS) //!!!! { NS_figs = fig.Value; EW_figs = 40 - NS_figs; } else { EW_figs = fig.Value; NS_figs = 40 - EW_figs; } Pairs pairStrongest = Pairs.NotDefinedYet; if(NS_figs > EW_figs) pairStrongest = Pairs.NS; else if(NS_figs < EW_figs) pairStrongest = Pairs.EW; else pairStrongest = (strongest.Value ? Pairs.NS : Pairs.EW); int fitsOfStrongPair = fits.Choise; int iNS_comp = 0, iEW_comp = 0; if(pairStrongest == Pairs.NS) iNS_comp = Compens_Europe(NS_figs, fitsOfStrongPair, ZoneSwitcher.IsPairInZone(Pairs.NS, zone.Zone), LessCompFor2Fits23PC); else iEW_comp = Compens_Europe(EW_figs, fitsOfStrongPair, ZoneSwitcher.IsPairInZone(Pairs.EW, zone.Zone), LessCompFor2Fits23PC); out_comp.SetScore(iEW_comp, iNS_comp); } else { out_comp.Born = false; } }
// Сколько очков за фигуры? public static void FiguresPoints(IntData out_figs, CardsDistribution cd, bool useReletivePair, PairSwitcher pair) { if (out_figs == null) return; if (!useReletivePair) //использовать pair { // Если пара неизвестна, то не принимать введенные фигуры if (pair == null || !pair.IsDefined()) { out_figs.Born = false; } else { // Если известно распределение карт, то заблокировать кол-во фигур на полученное из распределения if (cd != null && cd.IsDefined()) { out_figs.Value = CountFigurs(cd, pair.Pair); } else { } } } else //использовать RelativePair !!!!! { if (cd != null && cd.IsDefined()) { out_figs.Value = CountFigurs(cd, RelativePair); } else { } } }
// Очки за фиты (ОТНОСИТЕЛЬНО СИЛЬНОЙ ПАРЫ) public static void FitsPoints(FitsSwitcher out_fits, CardsDistribution cd, bool TenCardsIsTwoFits) { if (out_fits == null) return; // Определить из распределения карт, если оно есть: if (cd != null && cd.IsDefined()) { Pairs pairStrongest = Pairs.NotDefinedYet; int figs_NS = CountFigurs(cd, Pairs.NS); if (figs_NS > 20) pairStrongest = Pairs.NS; else if (figs_NS < 20) pairStrongest = Pairs.EW; else pairStrongest = DefineStrongest(cd); int fitsOfStrongPair = CountFits(cd, pairStrongest, TenCardsIsTwoFits); out_fits.Choise = (fitsOfStrongPair > 2 ? 2 : fitsOfStrongPair); } else { } }
//возврат: 0 "-", 1 "NS 4o", 2 "NS 5o", 3 "NS 4A", 4 "EW 4o", 5 "EW 5o", 6 "EW 4A" public static int CountOners(CardsDistribution cd, CardTrump trump) { if (trump == CardTrump.NotYetDefined) { return 0; //- } // Посчитать, кому приндледат 4 туза else if (trump == CardTrump.NT) { int countN = 0, countS = 0, countE = 0, countW = 0; Quarters q; for (CardSuit cs = (CardSuit)0; cs < (CardSuit)4; cs++) { q = cd.Get(CardValue.Ace, cs); switch (q) { case Quarters.N: countN++; break; case Quarters.S: countS++; break; case Quarters.E: countE++; break; case Quarters.W: countW++; break; } } if (countN == 4 || countS == 4) return 3; //NS 4A else if (countE == 4 || countW == 4) return 6; //EW 4A else return 0; //- } // Посчитать, кому принадлежат козырные онеры else { int countN = 0, countS = 0, countE = 0, countW = 0; Quarters q; for (CardValue cv = CardValue.Ten; cv <= CardValue.Ace; cv++) { q = cd.Get(cv, SmallHelper.TrumpToSuit(trump)); switch (q) { case Quarters.N: countN++; break; case Quarters.S: countS++; break; case Quarters.E: countE++; break; case Quarters.W: countW++; break; } } if (countN == 5 || countS == 5) return 2; //NS 5o else if (countE == 5 || countW == 5) return 5; //EW 5o else if (countN == 4 || countS == 4) return 1; //NS 4o else if (countE == 4 || countW == 4) return 4; //EW 4o else return 0; //- } }
// определить по картам сильную пару (при 20PC!!!) public static Pairs DefineStrongest(CardsDistribution cd) { //При 20 РС компенсация (как прибавление к очкам) начисляется линии, имеющей младший фит, а при двух фитах, не имеющей пикового. int fits_NS = CountFits(cd, Pairs.NS, false); int fits_EW = CountFits(cd, Pairs.EW, false); if (fits_NS > fits_EW) { return Pairs.NS; } else if (fits_EW > fits_NS) { return Pairs.EW; } else { if (fits_NS == 0) //обе пары не имеют фитов, => никто не сильнее { return Pairs.NotDefinedYet; } else if (fits_NS == 1) //обе пары по 1 фиту, => сильнее тот, у кого сильнее фит { return Whose1FitStronger(cd); } else if (fits_NS == 2) //обе пары по 2 фита, => сильнее тот, у кого есть пиковый фит { return WhoHasSpadesFit(cd); } else return Pairs.NotDefinedYet; } }
public static int CountFits(CardsDistribution cd, Pairs pair, bool TenCardsIsTwoFits) { int count = 0; //кол-во фитов int[] sum = new int[4] { 0, 0, 0, 0 }; //сумма карт каждой масти Quarters q; for (CardSuit cs = (CardSuit)0; cs < (CardSuit)4; cs++) { for (CardValue cv = CardValue.Two; cv <= CardValue.Ace; cv++) { q = cd.Get(cv, cs); if (pair == Pairs.NS && (q == Quarters.N || q == Quarters.S) || pair == Pairs.EW && (q == Quarters.E || q == Quarters.W)) sum[(int)cs]++; } } for (int i = 0; i < 4; i++) { if (sum[i] >= 10 && TenCardsIsTwoFits) count += 2; else if (sum[i] >= 8) count++; } return count; }
/*static public void GetCompensation(SimpleScore out_comp, IntData fig, ZoneSwitcher zone, PairSwitcher pair) { if (out_comp == null) return; if (fig == null || !fig.IsDefined() || zone == null || !zone.IsDefined() || pair == null || !pair.IsDefined()) { out_comp.Born = false; } else { int NS_figs, EW_figs; if (pair.Pair == Pairs.NS) { NS_figs = fig.Value; EW_figs = 40 - fig.Value; } else { EW_figs = fig.Value; NS_figs = 40 - fig.Value; } out_comp.SetScore(Compens(NS_figs, ZoneSwitcher.IsPairInZone(Pairs.NS, zone.Zone)), Compens(EW_figs, ZoneSwitcher.IsPairInZone(Pairs.EW, zone.Zone))); } }*/ public static int CountFigurs(CardsDistribution cd, Pairs pair) { int count = 0; Quarters q; for (CardValue cv = CardValue.Jack; cv <= CardValue.Ace; cv++) { for (CardSuit cs = (CardSuit)0; cs < (CardSuit)4; cs++) { q = cd.Get(cv, cs); if (pair == Pairs.NS && (q == Quarters.N || q == Quarters.S) || pair == Pairs.EW && (q == Quarters.E || q == Quarters.W)) count += (cv - CardValue.Jack + 1); } } return count; }
//чей 1 фит сильнее? public static Pairs Whose1FitStronger(CardsDistribution cd) { int[] sumNS = new int[4] { 0, 0, 0, 0 }; //сумма карт каждой масти (для NS) int[] sumEW = new int[4] { 0, 0, 0, 0 }; //сумма карт каждой масти (для EW) Quarters q; for (CardSuit cs = (CardSuit)0; cs < (CardSuit)4; cs++) { for (CardValue cv = CardValue.Two; cv <= CardValue.Ace; cv++) { q = cd.Get(cv, cs); if (q == Quarters.N || q == Quarters.S) sumNS[(int)cs]++; else if (q == Quarters.E || q == Quarters.W) sumEW[(int)cs]++; } } CardSuit suitNS = (CardSuit)4, suitEW = (CardSuit)4; for (int i = 0; i < 4; i++) { if (sumNS[i] >= 8) suitNS = (CardSuit)i; if (sumEW[i] >= 8) suitEW = (CardSuit)i; } if (SmallHelper.CompareSuits(suitNS, suitEW) == 1) return Pairs.NS; else if (SmallHelper.CompareSuits(suitNS, suitEW) == -1) return Pairs.EW; else return Pairs.NotDefinedYet; }
// Если 20 фигур - спросить, какая пара сильнее? public static void WhoIsStrongest20(BoolData out_strongest, IntData figs, CardsDistribution cd, bool loading_from_db) { // Если известно распределение карт, то определить по картам сильную пару if (cd != null && cd.IsDefined()) { int figs_NS = CountFigurs(cd, Pairs.NS); if (figs_NS == 20) { Pairs pairStrongest = DefineStrongest(cd); if (pairStrongest == Pairs.NS || pairStrongest == Pairs.NotDefinedYet) out_strongest.Value = true; else out_strongest.Value = false; } else { out_strongest.Born = false; } } // Иначе спросить у юзера else if (!loading_from_db) // ЕСЛИ ИДЕТ ЗАГРУЗКА ИЗ БД - НЕ СПРАШИВАТЬ!!! САМО ЗАГРУЗИТ!!! !!!!!!!!!!!!!!!!!!!!!!!!!! { if (figs != null && figs.IsDefined() && figs.Value == 20) { if (out_strongest.Born == false) // ВАЖНО!!! СПРАШИВАТЬ ТОЛЬКО ПРИ ИЗМЕНЕНИИ ФИГУР С XX НА 20 { if (MessageBox.Show("Какая пара сильнее?\nNS - да, EW - нет", "Фигур 20", MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button1) == DialogResult.Yes) out_strongest.Value = true; else out_strongest.Value = false; } } else { out_strongest.Born = false; } } }
//у кого пиковый фит? public static Pairs WhoHasSpadesFit(CardsDistribution cd) { int sumNS = 0, sumEW = 0; //сумма пиковых карт Quarters q; for (CardValue cv = CardValue.Two; cv <= CardValue.Ace; cv++) { q = cd.Get(cv, CardSuit.Spades); if (q == Quarters.N || q == Quarters.S) sumNS++; else if (q == Quarters.E || q == Quarters.W) sumEW++; } if (sumNS >= 8) return Pairs.NS; else if (sumEW >= 8) return Pairs.EW; else return Pairs.NotDefinedYet; }