Beispiel #1
0
        private DuplicateDealMetadata ExtractDuplicateDealMetadata(string line, DealMetadata deal, Dictionary <string, int> columnHeaders)
        {
            try
            {
                var duplicateDeal = new DuplicateDealMetadata();
                var values        = ParsePBNHelpers.ParseTableLine(line, columnHeaders);

                duplicateDeal.NSPairIndex = Int32.Parse(values["PairId_NS"]);
                duplicateDeal.EWPairIndex = Int32.Parse(values["PairId_EW"]);
                duplicateDeal.Contract    = values["Contract"];

                SysPlayer declarer;
                duplicateDeal.Declarer = Enum.TryParse(values["Declarer"], true, out declarer) ? (int)declarer : (int)SysPlayer.N;

                if (duplicateDeal.Contract == "-")
                {
                    return(null);
                }

                var position = PlayerPosition.North;
                switch (duplicateDeal.Declarer)
                {
                case (int)SysPlayer.S:
                    position = PlayerPosition.South;
                    break;

                case (int)SysPlayer.E:
                    position = PlayerPosition.East;
                    break;

                case (int)SysPlayer.W:
                    position = PlayerPosition.West;
                    break;
                }

                var contract = new Contract(duplicateDeal.Contract, position);

                int tricks;
                duplicateDeal.Result = Int32.TryParse(values["Result"], out tricks)
                    ? _scoreCalculator.CalculateScore(contract, tricks, (SysVulnerabilityEnum)deal.SysVulnerabilityId)
                    : _scoreCalculator.CalculateScore(contract, values["Result"], (SysVulnerabilityEnum)deal.SysVulnerabilityId);

                duplicateDeal.NSPercentage    = Int32.Parse(values.ContainsKey("Percentage_NS") ? values["Percentage_NS"] : values["IMP_NS"]);
                duplicateDeal.EWPercentage    = Int32.Parse(values.ContainsKey("Percentage_EW") ? values["Percentage_EW"] : values["IMP_EW"]);
                duplicateDeal.ContractDisplay = contract.Display();
                duplicateDeal.HandViewerInput = deal.HandViewerInput + ParsePBNHelpers.ConvertToPbnBiddingSequence(contract, deal.Dealer);
                duplicateDeal.Tricks          = values["Result"];

                return(duplicateDeal);
            }
            catch (Exception ex)
            {
                CustomErrorSignal.Handle(ex);
                return(null);
            }
        }
Beispiel #2
0
        private void CalculateOptimalContract(DealMetadata currentDeal)
        {
            var contract = _scoreCalculator.ComputeOptimalContract(currentDeal.PBNRepresentation, (SysVulnerabilityEnum)currentDeal.SysVulnerabilityId);

            currentDeal.BestContract                = contract.Item2.Notation();
            currentDeal.BestContractDisplay         = contract.Item2.Display();
            currentDeal.BestContractResult          = contract.Item1;
            currentDeal.BestContractDeclarer        = contract.Item2.PlayerPosition.ConvertToSysPlayer();
            currentDeal.BestContractHandViewerInput = currentDeal.HandViewerInput + ParsePBNHelpers.ConvertToPbnBiddingSequence(contract.Item2, currentDeal.Dealer);
        }
Beispiel #3
0
        public void DeclarerSDealerE()
        {
            //Arrange
            var       contract = new Contract("1S", PlayerPosition.South);
            const int dealerId = (int)SysPlayer.E;
            //Act
            var output = ParsePBNHelpers.ConvertToPbnBiddingSequence(contract, dealerId);

            //Assert
            Assert.AreEqual("|b|mb|p|mb|1S|mb|p|mb|p|mb|p|", output);
        }
Beispiel #4
0
        private static void CalculateMakeableContracts(DealMetadata deal)
        {
            var contracts = DoubleDummyModule.CalculateMakeableContracts(deal.PBNRepresentation);

            contracts.ForEach(contract => deal.MakeableContracts.Add(new MakeableContractMetadata
            {
                Contract        = contract.Display(),
                Declarer        = contract.PlayerPosition.ConvertToSysPlayer(),
                Denomination    = contract.Trump.Order,
                Level           = contract.Level,
                HandViewerInput = deal.HandViewerInput + ParsePBNHelpers.ConvertToPbnBiddingSequence(contract, deal.Dealer)
            }));
        }