Exemplo n.º 1
0
        /// <summary> Gets the final contract of the bidding </summary>
        /// <returns> The final contract of the bidding - an object of the class Contract </returns>
        public Contract getContract(int dealID)
        {
            Bid lastBid = getLastStrainBid();

            if (lastBid == null)
            {
                return(null);
            }
            Bid  modifier                = bidding.Last.Previous.Previous.Previous.Value;
            bool isDoubled               = modifier.getValue() == "X";
            bool isRedoubled             = modifier.getValue() == "XX";
            int  declarer                = (dealID - 1) % 4;
            int  idx                     = declarer;
            LinkedListNode <Bid> current = bidding.First;

            while (current.Value != lastBid)
            {
                current = current.Next;
                idx++;
            }
            int mod = idx % 2;

            idx     = declarer;
            current = bidding.First;
            while (current.Value.getValue() != lastBid.getValue() || idx % 2 != mod)
            {
                current = current.Next;
                idx++;
                declarer++;
            }
            declarer %= 4;
            return(new Contract(lastBid.getLevel(), new Strain(lastBid.getValue()), isDoubled, isRedoubled, true, declarer == 0 ? "N" : declarer == 1 ? "E" : declarer == 2 ? "S" : "W"));
        }
Exemplo n.º 2
0
 /// <summary> Checks whether a specified bid is currently a valid bid to make </summary>
 /// <param name="bid"> The bid to check the validity of </param>
 /// <returns> true if the bid is valid, otherwise false </returns>
 public bool isValidBid(Bid bid)
 {
     if (isBiddingOver())
     {
         return(false);
     }
     if (bid.getValue() == "P")
     {
         return(true);
     }
     if (bidding.Count == 0)
     {
         return(bid.getType() == 0);
     }
     if (bid.getValue() == "X")
     {
         if (bidding.Last.Value.getType() == 0)
         {
             return(true);
         }
         if (bidding.Count >= 3)
         {
             return(bidding.Last.Value.getValue() == "P" && bidding.Last.Previous.Value.getValue() == "P" && bidding.Last.Previous.Previous.Value.getType() == 0);
         }
         return(false);
     }
     if (bid.getValue() == "XX")
     {
         if (bidding.Last.Value.getValue() == "X")
         {
             return(true);
         }
         if (bidding.Count >= 3)
         {
             return(bidding.Last.Value.getValue() == "P" && bidding.Last.Previous.Value.getValue() == "P" && bidding.Last.Previous.Previous.Value.getValue() == "X");
         }
         return(false);
     }
     return(bid.compare(getLastStrainBid()));
 }
Exemplo n.º 3
0
 public bool compare(Bid other)
 {
     if (other == null)
     {
         return(true);
     }
     if (level > other.getLevel())
     {
         return(true);
     }
     if (level == other.getLevel())
     {
         string[] ranks = new string[5] {
             "C", "D", "H", "S", "NT"
         };
         return(Array.IndexOf(ranks, strain.value) > Array.IndexOf(ranks, other.getValue()));
     }
     return(false);
 }