public Combination ImproveIfPossible(Card c1) { Combination buffer = new Combination(cards); for (int i = cards.Count - 1; i >= 0; i++) { if (cards[i] != c1) { cards.Remove(cards[i]); cards.Insert(i, c1); break; } } this.CountCombination(); if (Combination.Compare(this, buffer) < 0) { this.CleanCombination(); this.InsertCard(buffer.GetCards()); } return(this); }
public void FinishHand() { List <Player> winners = new List <Player>(); Combination comb = new Combination(); foreach (Player p in players) { if (!p.WaitForNextHand) { p.TakeBestCards(cards); p.cards.Rebuild(); if (Combination.Compare(p.cards, comb) > 0) { comb = p.cards; } } } foreach (Player p in players) { if ((p.cards == comb) && (!p.WaitForNextHand)) { winners.Add(p); } } int winsum = 0; if (winners.Count == 1) { foreach (Player p in winners) { if ((cards.Count == 5) && (gamelog.getMove(0).move != Movements.Fold)) { if (p.roundBet < Bank / 2) { winsum = p.roundBet * 2; p.Stack += winsum; Bank -= winsum; int k = players.IndexOf(p); if (k == 0) { players[1].Stack += Bank; } else { players[0].Stack += Bank; } } else { winsum = Bank; p.Stack += winsum; } p.OnMove(new MoveEventArgs(Movements.WinHandsUp, winsum, p)); OnHandsUp(new EventArgs()); } else { p.Stack += Bank; p.OnMove(new MoveEventArgs(Movements.Win, Bank, p)); } } } else { players[0].Stack += Bank / 2; players[1].Stack += Bank / 2; players[0].OnMove(new MoveEventArgs(Movements.WinHandsUp, Bank / 2, players[2])); players[1].OnMove(new MoveEventArgs(Movements.WinHandsUp, Bank / 2, players[1])); } Bank = 0; roundnum++; if (roundnum % 4 == 0) { sblind += 2; } foreach (Player p in players) { p.foldcards(); p.roundBet = 0; } cards.Clear(); if ((players[0].Stack == 0) || ((players[1].Stack == 0))) { OnGameEnd(new EventArgs()); return; } NewDiller(); NewHand(); }
public void TakeBestCards(List <Card> tablecards) { List <Card> allcards = new List <Card>(7); allcards.AddRange(tablecards); allcards.AddRange(hand); if (tablecards.Count > 3) { Combination buffer; if (allcards.Count == 6) { buffer = new Combination(); for (int i = 0; i < 5; i++) { buffer.InsertCard(allcards[i]); } buffer = buffer.ImproveIfPossible(allcards[5]); cards.CleanCombination(); cards.InsertCard(buffer.GetCards()); buffer = null; } else { Combination strongest = new Combination(cards.GetCards()); int j = 1; for (int i = 0; i < allcards.Count - 1; i++) { while (i + j < allcards.Count) { buffer = new Combination(); for (int k = 0; k < allcards.Count; k++) { if ((k != i) && (k != j)) { buffer.InsertCard(allcards[k]); } } if (Combination.Compare(buffer, strongest) > 0) { strongest.CleanCombination(); strongest.InsertCard(buffer.GetCards()); } buffer = null; j++; } } List <Card> leftcards = new List <Card>(); foreach (Card c in allcards) { if (!strongest.GetCards().Contains(c)) { leftcards.Add(c); } } strongest = strongest.ImproveIfPossible(leftcards[0]); strongest = strongest.ImproveIfPossible(leftcards[1]); cards.InsertCard(strongest.GetCards()); } } else { List <Card> buffer = new List <Card>(5); buffer = cards.GetCards(); for (int i = 0; i < allcards.Count; i++) { if (!buffer.Contains(allcards[i])) { cards.InsertCard(allcards[i]); } } } }
private double AnalizeCombination() { double result = 0; Combination test = new Combination(game.table.cards); test.CountCombination(); test.Rebuild(); bool wettable = Combination.Compare(cards, test) <= 0; switch (cards.combination) { case Combinations.StreightFlash: { if (!wettable) { result = 1.5; } else { result = 1; } break; } case Combinations.Kare: { if (!wettable) { result = 1.5; } else { result = 1; } break; } case Combinations.FullHouse: { if (!wettable) { result = 1.4; } else { result = 0.9; } break; } case Combinations.Flash: { if (!wettable) { result = 1.3; } else { result = 0.8; } break; } case Combinations.Streight: { if (!wettable) { result = 1.2; } else { result = 0.7; } break; } case Combinations.Tree: { if (!wettable) { result = 1.1; } else { result = 0.6; } break; } case Combinations.TwoPairs: { if (!wettable) { result = 1; } else { result = 0.5; } break; } case Combinations.Pair: { if (!wettable) { result = 0.8; } else { result = 0.3; } break; } case Combinations.HighCard: { if (!wettable) { result = 0.6; } else { result = 0.1; } break; } } return(result); }