Esempio n. 1
0
        public void MakeGoodOne()
        {
            var board      = new Board();
            var hands      = board.Hands;
            var myHand     = hands[Seat.South];
            var otherHands = hands.OtherHands(Seat.South);

            new Deck()
            .Shuffle()
            .Deal(hands);
            var fact = new SuitHcp(6, Suit.Spades);

            Assert.IsTrue(fact.MakeGood(myHand, otherHands));
            Assert.AreEqual(6, HcpEvaluator.GetHcp(myHand, Suit.Spades));
            Console.WriteLine(board);

            new Deck()
            .Shuffle()
            .Deal(hands);
            fact = new SuitHcp(5, 9, Suit.Clubs);
            Assert.IsTrue(fact.MakeGood(myHand, otherHands));
            Console.WriteLine(board);
            int hcp = HcpEvaluator.GetHcp(myHand, Suit.Clubs);

            Assert.IsTrue(5 <= hcp && hcp <= 9);

            new Deck()
            .Shuffle()
            .Deal(hands);
            fact = new SuitHcp(14, Suit.Clubs);
            Assert.IsFalse(fact.MakeGood(myHand, otherHands));
        }
Esempio n. 2
0
        public void MakeGoodOne()
        {
            var board      = new Board();
            var hands      = board.Hands;
            var myHand     = hands[Seat.South];
            var otherHands = hands.OtherHands(Seat.South);

            new Deck()
            .Shuffle()
            .Deal(hands);
            var fact = new Hcp(23);

            Assert.IsTrue(fact.MakeGood(myHand, otherHands));
            Console.WriteLine(board);
            Assert.AreEqual(23, HcpEvaluator.GetHcp(myHand));

            new Deck()
            .Shuffle()
            .Deal(hands);
            fact = new Hcp(12, 14);
            Assert.IsTrue(fact.MakeGood(myHand, otherHands));
            Console.WriteLine(board);
            int hcp = HcpEvaluator.GetHcp(myHand);

            Assert.IsTrue(12 <= hcp && hcp <= 14);

            new Deck()
            .Shuffle()
            .Deal(hands);
            fact = new Hcp(42);
            Assert.IsFalse(fact.MakeGood(myHand, otherHands));
        }
Esempio n. 3
0
        public List <Fact> Evaluate(Hand hand)
        {
            var facts = new List <Fact>(4);

            facts.Add(new SuitHcp(HcpEvaluator.GetHcp(hand, Suit.Spades), Suit.Spades));
            facts.Add(new SuitHcp(HcpEvaluator.GetHcp(hand, Suit.Hearts), Suit.Hearts));
            facts.Add(new SuitHcp(HcpEvaluator.GetHcp(hand, Suit.Diamonds), Suit.Diamonds));
            facts.Add(new SuitHcp(HcpEvaluator.GetHcp(hand, Suit.Clubs), Suit.Clubs));
            return(facts);
        }
Esempio n. 4
0
        public bool MakeGood(Hand hand, HandCollection otherHands)
        {
            var rng = RandomThreaded.Generator;

            if (this.Minimum > 10 || this.Maximum > 10)
            {
                return(false);
            }

            Suit thisSuit = Suit;

            while (!IsTrue(hand))
            {
                int pointsNeeded = Minimum == Maximum ? Minimum : rng.Next(Minimum, Maximum + 1);
                int delta        = pointsNeeded - HcpEvaluator.GetHcp(hand, thisSuit);
                int ci;
                int oi;
                var other = otherHands[rng.Next(0, otherHands.Count)];
                if (delta > 0)
                {
                    ci = hand.Cards.FindIndexRandom(card => !(card.Suit == thisSuit && card.IsBiddingHonour));
                    if (ci < 0)
                    {
                        return(false);
                    }
                    oi = other.Cards.FindIndexRandom(card => card.Suit == thisSuit && card.IsBiddingHonour);
                    if (oi < 0)
                    {
                        continue;
                    }
                }
                else
                {
                    ci = hand.Cards.FindIndexRandom(card => card.Suit == thisSuit && card.IsBiddingHonour);
                    if (ci < 0)
                    {
                        return(false);
                    }
                    oi = other.Cards.FindIndexRandom(card => !(card.Suit == thisSuit && card.IsBiddingHonour));
                    if (oi < 0)
                    {
                        continue;
                    }
                }
                Card t = hand.Cards[ci];
                hand.Cards[ci]  = other.Cards[oi];
                other.Cards[oi] = t;
            }

            return(true);
        }
Esempio n. 5
0
        public void SuitHcp()
        {
            var hand = new Hand();

            hand.Add(Card.Parse("KC"));
            hand.Add(Card.Parse("AC"));
            hand.Add(Card.Parse("6C"));
            hand.Add(Card.Parse("2H"));
            hand.Add(Card.Parse("JH"));
            hand.Add(Card.Parse("QD"));
            hand.Add(Card.Parse("AD"));

            Assert.AreEqual(0, HcpEvaluator.GetHcp(hand, Suit.Spades));
            Assert.AreEqual(1, HcpEvaluator.GetHcp(hand, Suit.Hearts));
            Assert.AreEqual(6, HcpEvaluator.GetHcp(hand, Suit.Diamonds));
            Assert.AreEqual(7, HcpEvaluator.GetHcp(hand, Suit.Clubs));
        }
Esempio n. 6
0
        public bool MakeGood(Hand hand, HandCollection otherHands)
        {
            while (!IsTrue(hand))
            {
                int pointsNeeded = Minimum == Maximum ? Minimum : RandomThreaded.Generator.Next(Minimum, Maximum + 1);
                int delta        = pointsNeeded - HcpEvaluator.GetHcp(hand);
                int ci;
                int oi;
                var other = otherHands[RandomThreaded.Generator.Next(0, otherHands.Count)];
                if (delta > 0)
                {
                    ci = hand.Cards.FindIndexRandom(card => !card.IsBiddingHonour);
                    if (ci < 0)
                    {
                        return(false);
                    }
                    oi = other.Cards.FindIndexRandom(card => card.IsBiddingHonour);
                    if (oi < 0)
                    {
                        continue;
                    }
                }
                else
                {
                    ci = hand.Cards.FindIndexRandom(card => card.IsBiddingHonour); // FindRandomIndex
                    if (ci < 0)
                    {
                        return(false);
                    }
                    oi = other.Cards.FindIndexRandom(card => !card.IsBiddingHonour);
                    if (oi < 0)
                    {
                        continue;
                    }
                }
                Card t = hand.Cards[ci];
                hand.Cards[ci]  = other.Cards[oi];
                other.Cards[oi] = t;
            }

            return(true);
        }
Esempio n. 7
0
        public bool IsTrue(Hand hand)
        {
            var v = HcpEvaluator.GetHcp(hand, Suit);

            return(Minimum <= v && v <= Maximum);
        }
Esempio n. 8
0
        public bool IsTrue(Hand hand)
        {
            var hcp = HcpEvaluator.GetHcp(hand);

            return(Minimum <= hcp && hcp <= Maximum);
        }