Exemple #1
0
        public void ModifyLevelIfOpponentRaised(BiddingRound round)
        {
            Bid lastOpponentBid = round.LastOpponentBid();

            if (lastOpponentBid.IsPass)
            {
                return;
            }

            if (Bid.IsHigherThan(lastOpponentBid))
            {
                return;
            }

            int levelDiff = Bid.LevelDifference(lastOpponentBid, Bid);

            if (levelDiff == 0)
            {
                // We wanted to bid the same as our opponent
                levelDiff = 1;
            }

            Console.ForegroundColor = ConsoleColor.DarkRed;
            Console.WriteLine($"\nPartner was overcalled. We need to raise our bid {levelDiff} level(s) to be able to respond.\nPartner will interpret it as if it was {levelDiff} level(s) lower to get the correct read on our hand.\nOnly bid this if it's within reason.");
            Console.ResetColor();

            Bid.NumberOfTricks += levelDiff;
        }
Exemple #2
0
        public void Start()
        {
            PlayerPosition userPosition = GetPlayerPositionFromUserInput("Your position: ");
            PlayerPosition firstToBid   = GetPlayerPositionFromUserInput("First player to bid: ");

            while (true)
            {
                BiddingRound round = new BiddingRound(userPosition, firstToBid);

                DoBidding(round);

                BiddingRoundHistory.Add(round);

                Console.ForegroundColor = ConsoleColor.Red;
                Console.WriteLine("\nNew hand\n");
                Console.ForegroundColor = ConsoleColor.White;

                // TODO Add tips for communication during play

                firstToBid = BiddingRound.GetNextPlayerPosition(firstToBid);
            }
        }
Exemple #3
0
        private static void DoBidding(BiddingRound round)
        {
            Hand userHand = GetHandFromUserInput("Your hand: ");

            BiddingSystemLogic biddingLogic = new BiddingSystemLogic(round, userHand);

            while (true)
            {
                if (round.BiddingEnded)
                {
                    return;
                }

                Bid bid;

                if (round.CurrentBiddingPlayer == round.User)
                {
                    // It's our turn to bid

                    if (new List <BiddingMode> {
                        BiddingMode.Improvise, BiddingMode.Overcall, BiddingMode.OvercallResponse
                    }.Contains(round.BiddingMode))
                    {
                        Console.ForegroundColor = ConsoleColor.DarkGreen;
                        Console.WriteLine("\nWe can't help you anymore. Waiting for next hand.");
                        Console.ForegroundColor = ConsoleColor.White;
                        return;
                    }

                    BiddingSystemFeedback feedback = null;

                    if (round.BiddingMode == BiddingMode.Opening)
                    {
                        feedback = biddingLogic.OpeningBid();
                    }
                    else if (round.BiddingMode == BiddingMode.Responding)
                    {
                        feedback = biddingLogic.RespondingBid();
                        feedback.ModifyLevelIfOpponentRaised(round);
                    }
                    else if (round.BiddingMode == BiddingMode.OpenersRebid)
                    {
                        feedback = biddingLogic.OpenersRebid();
                    }

                    if (feedback != null)
                    {
                        feedback.ToConsole();
                    }

                    if (round.BiddingMode == BiddingMode.Responding || round.BiddingMode == BiddingMode.OpenersRebid)
                    {
                        // Can't help the user after this
                        return;
                    }

                    bid = GetBidFromUserInput("Your bid: ");
                }
                else if (round.CurrentBiddingPlayer == round.Partner)
                {
                    bid = GetBidFromUserInput("Partner's bid: ");
                }
                else
                {
                    bid = GetBidFromUserInput($"{round.CurrentBiddingPlayer.Position.ToString()} bid: ");
                }

                if (bid == null)
                {
                    // User input "break"
                    return;
                }

                round.AddBid(bid);

                round.NextTurn();

                continue;
            }
        }