Exemplo n.º 1
0
        public void Auction_InvalidBidThrows()
        {
            Auction auction = new Auction(CardinalDirection.North, Vurnability.None);

            var heartBid = new BidTrumph(TrumphSuite.Hearts, 1);
            PlacedBid heartPlacedBid = new PlacedBid(heartBid,
                new List<BidMeaning>()
                {
                    new BidMeaning(13, 21, new List<SuiteTells>() {new SuiteTells(SuiteColor.Hearts, 4, 11)})
                });

            var clubBid = new BidTrumph(TrumphSuite.Clubs, 1);
            PlacedBid clubPlacedBid = new PlacedBid(heartBid,
                new List<BidMeaning>()
                {
                    new BidMeaning(13, 21, new List<SuiteTells>() {new SuiteTells(SuiteColor.Clubs, 4, 11)})
                });

            auction.PlaceBid(heartPlacedBid);
            auction.PlaceBid(clubPlacedBid);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Determines whether <paramref name="bidToPlace"/> is acceptable.
        /// </summary>
        /// <param name="bidToPlace">The bid to place.</param>
        /// <returns>
        ///   <c>true</c> if [is bid acceptable] [the specified bid to place]; otherwise, <c>false</c>.
        /// </returns>
        private bool IsBidAcceptable(PlacedBid bidToPlace)
        {
            // The first bid is allways OK
            if (this.LastBid == null)
            {
                return true;
            }

            // A pass bid is accepable at all times.
            if (BidPass.Instance.Equals(bidToPlace.Bid))
            {
                return true;
            }

            return this.LastBid.IsHigherBid(bidToPlace.Bid);
        }
Exemplo n.º 3
0
        /// <summary>
        /// Places the bid.
        /// </summary>
        /// <param name="bidToPlace">The bid to place.</param>
        /// <exception cref="InvalidBidException">If the bid was not valid.</exception>
        public void PlaceBid(PlacedBid bidToPlace)
        {
            if (bidToPlace == null)
            {
                throw new ArgumentNullException("bidToPlace");
            }

            if (IsAuctionOver)
            {
                throw new InvalidBidException("The auction was over, no more bids acceptable", bidToPlace.Bid);
            }

            if (!IsBidAcceptable(bidToPlace))
            {
                throw new InvalidBidException("Bid was not valid", bidToPlace.Bid);
            }

            this.Bids.Add(bidToPlace);

            if(BidPass.Instance.Equals(bidToPlace.Bid) && Bids.Count >= 4)
            {
                bool fourPasses = true;
                for (int n = Bids.Count - 1; n >= Bids.Count - 4; n--)
                {
                    fourPasses &=  BidPass.Instance.Equals(Bids[n].Bid);

                    if (!fourPasses)
                    {
                        break;
                    }
                }
                if (fourPasses)
                {
                    IsAuctionOver = true;
                }
            }

            TurnToBid = TurnToBid.Next();
        }