Пример #1
0
        private IEnumerator RunStateScenario(Deck deckWithBiddingCards)
        {
            Debug.Log("RunStateScenario");
            //select random player to start
            NetworkPlayer[] shuffledPlayerList = GameCircle
                                                 .GamePlayers
                                                 .ToArray();

            //shuffledPlayerList.Shift(UnityEngine.Random.Range(0, 3));
            shuffledPlayerList.Shift(1);

            FirstMovePlayer = shuffledPlayerList[0];

            // All players should peek their bid or pass.
            yield return(StartCoroutine(MainBidding(shuffledPlayerList)));

            if (shuffledPlayerList.All(player =>
                                       !player.SelectedBiddingSuit.HasValue || //was selected BidSuit.SNIP
                                       player.SelectedBiddingSuit == BidSuit.PASS))    //all players selected pass
            {
                Debug.Log("all players selected pass");

                //first player takes bidding cards and gets rid of extra cards
                yield return(StartCoroutine(FirstPlayerGetRidOfTwoExtraCards(FirstMovePlayer, deckWithBiddingCards.GetCards(2).ToArray())));

                //bidding timeout
                if (FirstMovePlayer.TwoExtraCardsSelectedByFirstPlayer == null)
                {
                    foreach (var player in shuffledPlayerList)
                    {
                        player.SelectedBiddingSuit = BidSuit.PASS;
                    }
                    GameCircle.RoundComplete(shuffledPlayerList);
                    yield break;
                }

                //after that he must choose bid again
                var availableChoices = EnumExtender.GetAllVariants <BidSuit>().Except(new[] { BidSuit.SNIP }).ToArray();
                yield return(StartCoroutine(MakeBidding(FirstMovePlayer, availableChoices)));

                if (FirstMovePlayer.SelectedBiddingSuit == BidSuit.PASS)
                {
                    foreach (var player in shuffledPlayerList.Except(FirstMovePlayer))
                    {
                        player.SelectedBiddingSuit = BidSuit.PASS;
                    }
                    //if he selected pass again
                    //he looses game
                    GameCircle.RoundComplete(shuffledPlayerList);
                    yield break;
                }
            }

            WonBiddingPlayer = shuffledPlayerList.OrderBy(player => player.SelectedBiddingSuit).Last();
            WonBiddingPlayer.IsBiddingWinner = true;

            GameCircle.BiddingCompleted(shuffledPlayerList[0], WonBiddingPlayer, WonBiddingPlayer.SelectedBiddingSuit.Value);
        }
Пример #2
0
        /// <summary>
        /// Variants of complete:
        /// 1. one of players selected bid and 2 other selected PASS
        /// 2. all selected PASS.
        /// </summary>
        /// <param name="shuffledPlayerList"></param>
        /// <returns></returns>
        private IEnumerator MainBidding(NetworkPlayer[] shuffledPlayerList)
        {
            BidSuit previousBiggestSuit = BidSuit.PASS;            //nobody made any bid by default

            while (true)
            {
                foreach (NetworkPlayer player in shuffledPlayerList)
                {
                    Debug.Log("MainBidding. " + player.gameObject.ToString(), player);

                    //previous player selected max available bit
                    if (previousBiggestSuit == BidSuit.SNIP)
                    {
                        //player.SelectedBiddingSuit = BidSuit.PASS; //all next player passes
                        continue;
                    }

                    if (player.SelectedBiddingSuit != null && player.SelectedBiddingSuit == previousBiggestSuit)
                    {
                        //that player, who selected biggest bid in previous iteration,
                        //just waits until other players make bigger bid in this
                        continue;
                    }

                    var allVariants = EnumExtender.GetAllVariants <BidSuit>();

                    //it's forbiden to take SPADE before you have 2 extra cards (in second bidding)
                    BidSuit[] forbiddenChoices = { BidSuit.SPADE };

                    if (previousBiggestSuit != BidSuit.PASS)
                    {
                        //next bid must be bigger than previous
                        forbiddenChoices = allVariants
                                           .Where(suit => suit <= previousBiggestSuit && suit != BidSuit.PASS)
                                           .ToArray();
                    }

                    var availableChoices = allVariants.Except(forbiddenChoices).ToArray();

                    yield return(StartCoroutine(MakeBidding(player, availableChoices)));

                    if (player.SelectedBiddingSuit.Value > previousBiggestSuit)                     //player made bigger bid
                    {
                        previousBiggestSuit = player.SelectedBiddingSuit.Value;
                    }
                }

                if (IsTwoPassBids(shuffledPlayerList))
                {
                    break;                               //2 or more player selected PASS
                }
                if (previousBiggestSuit == BidSuit.SNIP) //selected max possible bid
                {
                    ////all player pass to that one who selected SNIP
                    //foreach (NetworkPlayer player in shuffledPlayerList)
                    //	if (player.SelectedBiddingSuit != BidSuit.SNIP)
                    //		player.SelectedBiddingSuit = BidSuit.PASS;
                    break;
                }
            }
        }