public static BeloteCard GetBestCard(BeloteCard a, BeloteCard b, Card32Family trumpFamily) { if (a.Family == b.Family) { int aCardPoint = a.GetPoint(trumpFamily); int bCardpoint = b.GetPoint(trumpFamily); if (aCardPoint > bCardpoint) { return(a); } else if (aCardPoint == bCardpoint) // Same point, value wins { if (a.Value > b.Value) { return(a); } } } else { if (a.Family == trumpFamily) { return(a); } } return(b); }
public int GetPoints(Card32Family trumpFamily) { int points = 0; foreach (BeloteCard card in Deck.Cards) { points += card.GetPoint(trumpFamily); } return(points); }
public void Finalize(Card32Family trumpFamily) { BeloteCard bestCard = GetBest(trumpFamily); if (bestCard != null) { Winner = bestCard.Owner as Player; Points = GetPoints(trumpFamily); } }
public Sprite GetSprite(Card32Value Value, Card32Family Family) { foreach (CardSpriteRef cardRef in CardSprites) { if (cardRef.Value == Value && cardRef.Family == Family) { return(cardRef.Prefab); } } return(null); }
public BeloteCard GetBest(Card32Family trumpFamily) { Card32Family?requested = RequestedFamily; if (requested != null) { BeloteCard bestCard = Deck.Cards[0]; if (Deck.Cards.Count > 1) { for (int i = 1; i < Deck.Cards.Count; ++i) { BeloteCard card = Deck.Cards[i]; bestCard = BeloteCard.GetBestCard(card, bestCard, trumpFamily); } } return(bestCard); } return(null); }
//---------------------------------------------- void StartRound() { m_currentRound++; DealCards(); // TODO : Bidding round, Random Trump for now // TODO : Bidder Bidder = RoundFirstPlayer; Trump = (Card32Family)UnityEngine.Random.Range(0, Enum.GetValues(typeof(Card32Family)).Length); foreach (Player player in m_players) { player.Hand.SortByFamilyAndValue(Trump); } NewRoundEvent evt = Pools.Claim <NewRoundEvent>(); evt.Start = true; EventManager.SendEvent(evt); StartTurn(RoundFirstPlayer); }
protected BeloteDeck ComputePlayableCards(Fold fold, Card32Family trumpFamily) { BeloteDeck playables = new BeloteDeck(); m_trumpCards.Clear(); m_trumpBetterCards.Clear(); if (!Hand.Empty) { // No cards in the fold, all cards are valid if (fold.RequestedFamily == null) { playables.CopyFrom(Hand); } else { BeloteCard bestCard = fold.GetBest(trumpFamily); Player bestPlayer = bestCard.Owner as Player; Card32Family requestedFamily = (Card32Family)fold.RequestedFamily; // We look for cards of the requested families foreach (BeloteCard card in Hand.Cards) { if (card.Family == requestedFamily) { playables.AddCard(card); } if (card.Family == trumpFamily) { m_trumpCards.Add(card); if (bestCard.Family == trumpFamily) { if (BeloteCard.GetBestCard(card, bestCard, trumpFamily) == card) { m_trumpBetterCards.Add(card); } } } } // Remove all trump cards that are too low if (!playables.Empty && trumpFamily == requestedFamily) { if (m_trumpBetterCards.Count > 0) { playables.Clear(); playables.AddCards(m_trumpBetterCards); } } // No card of the requested family if (playables.Empty) { // Best card is partner we can play what we want if (bestPlayer.Team == this.Team) { playables.CopyFrom(Hand); } else { if (bestCard.Family == trumpFamily) { if (m_trumpBetterCards.Count > 0) { playables.AddCards(m_trumpBetterCards); } else // TODO : Add "pisser" rules { playables.AddCards(m_trumpCards); } } else { playables.AddCards(m_trumpCards); } if (playables.Empty) { playables.CopyFrom(Hand); } } } } } return(playables); }