예제 #1
0
        /// <summary>Constructor</summary>
        /// <param name="index">Index of the bid</param>
        /// <param name="newExplanation">Explanation of the bid</param>
        public Bid(int index, string newExplanation, bool alert, string newHumanExplanation)
        {
            switch (index)
            {
            case 0:
                this.level   = BidLevels.Pass;
                this.special = SpecialBids.Pass; break;

            case 36:
                this.level   = BidLevels.Pass;
                this.special = SpecialBids.Double; break;

            case 37:
                this.level   = BidLevels.Pass;
                this.special = SpecialBids.Redouble; break;

            default:
            {
                if (index > 35)
                {
                    throw new FatalBridgeException("invalid index: {0}", index);
                }
                this.special = SpecialBids.NormalBid;
                this.suit    = (Suits)((index - 1) % 5);
                this.level   = (BidLevels)(((index - 1) / 5) + 1);
                break;
            }
            }

            if (this.level > BidLevels.Level7)
            {
                throw new InvalidCastException("level " + this.level.ToString());
            }
            if (this.suit > Suits.NoTrump)
            {
                throw new InvalidCastException("suit " + this.suit.ToString());
            }
            this.explanation      = newExplanation;
            this.alert            = alert;
            this.humanExplanation = newHumanExplanation;
        }
예제 #2
0
 /// <summary>Constructor</summary>
 public void SetPass()
 {
     this.special = SpecialBids.Pass; this.level = BidLevels.Pass; this.alert = false;
 }
예제 #3
0
 /// <summary>Is bid equal to provided object?</summary>
 /// <param name="obj">Object to compare to</param>
 /// <returns>boolean</returns>
 public bool Equals(Suits s, BidLevels height)
 {
     return(this.level == height && this.suit == s);
 }
예제 #4
0
        /// <summary>Constructor</summary>
        /// <param name="fromXML">XML describing the bid</param>
        public Bid(string fromXML)
        {
            if (fromXML == null)
            {
                throw new ArgumentNullException("fromXML");
            }
            this.explanation = "";
            if (fromXML.Contains(";"))
            {
                string[] parts = fromXML.Split(';');
                if (parts.Length >= 2)
                {
                    this.explanation = parts[1];
                }
                if (parts.Length >= 3)
                {
                    this.humanExplanation = parts[2];
                }
                fromXML = parts[0];
            }

            if (fromXML.Contains("!"))
            {
                int p = fromXML.IndexOf('!');
                this.explanation = fromXML.Substring(p + 1);
                fromXML          = fromXML.Substring(0, p);
                this.NeedsAlert();
            }

            switch (fromXML.ToLowerInvariant())
            {
            case "p":
            case "pass":
            case "passes":
                this.level   = BidLevels.Pass;
                this.special = SpecialBids.Pass;
                break;

            case "x":
            case "dbl":
            case "double":
            case "doubles":
            case "36":
                this.level   = BidLevels.Pass;
                this.special = SpecialBids.Double;
                break;

            case "xx":
            case "rdbl":
            case "redouble":
            case "redoubles":
            case "37":
                this.level   = BidLevels.Pass;
                this.special = SpecialBids.Redouble;
                break;

            default:
                this.special = SpecialBids.NormalBid;
                this.level   = (BidLevels)(Convert.ToByte(fromXML[0]) - 48);
                this.suit    = SuitHelper.FromXML(fromXML.Substring(1));
                break;
            }
        }
예제 #5
0
 /// <summary>Constructor</summary>
 /// <param name="specialBid">Special bid</param>
 public Bid(SpecialBids specialBid)
 {
     this.special     = specialBid;
     this.level       = BidLevels.Pass;
     this.explanation = "";
 }