public bool Play(Card card) { if (_hand.Contains(card)) { _hand.Remove(card); _grave.Add(card); EventManager.Instance.QueueEvent(new Evt_PlayedCard() { Owner = Owner, Card = card }); return(true); } return(false); }
public void Initialize(CardSet deadCards) { CardSet full = StdDeck.Descriptor.FullDeck; Debug.Assert(full.CountCards() == 52); full.Remove(deadCards); _cards = StdDeck.Descriptor.GetIndexesAscending(full).ToArray(); }
public void TrashCardInPlay(CardType cardType) { var card = _cardsInPlay.FirstOrDefault(c => c.CardType == cardType); if (card == null) { return; } _cardsInPlay.Remove(card); PutCardInTrash(card); }
private Bucket[] CreatePreflopBuckets(int preflopBucketsCount) { Bucket[] buckets = new Bucket[preflopBucketsCount].Fill(i => new Bucket()); int totalHands = 0; for (int i = 0; i < HePocket.Count; ++i) { HePocketKind pk = (HePocketKind)i; // Use all possible pockets for each pocket kind. This ensures // that they occur with the natural frequency in a typical case where // a bucket contain pocket kinds with different numbers of pockets (e.g. AA - 6, AKs - 4, AKo - 12). CardSet [] range = HePocket.KindToRange(pk); foreach (CardSet pocketCs in range) { McHand hand = new McHand(); int[] pocket = StdDeck.Descriptor.GetIndexesAscending(pocketCs).ToArray(); CardSet restCs = StdDeck.Descriptor.FullDeck; restCs.Remove(pocketCs); int[] rest = StdDeck.Descriptor.GetIndexesAscending(restCs).ToArray(); Debug.Assert(pocket.Length + rest.Length == 52); pocket.CopyTo(hand.Cards, 0); rest.CopyTo(hand.Cards, 2); hand.Length = 2; int abstrCard = Clusterizer.GetAbstractCard(hand.Cards, hand.Length); buckets[abstrCard].Hands.Add(hand); totalHands++; } } Debug.Assert(totalHands == 1326); if (IsVerbose) { Console.WriteLine("Preflop buckets created, buckets: {0}, hands: {1}", buckets.Length, totalHands); } return(buckets); }
private static void TestUnit_04_CardSet() { // test frame for a single CardSet object Card card1 = new Card(CardColor.Kreuz, CardPicture.Neun); Card card2 = new Card(CardColor.Pik, CardPicture.König); Card card3 = new Card(CardColor.Herz, CardPicture.Sieben); CardSet set = new CardSet(); set.Add(card1); set.Add(card2); set.Add(card3); for (int i = 0; i < set.Size; i++) { Console.WriteLine("Karte {0}: {1}", i, set[i]); } Console.WriteLine("Karten auf der Hand: {0}", set); set.Remove(1); Console.WriteLine("Karten auf der Hand: {0}", set); }
public GameRecord Generate(int repetition) { string[][] enumNames = new string[_enumCounts.Count][]; int[] enumIndexes = new int[_enumCounts.Count]; CardSet deadCards = _fixedCards; if (_enumCounts.Count != 0) { int r = repetition; for (int d = _enumCounts.Count - 1; d >= 0; --d) { enumIndexes[d] = r % (int)_enumCombosCounts[d]; r /= (int)_enumCombosCounts[d]; } int redealFrom = _enumCombos.Count; for (int d = _enumCounts.Count - 1; d >= 0; --d) { if (enumIndexes[d] != 0) { break; } redealFrom = d; } for (int d = 0; d < redealFrom; ++d) { deadCards.UnionWith(_enumCombos[d][enumIndexes[d]]); } for (int d = redealFrom; d < _enumCombos.Count; ++d) { _enumCombos[d].Clear(); CardEnum.Combin(_deckDescr, _enumCounts[d], CardSet.Empty, deadCards, OnCombin, d); Debug.Assert(_enumCombosCounts[d] == _enumCombos[d].Count); deadCards.UnionWith(_enumCombos[d][enumIndexes[d]]); } for (int d = 0; d < _enumCombos.Count; ++d) { string enumCards = _deckDescr.GetCardNames(_enumCombos[d][enumIndexes[d]]); enumNames[d] = enumCards.Split(_separator, StringSplitOptions.RemoveEmptyEntries); } } GameRecord result = new GameRecord(_cfg.ToString()); result.Actions.Clear(); // Shuffle the rest of the deck. CardSet deckRest = _deckDescr.FullDeck; deckRest.Remove(deadCards); _randomDealer.SetSequence(_deckDescr.GetIndexesAscending(deckRest).ToArray()); _randomDealer.Shuffle(_randomCount); int randomDealt = 0; int[] enumDealt = new int[_enumCounts.Count]; // Deal the cards. for (int a = 0; a < _cfg.Actions.Count; ++a) { PokerAction action = _cfg.Actions[a]; if (!action.IsDealerAction()) { continue; } string[] cards = action.Cards.Split(_separator, StringSplitOptions.RemoveEmptyEntries); CardSet resultCards = new CardSet(); foreach (string card in cards) { CardSet nextCard = new CardSet(); if (card == "?") { nextCard = _deckDescr.GetCardSet(_randomDealer.Sequence, randomDealt++, 1); } else if (card.Length > 0 && card.Substring(0, 1) == "#") { int d = int.Parse(card.Substring(1)); string enumName = enumNames[d][enumDealt[d]++]; nextCard = _deckDescr.GetCardSet(enumName); } else { nextCard = _deckDescr.GetCardSet(card); } Debug.Assert(!resultCards.IsIntersectingWith(nextCard)); resultCards.UnionWith(nextCard); } PokerAction resultAction = new PokerAction(action.Kind, action.Position, action.Amount, _deckDescr.GetCardNames(resultCards)); result.Actions.Add(resultAction); } Debug.Assert(_randomCount == randomDealt); return(result); }