Ejemplo n.º 1
0
        public void Generate(HandCollection hands, params Hand[] fixedHands)
        {
            var deck = new Deck();

            deck.Shuffle();
            deck.Deal(hands, Seat.West, fixedHands);

restart:
            foreach (var hand in hands)
            {
                if (fixedHands.Contains <Hand>(hand))
                {
                    continue;
                }

                foreach (var fact in hand.Facts)
                {
                    if (fact.IsTrue(hand))
                    {
                        continue;
                    }
                    var ignore = new Hand[fixedHands.Length + 1];
                    ignore[0] = hand;
                    fixedHands.CopyTo(ignore, 1);
                    if (!fact.MakeGood(hand, hands.OtherHands(ignore)))
                    {
                        throw new Exception(string.Format("Can not make the hand {0} contain {1}.", hand, fact));
                    }
                    goto restart;
                }
            }
        }
 public void Indexing()
 {
     var hands = new HandCollection();
     Assert.AreSame(hands[0], hands[Seat.North]);
     Assert.AreSame(hands[1], hands[Seat.East]);
     Assert.AreSame(hands[2], hands[Seat.South]);
     Assert.AreSame(hands[3], hands[Seat.West]);
 }
 public void Initing()
 {
     var hands = new HandCollection();
     Assert.AreEqual(4, hands.Count);
     Assert.IsInstanceOfType(hands[Seat.North], typeof(Hand));
     Assert.IsInstanceOfType(hands[Seat.South], typeof(Hand));
     Assert.IsInstanceOfType(hands[Seat.East], typeof(Hand));
     Assert.IsInstanceOfType(hands[Seat.West], typeof(Hand));
 }
 public void ParsePbn()
 {
     var hands = HandCollection.ParsePbn("W:KQT2.AT.J6542.85 - A8654.KQ5.T.QJT6 -");
     Assert.AreEqual(13, hands[Seat.West].Cards.Count);
     Assert.AreEqual(0, hands[Seat.North].Cards.Count);
     Assert.AreEqual(13, hands[Seat.East].Cards.Count);
     Assert.AreEqual(0, hands[Seat.South].Cards.Count);
     CollectionAssert.Contains(hands[Seat.West].Cards, Card.Parse("KS"));
     CollectionAssert.Contains(hands[Seat.East].Cards, Card.Parse("6C"));
 }
 public void OtherHandsHand2()
 {
     var hands = new HandCollection();
     new Deck().Deal(hands);
     var otherHands = hands.OtherHands(hands[Seat.North], hands[Seat.South]);
     Assert.IsFalse(otherHands.Contains(hands[Seat.North]));
     Assert.IsTrue(otherHands.Contains(hands[Seat.East]));
     Assert.IsFalse(otherHands.Contains(hands[Seat.South]));
     Assert.IsTrue(otherHands.Contains(hands[Seat.West]));
 }
Ejemplo n.º 6
0
        public HandCollection OtherHands(params Hand[] hands)
        {
            var otherHands = new HandCollection();

            for (int i = 0; i < this.Count; ++i)
            {
                otherHands[i] = hands.Contains <Hand>(this[i]) ? new Hand() : this[i];
            }

            return(otherHands);
        }
Ejemplo n.º 7
0
        public HandCollection OtherHands(Hand hand)
        {
            var otherHands = new HandCollection();

            for (int i = 0; i < this.Count; ++i)
            {
                otherHands[i] = hand == this[i] ? new Hand() : this[i];
            }

            return(otherHands);
        }
Ejemplo n.º 8
0
        public HandCollection OtherHands(Seat seat)
        {
            var otherHands = new HandCollection();

            for (int i = 0; i < this.Count; ++i)
            {
                otherHands[i] = this[i];
            }
            otherHands[(int)seat] = new Hand();

            return(otherHands);
        }
Ejemplo n.º 9
0
        public Deck Deal(HandCollection hands, Seat dealer)
        {
            var seat = dealer;

            foreach (var hand in hands)
            {
                hand.Cards.Clear();
            }
            for (int i = 0; i < Cards.Length; ++i)
            {
                seat = HandCollection.NextSeat(seat);
                hands[seat].Add(Cards[i]);
            }

            return(this);
        }
Ejemplo n.º 10
0
        public Deck Deal(HandCollection hands, Seat dealer, params Hand[] fixedHands)
        {
            var seat = dealer;

            foreach (var hand in hands)
            {
                if (!fixedHands.Contains <Hand>(hand))
                {
                    hand.Cards.Clear();
                }
            }
            for (int i = 0; i < Cards.Length; ++i)
            {
                seat = HandCollection.NextSeat(seat);
                if (fixedHands.Contains <Hand>(hands[seat]))
                {
                    continue;
                }
                var  card      = Cards[i];
                bool fixedCard = false;
                foreach (var fixedHand in fixedHands)
                {
                    if (fixedHand.Cards.Contains(card))
                    {
                        fixedCard = true;
                        break;
                    }
                }
                if (!fixedCard)
                {
                    hands[seat].Add(Cards[i]);
                }
            }

            return(this);
        }
Ejemplo n.º 11
0
        public void Generate(HandCollection hands)
        {
            var deck = new Deck();

            deck.Shuffle();
            deck.Deal(hands);

restart:
            foreach (var hand in hands)
            {
                foreach (var fact in hand.Facts)
                {
                    if (fact.IsTrue(hand))
                    {
                        continue;
                    }
                    if (!fact.MakeGood(hand, hands.OtherHands(hand)))
                    {
                        throw new Exception(string.Format("Can not make the hand {0} contain {1}.", hand, fact));
                    }
                    goto restart;
                }
            }
        }
Ejemplo n.º 12
0
        public static HandCollection ParsePbn(string s)
        {
            if (s.IndexOf(':') != 1)
            {
                throw new FormatException("Missing the 'first' delimiter.");
            }
            Seat seat;

            switch (s[0])
            {
            case 'N': seat = Seat.North; break;

            case 'E': seat = Seat.East; break;

            case 'S': seat = Seat.South; break;

            case 'W': seat = Seat.West; break;

            default: throw new FormatException("Invalid 'first' valid.");
            }
            string[] handStrings = s.Substring(2).Split(' ');
            if (handStrings.Length != 4)
            {
                throw new FormatException("Not all four hands are defined.");
            }

            var hands = new HandCollection();

            foreach (string cards in handStrings)
            {
                hands[seat] = cards == "-" ? new Hand() : Hand.ParsePbn(cards);
                seat        = NextSeat(seat);
            }

            return(hands);
        }
Ejemplo n.º 13
0
 public Deck Deal(HandCollection hands)
 {
     return(Deal(hands, Seat.West));
 }
 public void Issue9()
 {
     var pbn = "N:AKJ763.987.T8.Q8 .AKT3.Q6543.KJ64 QT98.64.A9.97532 542.QJ52.KJ72.AT";
     var hands = HandCollection.ParsePbn(pbn);
     Assert.AreEqual(pbn, hands.ToPbn(Seat.North));
 }
 public void ToPbn()
 {
     var pbn = "W:KQT2.AT.J6542.85 - A8654.KQ5.T.QJT6 -";
     var hands = HandCollection.ParsePbn(pbn);
     Assert.AreEqual(pbn, hands.ToPbn(Seat.West));
 }
Ejemplo n.º 16
0
 public Board()
 {
     Hands = new HandCollection();
 }