public void DoubleDummy()
        {
            var board = new Board()
            {
                Dealer        = Seat.West,
                Vulnerability = Vulnerability.All,
                Hands         = HandCollection.ParsePbn("W:KJ95.T.AT873.T98 76.AQJ9642.KJ.QJ QT8.K87.962.A654 A432.53.Q54.K732")
            };
            var dds = Solver.MakeableContracts(board);

            Assert.AreEqual(0, dds[Seat.North, Denomination.Clubs].Level);
            Assert.AreEqual(0, dds[Seat.North, Denomination.Diamonds].Level);
            Assert.AreEqual(3, dds[Seat.North, Denomination.Hearts].Level);
            Assert.AreEqual(0, dds[Seat.North, Denomination.Spades].Level);
            Assert.AreEqual(1, dds[Seat.North, Denomination.NoTrumps].Level);

            Assert.AreEqual(0, dds[Seat.South, Denomination.Clubs].Level);
            Assert.AreEqual(0, dds[Seat.South, Denomination.Diamonds].Level);
            Assert.AreEqual(3, dds[Seat.South, Denomination.Hearts].Level);
            Assert.AreEqual(0, dds[Seat.South, Denomination.Spades].Level);
            Assert.AreEqual(1, dds[Seat.South, Denomination.NoTrumps].Level);

            Assert.AreEqual(1, dds[Seat.East, Denomination.Clubs].Level);
            Assert.AreEqual(2, dds[Seat.East, Denomination.Diamonds].Level);
            Assert.AreEqual(0, dds[Seat.East, Denomination.Hearts].Level);
            Assert.AreEqual(1, dds[Seat.East, Denomination.Spades].Level);
            Assert.AreEqual(0, dds[Seat.East, Denomination.NoTrumps].Level);

            Assert.AreEqual(1, dds[Seat.West, Denomination.Clubs].Level);
            Assert.AreEqual(2, dds[Seat.West, Denomination.Diamonds].Level);
            Assert.AreEqual(0, dds[Seat.West, Denomination.Hearts].Level);
            Assert.AreEqual(1, dds[Seat.West, Denomination.Spades].Level);
            Assert.AreEqual(0, dds[Seat.West, Denomination.NoTrumps].Level);
        }
Exemple #2
0
        // GET api/contracts?pbn=W:KJ95.T.AT873.T98 76.AQJ9642.KJ.QJ QT8.K87.962.A654 A432.53.Q54.K732
        // GET api/contracts?html=true&pbn=W:KJ95.T.AT873.T98 76.AQJ9642.KJ.QJ QT8.K87.962.A654 A432.53.Q54.K732
        public object Get(string pbn, bool?html = false, bool?stats = false)
        {
            var board = new Board
            {
                Hands = HandCollection.ParsePbn(pbn)
            };

            if (board.Hands[Seat.North].Cards.Count != 13)
            {
                throw new FormatException("North needs 13 cards.");
            }
            if (board.Hands[Seat.South].Cards.Count != 13)
            {
                throw new FormatException("South needs 13 cards.");
            }
            if (board.Hands[Seat.East].Cards.Count != 13)
            {
                throw new FormatException("East needs 13 cards.");
            }
            if (board.Hands[Seat.West].Cards.Count != 13)
            {
                throw new FormatException("West needs 13 cards.");
            }

            // Return HTML report?
            if (html.HasValue && html.Value)
            {
                var tournament = new Session();
                tournament.Boards.Add(board);
                var writer = new StringWriter();
                var report = new HandRecord()
                {
                    Tournament = tournament
                };
                report.Produce(writer);

                var response = new HttpResponseMessage();
                response.Content = new StringContent(writer.ToString());
                response.Content.Headers.ContentType = new MediaTypeHeaderValue("text/html");
                return(response);
            }

            // Stats and the data?
            if (stats.HasValue && stats.Value)
            {
                var stopWatch = new Stopwatch();
                stopWatch.Start();
                var contracts = Solver.MakeableContracts(board);
                stopWatch.Stop();

                return(new
                {
                    Stats = new
                    {
                        ProcessorCount = Environment.ProcessorCount,
                        ProcessorSpeedMhz = CPUSpeed(),
                        RunTime = stopWatch.Elapsed
                    },
                    Contracts = contracts
                });
            }

            // Just return the data.
            return(Solver.MakeableContracts(board));
        }