예제 #1
0
        public void TestScoreTableLineIsParsed()
        {
            //Arrange
            const string header = @"Table\2R;Round\2R;PairId_NS\2R;PairId_EW\2R;Contract\4L;Declarer\1R;Result\2R;Lead\3L;Score_NS\6R;Score_EW\6R;MP_NS\2R;MP_EW\2R;Percentage_NS\3R;Percentage_EW\3R";
            const string line   = " 8  5  8 24 2H   N  7 H3       -   \"50\" 20  0 100   0";
            //Act
            var headerColumns = ParsePBNHelpers.ParseTableHeader(header);
            var output        = ParsePBNHelpers.ParseTableLine(line, headerColumns);

            //Assert
            Assert.AreEqual("8", output["Table"]);
            Assert.AreEqual("5", output["Round"]);
            Assert.AreEqual("8", output["PairId_NS"]);
            Assert.AreEqual("24", output["PairId_EW"]);
            Assert.AreEqual("2H", output["Contract"]);
            Assert.AreEqual("N", output["Declarer"]);
            Assert.AreEqual("7", output["Result"]);
            Assert.AreEqual("H3", output["Lead"]);
            Assert.AreEqual("-", output["Score_NS"]);
            Assert.AreEqual("50", output["Score_EW"]);
            Assert.AreEqual("20", output["MP_NS"]);
            Assert.AreEqual("0", output["MP_EW"]);
            Assert.AreEqual("100", output["Percentage_NS"]);
            Assert.AreEqual("0", output["Percentage_EW"]);
        }
예제 #2
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);
            }
        }
예제 #3
0
        private static PairMetadata ExtractPairMetadata(string line, Dictionary <string, int> columnHeaders)
        {
            var pair   = new PairMetadata();
            var values = ParsePBNHelpers.ParseTableLine(line, columnHeaders);

            pair.Name   = values["Names"];
            pair.Rank   = Int32.Parse(values["Rank"]);
            pair.Score  = decimal.Parse(values.ContainsKey("TotalPercentage") ? values["TotalPercentage"] : values["TotalScoreIMP"]);
            pair.PairId = Int32.Parse(values["PairId"]);

            var playerNames = pair.Name.Split(new[] { " - " }, StringSplitOptions.RemoveEmptyEntries);

            pair.Player1Name = playerNames[0];
            pair.Player2Name = playerNames[1];

            return(pair);
        }
예제 #4
0
        public void TestTotalScoreTableLineIsParsed()
        {
            //Arrange
            const string header = @"Rank\2R;PairId\2R;Table\2R;Direction\5R;TotalScoreMP\3R;TotalPercentage\5R;Names\40L;NrBoards\2R";
            const string line   = " 1  5  5 \"N-S\" 305 69.32 \"GAVRILIU MADALINA - BONTAS BUJOR\"       22";
            //Act
            var headerColumns = ParsePBNHelpers.ParseTableHeader(header);
            var output        = ParsePBNHelpers.ParseTableLine(line, headerColumns);

            //Assert
            Assert.AreEqual("1", output["Rank"]);
            Assert.AreEqual("5", output["PairId"]);
            Assert.AreEqual("5", output["Table"]);
            Assert.AreEqual("N-S", output["Direction"]);
            Assert.AreEqual("305", output["TotalScoreMP"]);
            Assert.AreEqual("69.32", output["TotalPercentage"]);
            Assert.AreEqual("GAVRILIU MADALINA - BONTAS BUJOR", output["Names"]);
            Assert.AreEqual("22", output["NrBoards"]);
        }