/// <summary> /// 分析一个投注号码,计算此号码所包含的注数。 /// 投注号码格式错误时抛出异常AntecodeFormatException。 /// </summary> /// <param name="antecode">投注号码</param> /// <returns>号码所包含的注数</returns> public int AnalyzeAnteCode(string antecode) { string msg; if (!CheckAntecode(antecode, out msg)) { throw new AntecodeFormatException(GameCode, GameType, antecode, "投注号码格式错误 - " + msg); } var c = new Combination(); var i = 0; c.Calculate(AnteCodeNumbers, BallNumber, (num) => i++); return(i); }
private void CaculateBonus_R9(IWinNumberAnalyzable checker, List <int> bonusLevelList) { var numHitCount = 0; var danHitCount = 0; var zhu = 1; var danList = new List <string>(); var numList = new List <string>(); for (int i = 0; i < TotalNumber; i++) { var ante = AnteCodeNumbers[i]; var win = checker.WinNumbers[i]; if (ante != Wildcard && (ante.Contains(win) || (IsEnableWildcard && win == Wildcard))) { if (DanNumbers.Contains(i)) { danHitCount++; danList.Add(ante); } else { numHitCount++; numList.Add(ante); } if (ante.Length > 1 && win == Wildcard) { zhu *= ante.Length; } } } var hitCount = numHitCount + danHitCount; if (danHitCount >= DanNumbers.Length) { if (hitCount >= BallNumber) { var c = new Combination(); c.Calculate(numList.ToArray(), BallNumber - DanNumbers.Length, (item) => { for (int i = 0; i < zhu; i++) { bonusLevelList.Add(1); } }); } } }
/// <summary> /// 分析一个投注号码,计算此号码所包含的注数。 /// 投注号码格式错误时抛出异常AntecodeFormatException。 /// </summary> /// <param name="antecode">投注号码</param> /// <returns>号码所包含的注数</returns> public int AnalyzeAnteCode(string antecode) { string msg; if (!CheckAntecode(antecode, out msg)) { throw new AntecodeFormatException(GameCode, GameType, antecode, "投注号码格式错误 - " + msg); } var totalCount = 0; var danList = new List <string>(); var tmp = new List <string>(); for (int i = 0; i < TotalNumber; i++) { if (DanNumbers.Contains(i)) { danList.Add(AnteCodeNumbers[i]); } else { if (AnteCodeNumbers[i] != Wildcard.ToString()) { tmp.Add(AnteCodeNumbers[i]); } } } var c = new Combination(); c.Calculate(tmp.ToArray(), BallNumber - DanNumbers.Length, (item) => { var count = 1; foreach (var t in item) { count *= t.Length; } totalCount += count; }); foreach (var dan in danList) { totalCount *= dan.Length; } return(totalCount); }
public IList <int> CaculateBonus(string antecode, string winNumber) { string msg; if (!CheckAntecode(antecode, out msg)) { throw new AntecodeFormatException(GameCode, GameType, antecode, "投注号码格式错误 - " + msg); } var checker = KaSon.FrameWork.Analyzer.AnalyzerFactory.AnalyzerFactory.GetWinNumberAnalyzer(GameCode, GameType); if (!checker.CheckWinNumber(winNumber, out msg)) { throw new AntecodeFormatException(GameCode, GameType, winNumber, "中奖号码格式错误 - " + msg); } var bonusLevelList = new List <int>(); if (IsLast) // 直选好运特 任意选择1个数字竞猜开奖号码的最后一位(后一),投注号码与开奖号码最后一位相同即中奖 { if (AnteCodeNumbers.Contains(checker.WinNumbers.Last())) { bonusLevelList.Add(0); } } else if (BallNumber <= TotalNumber) // 任选的数量小于等于总号码数。如:任选四、任选五 { var p = new Combination(); p.Calculate(AnteCodeNumbers, BallNumber, (num) => { if (IsWin_Less(checker.WinNumbers, num)) { bonusLevelList.Add(0); } }); } else { throw new ArgumentOutOfRangeException("直选好运不支持的玩法 - 选" + BallNumber); } return(bonusLevelList.OrderBy((i) => i).ToList()); }
public static string ToAnteString_LiangCai(this Antecode ante, string gameCode, string gameType) { if (gameCode.Equals("SSQ", StringComparison.OrdinalIgnoreCase) && ante.GameType.Equals("DS", StringComparison.OrdinalIgnoreCase)) { return(ante.AnteNumber.Replace("|", "-").Replace(",", " ")); } if (gameCode.Equals("SSQ", StringComparison.OrdinalIgnoreCase) && ante.GameType.Equals("FS", StringComparison.OrdinalIgnoreCase)) { var hong = ante.AnteNumber.Split('|')[0]; var lan = ante.AnteNumber.Split('|')[1]; if (lan.Length > 35) { var lan1 = ante.AnteNumber.Split('|')[1].Substring(0, 17); var lan2 = ante.AnteNumber.Split('|')[1].Substring(18); return(hong.Replace(",", " ") + "-" + lan1.Replace(",", " ") + ";" + hong.Replace(",", " ") + "-" + lan2.Replace(",", " ")); } return(ante.AnteNumber.Replace("|", "-").Replace(",", " ")); } if (gameCode.Equals("SSQ", StringComparison.OrdinalIgnoreCase) && ante.GameType.Equals("DT", StringComparison.OrdinalIgnoreCase)) { var tmp = ante.AnteNumber.Split('|'); if (tmp.Length != 3) { throw new LogicException("大乐透胆拖玩法号码错误 - " + ante.AnteNumber); } var hongdan = tmp[0]; var hongtuo = tmp[1]; var lan = tmp[2]; if (lan.Length > 35) { var lan1 = lan.Substring(0, 17); var lan2 = lan.Substring(18); return(hongdan.Replace(",", " ") + "$" + hongtuo.Replace(",", " ") + "-" + lan1.Replace(",", " ") + ";" + hongdan.Replace(",", " ") + "$" + hongtuo.Replace(",", " ") + "-" + lan2.Replace(",", " ")); } return(string.Format("{0}${1}-{2}", hongdan.Replace(",", " "), hongtuo.Replace(",", " "), lan.Replace(",", " "))); } if (gameCode.Equals("DLT", StringComparison.OrdinalIgnoreCase) && (ante.GameType.Equals("DS", StringComparison.OrdinalIgnoreCase) || ante.GameType.Equals("FS", StringComparison.OrdinalIgnoreCase))) { return(ante.AnteNumber.Replace("|", "-").Replace(",", " ")); } if (gameCode.Equals("DLT", StringComparison.OrdinalIgnoreCase) && ante.GameType.Equals("DT", StringComparison.OrdinalIgnoreCase)) { var tmp = ante.AnteNumber.Replace(",", " ").Split('|'); if (tmp.Length != 4) { throw new LogicException("大乐透胆拖玩法号码错误 - " + ante.AnteNumber); } //05,06,07,08|01,02,03,04,09|01|02,03 //(05,06,07,08),01,02,03,04,09+(01),02,03 var hongdan = tmp[0]; var hongtuo = tmp[1]; var landan = tmp[2]; var lantuo = tmp[3]; return(string.Format("{0}${1}-{2}${3}", hongdan, hongtuo, landan, lantuo)); } if (gameCode.Equals("CTZQ", StringComparison.OrdinalIgnoreCase)) { switch (ante.GameType.ToUpper()) { case "T14C": if (ante.AnteNumber.Replace(",", "").Length > 38) { throw new LogicException("传统足球14场玩法号码错误 - " + ante.AnteNumber); } return(ante.AnteNumber); case "TR9": if (ante.AnteNumber.Replace(",", "").Length > 27) { throw new LogicException("传统足球任选9场玩法号码错误 - " + ante.AnteNumber); } return(ante.AnteNumber.Replace("*", "#")); case "T6BQC": if (ante.AnteNumber.Replace(",", "").Length > 32) { throw new LogicException("传统足球6场半全场玩法号码错误 - " + ante.AnteNumber); } return(ante.AnteNumber); case "T4CJQ": if (ante.AnteNumber.Replace(",", "").Length > 32) { throw new LogicException("传统足球4场进球玩法号码错误 - " + ante.AnteNumber); } return(ante.AnteNumber); default: return(ante.AnteNumber); } } #region 重庆时时彩 if (gameCode.Equals("CQSSC", StringComparison.OrdinalIgnoreCase)) { var touzhu = string.Empty; switch (ante.GameType.ToLower()) { case "1xdx": var dx1xL = ante.AnteNumber.Replace("-,-,-,-,", ""); if (dx1xL.Length > 5) { return(ConvertGameType(gameCode, gameType) + "|" + "-,-,-,-," + dx1xL.Substring(0, 5) + ";" + ConvertGameType(gameCode, gameType) + "|" + "-,-,-,-," + dx1xL.Substring(5)); } return(ConvertGameType(gameCode, gameType) + "|" + ante.AnteNumber); case "2xdx": var dx2xL = ante.AnteNumber.Replace("-,-,-,", "").Split(','); if (dx2xL[0].Length + dx2xL[1].Length > 12) { var list = new List <char[]>(); list.Add(dx2xL[0].ToArray()); list.Add(dx2xL[1].ToArray()); var strL = new List <string>(); var c = new ArrayCombination(); c.Calculate(list.ToArray(), a => { strL.Add(ConvertGameType(gameCode, gameType) + "|" + "-,-,-," + string.Join(",", a)); }); return(string.Join(";", strL)); } return(ConvertGameType(gameCode, gameType) + "|" + ante.AnteNumber); case "3xdx": var dx3xL = ante.AnteNumber.Replace("-,-,", "").Split(','); if (dx3xL[0].Length + dx3xL[1].Length + dx3xL[2].Length > 24) { var list = new List <char[]>(); list.Add(dx3xL[0].ToArray()); list.Add(dx3xL[1].ToArray()); list.Add(dx3xL[2].ToArray()); var strL = new List <string>(); var c = new ArrayCombination(); c.Calculate(list.ToArray(), a => { strL.Add(ConvertGameType(gameCode, gameType) + "|" + "-,-," + string.Join(",", a)); }); return(string.Join(";", strL)); } return(ConvertGameType(gameCode, gameType) + "|" + ante.AnteNumber); case "5xdx": var dx5xL = ante.AnteNumber.Split(','); if (ante.AnteNumber.Replace(",", "").Length > 45) { var list = new List <char[]>(); list.Add(dx5xL[0].ToArray()); list.Add(dx5xL[1].ToArray()); list.Add(dx5xL[2].ToArray()); list.Add(dx5xL[3].ToArray()); list.Add(dx5xL[4].ToArray()); var strL = new List <string>(); var c = new ArrayCombination(); c.Calculate(list.ToArray(), a => { strL.Add(ConvertGameType(gameCode, gameType) + "|" + string.Join(",", a)); }); return(string.Join(";", strL)); } return(ConvertGameType(gameCode, gameType) + "|" + ante.AnteNumber); case "2xzxfs": return(ConvertGameType(gameCode, gameType) + "|" + ante.AnteNumber.Replace(",", "")); case "5xtx": return(ConvertGameType(gameCode, gameType) + "|" + ante.AnteNumber); case "dxds": return(ConvertGameType(gameCode, gameType) + "|" + ante.AnteNumber.Replace(",", "")); default: return(ante.AnteNumber); } } #endregion #region 江西11选5 if (gameCode.Equals("JX11X5", StringComparison.OrdinalIgnoreCase)) { switch (ante.GameType.ToLower()) { case "rx2": case "rx3": case "rx4": case "rx5": case "rx6": case "rx7": case "q2zux": case "q3zux": return(ConvertGameType(gameCode, gameType) + "|" + ante.AnteNumber.Replace(",", " ")); case "q2zhix": if (ante.AnteNumber.Replace(",", " ").Split(' ').Length > 11) { var q2zhix = ante.AnteNumber.Replace(" ", "-").Split(','); var list = new List <string[]>(); list.Add(q2zhix[0].Split('-')); list.Add(q2zhix[1].Split('-')); var strL = new List <string>(); var c = new ArrayCombination(); c.Calculate(list.ToArray(), a => { if (a[0] != a[1]) { strL.Add(ConvertGameType(gameCode, gameType) + "|" + string.Join(",", a)); } }); return(string.Join(";", strL)); } return(ConvertGameType(gameCode, gameType) + "|" + ante.AnteNumber); case "q3zhix": if (ante.AnteNumber.Replace(",", " ").Split(' ').Length > 3) { var q3zhix = ante.AnteNumber.Replace(" ", "-").Split(','); var list = new List <string[]>(); list.Add(q3zhix[0].Split('-')); list.Add(q3zhix[1].Split('-')); list.Add(q3zhix[2].Split('-')); var strL = new List <string>(); var c = new ArrayCombination(); c.Calculate(list.ToArray(), a => { if (a.Distinct().ToArray().Length == 3) { strL.Add(ConvertGameType(gameCode, gameType) + "|" + string.Join(",", a)); } }); return(string.Join(";", strL)); } return(ConvertGameType(gameCode, gameType) + "|" + ante.AnteNumber); default: return(ante.AnteNumber); } } #endregion #region 排列三、福彩3D if (gameCode.Equals("PL3", StringComparison.OrdinalIgnoreCase) || gameCode.Equals("FC3D", StringComparison.OrdinalIgnoreCase)) { switch (ante.GameType.ToLower()) { case "ds": case "fs": var pl = ante.AnteNumber.Replace(",", ""); if (pl.Length > 24) { var pl3fs = ante.AnteNumber.Split(','); var list = new List <char[]>(); list.Add(pl3fs[0].ToArray()); list.Add(pl3fs[1].ToArray()); list.Add(pl3fs[2].ToArray()); var strL = new List <string>(); var c = new ArrayCombination(); c.Calculate(list.ToArray(), a => { strL.Add(ConvertGameType(gameCode, gameType) + "|" + string.Join(",", a)); }); return(string.Join(";", strL)); } return(ConvertGameType(gameCode, gameType) + "|" + ante.AnteNumber); case "hz": return(ConvertGameType(gameCode, gameType) + "|" + ante.AnteNumber); case "zx3ds": return(ConvertGameType(gameCode, gameType) + "|" + ante.AnteNumber); case "zx6": if (ante.AnteNumber.Replace(",", "").Length > 3) { var num = ante.AnteNumber.Replace(",", ""); var c = new Combination(); var strL = new List <string>(); c.Calculate(num.ToArray(), 3, a => { strL.Add(ConvertGameType(gameCode, gameType) + "|" + string.Join(",", a)); }); return(string.Join(";", strL)); } return(ConvertGameType(gameCode, gameType) + "|" + ante.AnteNumber); case "zx3fs": return(ConvertGameType(gameCode, gameType) + "|" + ante.AnteNumber.Replace(",", "")); default: return(ante.AnteNumber); } } #endregion return(ante.AnteNumber); }
public IList <int> CaculateBonus(string antecode, string winNumber) { string msg; if (!CheckAntecode(antecode, out msg)) { throw new AntecodeFormatException(GameCode, GameType, antecode, "投注号码格式错误 - " + msg); } var checker = KaSon.FrameWork.Analyzer.AnalyzerFactory.AnalyzerFactory.GetWinNumberAnalyzer(GameCode, GameType); if (!checker.CheckWinNumber(winNumber, out msg)) { throw new AntecodeFormatException(GameCode, GameType, winNumber, "中奖号码格式错误 - " + msg); } var bonusLevelList = new List <int>(); if (BallNumber == 3) { var p = new Combination(); p.Calculate(AnteCodeNumbers, BallNumber, (num) => { if (IsWin_Less(checker.WinNumbers, num)) { bonusLevelList.Add(1); } else { p.Calculate(num, BallNumber - 1, (item) => { if (IsWin_Less(checker.WinNumbers, item)) { bonusLevelList.Add(2); return(false); } return(true); }); } }); } else if (BallNumber == 4 || BallNumber == 5) { var p = new Combination(); p.Calculate(AnteCodeNumbers, BallNumber, (num) => { if (IsWin_Less(checker.WinNumbers, num)) { bonusLevelList.Add(1); } else { var isWin = false; p.Calculate(num, BallNumber - 1, (item) => { if (IsWin_Less(checker.WinNumbers, item)) { isWin = true; bonusLevelList.Add(2); return(false); } return(true); }); if (!isWin) { p.Calculate(num, BallNumber - 2, (item) => { if (IsWin_Less(checker.WinNumbers, item)) { bonusLevelList.Add(3); return(false); } return(true); }); } } }); } else { throw new ArgumentOutOfRangeException("通选好运不支持的玩法 - 选" + BallNumber); } return(bonusLevelList.OrderBy((i) => i).ToList()); }
public IList <int> CaculateBonus(string antecode, string winNumber) { string msg; if (!CheckAntecode(antecode, out msg)) { throw new AntecodeFormatException(GameCode, GameType, antecode, "投注号码格式错误 - " + msg); } var checker = KaSon.FrameWork.Analyzer.AnalyzerFactory.AnalyzerFactory.GetWinNumberAnalyzer(GameCode, GameType); if (!checker.CheckWinNumber(winNumber, out msg)) { throw new AntecodeFormatException(GameCode, GameType, winNumber, "中奖号码格式错误 - " + msg); } var red_dan = AnteCodeNumbers[0].Split(Spliter_Level2); var red_tuo = AnteCodeNumbers[1].Split(Spliter_Level2); string[] blue_dan, blue_tuo; if (NeedLastDan) { blue_dan = AnteCodeNumbers[2].Split(Spliter_Level2); blue_tuo = AnteCodeNumbers[3].Split(Spliter_Level2); } else { blue_dan = new string[0]; blue_tuo = AnteCodeNumbers[2].Split(Spliter_Level2); } var red_winNumber = checker.WinNumbers[0].Split(Spliter_Level2); var blue_winNumber = checker.WinNumbers[1].Split(Spliter_Level2); var list = new List <int>(); var p = new Combination(); p.Calculate(red_tuo, BallNumber_First - red_dan.Length, (item_red) => { p.Calculate(blue_tuo, BallNumber_Last - blue_dan.Length, (item_blue) => { var redList = new List <string>(red_dan); redList.AddRange(item_red); var count_red = GetSameCodeCount(redList.ToArray(), red_winNumber); var blueList = new List <string>(blue_dan); blueList.AddRange(item_blue); var count_blue = GetSameCodeCount(blueList.ToArray(), blue_winNumber); switch (GameCode) { case "SSQ": if (count_red == 6 && count_blue == 1) { list.Add(1); } else if (count_red == 6 && count_blue == 0) { list.Add(2); } else if (count_red == 5 && count_blue == 1) { list.Add(3); } else if ((count_red == 5 && count_blue == 0) || (count_red == 4 && count_blue == 1)) { list.Add(4); } else if ((count_red == 4 && count_blue == 0) || (count_red == 3 && count_blue == 1)) { list.Add(5); } else if (count_blue == 1) { list.Add(6); } break; case "DLT": if (count_red == 5 && count_blue == 2) { list.Add(1); } else if (count_red == 5 && count_blue == 1) { list.Add(2); } else if ((count_red == 5 && count_blue == 0) || (count_red == 4 && count_blue == 2)) { list.Add(3); } //else if (count_red == 4 && count_blue == 2) //{ // list.Add(4); //} else if ((count_red == 4 && count_blue == 1) || (count_red == 3 && count_blue == 2)) { list.Add(4); } //else if ((count_red == 4 && count_blue == 0) || (count_red == 3 && count_blue == 2)) //{ // list.Add(6); //} else if ((count_red == 4 && count_blue == 0) || (count_red == 3 && count_blue == 1) || (count_red == 2 && count_blue == 2)) { list.Add(5); } else if ((count_red == 3 && count_blue == 0) || (count_red == 1 && count_blue == 2) || (count_red == 2 && count_blue == 1) || (count_red == 0 && count_blue == 2)) { list.Add(6); } break; default: throw new ArgumentOutOfRangeException("不支持的彩种 - " + GameCode); } }); }); return(list); }
public SportBonusResult CaculateBonus(ISportAnteCode[] antecodeList, ISportResult[] winNumberList) { string msg; if (!CheckAntecode(antecodeList, out msg)) { throw new AntecodeFormatException(GameCode, GameType, "过关足球", "投注号码格式错误 - " + msg); } if (!CheckWinNumbers(antecodeList, winNumberList, out msg)) { throw new AntecodeFormatException(GameCode, GameType, "过关足球", "比赛结果开奖格式错误 - " + msg); } var result = new SportBonusResult { IsWin = false, BaseCount = BaseCount, AnteDanCount = DanNumbers.Length, AnteTuoCount = TuoNumbers.Length, AnteTotalCount = antecodeList.Length, HitDanCount = 0, HitTuoCount = 0, HitTotalCount = 0, BonusCount = 0, HitDanMatchIdList = new List <string>(), HitTuoMatchIdList = new List <string>(), HitTotalMatchIdList = new List <string>(), BonusHitMatchIdListCollection = new List <string[]>(), }; var cancelCount = 1; var hitList = new List <ISportAnteCode>(antecodeList); var cancelList = new Dictionary <string, int>(); for (int i = hitList.Count - 1; i >= 0; i--) { var ante = hitList[i]; var win = winNumberList.FirstOrDefault(a => a.GetMatchId(GameCode).Equals(ante.MatchId)); if (win == null) { throw new Exception("计算派奖的比赛在已开奖的比赛中不存在 - " + ante.MatchId); } string winResult; var gameType = string.IsNullOrEmpty(ante.GameType) ? GameType : ante.GameType; if (IsResultFromAnteCode) { winResult = ante.GetMatchResult(GameCode, gameType, win.GetFullMatchScore(GameCode)); if (string.IsNullOrEmpty(winResult)) { winResult = win.GetMatchResult(GameCode, gameType); } } else { winResult = win.GetMatchResult(GameCode, gameType); } if (winResult != CancelMatchResultFlag && !ante.AnteCode.Split(',').Contains(winResult)) { hitList.RemoveAt(i); } else { if (winResult == CancelMatchResultFlag && ante.Length > 1) { cancelCount *= ante.Length; cancelList.Add(ante.MatchId, 1); } if (ante.IsDan) { result.HitDanCount++; result.HitDanMatchIdList.Add(ante.MatchId); } else { result.HitTuoCount++; result.HitTuoMatchIdList.Add(ante.MatchId); } result.HitTotalCount++; result.HitTotalMatchIdList.Add(ante.MatchId); } } if (result.HitDanCount < result.AnteDanCount) { return(result); } if (result.HitTotalCount < result.BaseCount) { return(result); } result.IsWin = true; if (result.BaseCount == result.AnteDanCount) { result.BonusCount++; var tmp = new List <string>(); tmp.AddRange(result.HitDanMatchIdList); result.BonusHitMatchIdListCollection.Add(tmp.OrderBy(m => m).ToArray()); } else { var c = new Combination(); c.Calculate(result.HitTuoMatchIdList.ToArray(), result.BaseCount - result.AnteDanCount, (arr) => { var tmp = new List <string>(); tmp.AddRange(result.HitDanMatchIdList); tmp.AddRange(arr); var t = GetBonusCount(cancelList, tmp.ToArray()); result.BonusCount += t; for (int i = 0; i < t; i++) { result.BonusHitMatchIdListCollection.Add(tmp.OrderBy(m => m).ToArray()); } }); } return(result); }
public int AnalyzeAnteCode(ISportAnteCode[] antecodeList) { string msg; if (!CheckAntecode(antecodeList, out msg)) { throw new AntecodeFormatException(GameCode, GameType, "过关足球", "投注号码格式错误 - " + msg); } var tmp = antecodeList.Where(a => !a.IsDan).ToArray(); var danList = antecodeList.Where(a => a.IsDan).ToArray(); var c = new Combination(); var ac = new ArrayCombination(); var totalCount = 0; ////new ////按比赛编号组成二维数组 //var totalCodeList = new List<ISportAnteCode[]>(); //foreach (var g in tmp.GroupBy(p => p.MatchId)) //{ // totalCodeList.Add(tmp.Where(p => p.MatchId == g.Key).ToArray()); //} //if (this.GameType == "HH") //{ // ac.Calculate(totalCodeList.ToArray(), (match) => // { // c.Calculate(match, BaseCount - danList.Count(), (tuoArr) => // { // totalCount++; // }); // }); //} //else //{ // c.Calculate(totalCodeList.ToArray(), BaseCount - danList.Count(), (arr2) => // { // ac.Calculate(arr2, (tuoArr) => // { // var count = 1; // foreach (var item in tuoArr) // { // count *= item.AnteCode.Split(',').Length; // } // totalCount += count; // }); // }); //} #region old c.Calculate <ISportAnteCode>(tmp, BaseCount - danList.Length, (list) => { var count = 1; foreach (var t in list) { count *= t.Length; } totalCount += count; }); if (totalCount == 0) { totalCount = 1; } foreach (var dan in danList) { totalCount *= dan.Length; } #endregion return(totalCount); }
public IList <int> CaculateBonus(string antecode, string winNumber) { string msg; if (!CheckAntecode(antecode, out msg)) { throw new AntecodeFormatException(GameCode, GameType, antecode, "投注号码格式错误 - " + msg); } var checker = KaSon.FrameWork.Analyzer.AnalyzerFactory.AnalyzerFactory.GetWinNumberAnalyzer(GameCode, GameType); if (!checker.CheckWinNumber(winNumber, out msg)) { throw new AntecodeFormatException(GameCode, GameType, winNumber, "中奖号码格式错误 - " + msg); } var red_antecode = AnteCodeNumbers[0].Split(Spliter_Level2); var blue_antecode = AnteCodeNumbers[1].Split(Spliter_Level2); var red_winNumber = checker.WinNumbers[0].Split(Spliter_Level2); var blue_winNumber = checker.WinNumbers[1].Split(Spliter_Level2); var list = new List <int>(); var p = new Combination(); p.Calculate(red_antecode, BallNumber_First, (item_red) => { p.Calculate(blue_antecode, BallNumber_Last, (item_blue) => { var redCount = GetSameCodeCount(item_red, red_winNumber); var blueCount = GetSameCodeCount(item_blue, blue_winNumber); switch (GameCode) { case "SSQ": if (redCount == 6 && blueCount == 1) { list.Add(1); } else if (redCount == 6 && blueCount == 0) { list.Add(2); } else if (redCount == 5 && blueCount == 1) { list.Add(3); } else if ((redCount == 5 && blueCount == 0) || (redCount == 4 && blueCount == 1)) { list.Add(4); } else if ((redCount == 4 && blueCount == 0) || (redCount == 3 && blueCount == 1)) { list.Add(5); } else if (blueCount == 1) { list.Add(6); } break; case "DLT": if (redCount == 5 && blueCount == 2) { list.Add(1); } else if (redCount == 5 && blueCount == 1) { list.Add(2); } else if ((redCount == 5 && blueCount == 0) || (redCount == 4 && blueCount == 2)) { list.Add(3); } //else if (redCount == 4 && blueCount == 2) //{ // list.Add(4); //} else if ((redCount == 4 && blueCount == 1) || (redCount == 3 && blueCount == 2)) { list.Add(4); } //else if ((redCount == 4 && blueCount == 0) || (redCount == 3 && blueCount == 2)) //{ // list.Add(6); //} else if ((redCount == 4 && blueCount == 0) || (redCount == 3 && blueCount == 1) || (redCount == 2 && blueCount == 2)) { list.Add(5); } else if ((redCount == 3 && blueCount == 0) || (redCount == 1 && blueCount == 2) || (redCount == 2 && blueCount == 1) || (redCount == 0 && blueCount == 2)) { list.Add(6); } break; default: throw new ArgumentOutOfRangeException("不支持的彩种 - " + GameCode); } }); }); return(list); }
/// <summary> /// 计算单张票中,最大最小中奖金额(M串N) /// 暂只计算了JCZQ JCLQ /// </summary> public static void GetTicketMinMoneyOrMaxMoney_MN(string playType, string betContent, string betOdds, out decimal minMoney, out decimal maxMoney) { minMoney = 0M; maxMoney = 0M; //M_N var chuanArray = playType.Split('_'); if (chuanArray.Length != 2) { return; } var a = int.Parse(chuanArray[0]); var b = int.Parse(chuanArray[1]); if (b <= 1) { return; } //串关包括的M串1种类 var countList = AnalyzeChuanJC(a, b); var c = new Combination(); //var betContent = "SPF_140709001_3,1/SPF_140709052_1/BRQSPF_140709053_3,0/SPF_140709054_3"; //var betOdds = "140709001_3|1.5200,1|3.7200,0|4.9500/140709052_3|1.8300,1|3.5000,0|3.3600/140709053_3|3.2000,1|3.4500,0|1.9200/140709054_3|2.8800,1|3.5500,0|2.0000"; //拆分odds var oddstrArray = betOdds.Split(new string[] { "/" }, StringSplitOptions.RemoveEmptyEntries); //投注内容 var betContentArray = betContent.Split(new string[] { "/" }, StringSplitOptions.RemoveEmptyEntries); //投注的比赛 var betMatchIdList = new List <string>(); #region 查找出投注的比赛 foreach (var contentItem in betContentArray) { var matchId = string.Empty; var content = string.Empty; //140709051_2,3 //SPF_140709001_3,1 var array = contentItem.Split(new string[] { "_" }, StringSplitOptions.RemoveEmptyEntries); switch (array.Length) { case 2: matchId = array[0]; break; case 3: matchId = array[1]; break; default: break; } if (!betMatchIdList.Contains(matchId)) { betMatchIdList.Add(matchId); } } #endregion var tempMin = 0M; var tempMax = 0M; foreach (var m in countList) { c.Calculate(betMatchIdList.ToArray(), m, (arr) => { var tempBetContentList = new List <string>(); var tempBetOddsList = new List <string>(); foreach (var item in arr) { foreach (var bc in betContentArray) { if (bc.IndexOf(item) >= 0) { tempBetContentList.Add(bc); } } foreach (var bo in oddstrArray) { if (bo.IndexOf(item) >= 0) { tempBetOddsList.Add(bo); } } } var min = 0M; var max = 0M; GetTicketMinMoneyOrMaxMoney(string.Join("/", tempBetContentList.ToArray()), string.Join("/", tempBetOddsList.ToArray()), out min, out max); if (tempMin == 0M) { tempMin = min; } if (min < tempMin) { tempMin = min; } tempMax += max; }); } minMoney = tempMin; maxMoney = tempMax; }
public IList <int> CaculateBonus(string antecode, string winNumber) { string msg; if (!CheckAntecode(antecode, out msg)) { throw new AntecodeFormatException(GameCode, GameType, antecode, "投注号码格式错误 - " + msg); } var checker = AnalyzerFactory.GetWinNumberAnalyzer(GameCode, GameType); if (!checker.CheckWinNumber(winNumber, out msg)) { throw new AntecodeFormatException(GameCode, GameType, winNumber, "中奖号码格式错误 - " + msg); } var bonusLevelList = new List <int>(); if (BallNumber == 3 || BallNumber == 4) { var p = new Combination(); p.Calculate(AnteCodeNumbers, BallNumber, (num) => { if (IsWin_Less(checker.WinNumbers, num)) { bonusLevelList.Add(1); } else { p.Calculate(num, BallNumber - 1, (item) => { if (IsWin_Less(checker.WinNumbers, item)) { bonusLevelList.Add(2); return(false); } return(true); }); } }); } else if (BallNumber == 5) { var p = new Combination(); p.Calculate(AnteCodeNumbers, BallNumber, (num) => { if (IsWin_Less(checker.WinNumbers, num)) { bonusLevelList.Add(1); } else { var isWin = false; p.Calculate(num, BallNumber - 1, (item) => { if (IsWin_Less(checker.WinNumbers, item)) { isWin = true; bonusLevelList.Add(2); return(false); } return(true); }); if (!isWin) { p.Calculate(num, BallNumber - 2, (item) => { if (IsWin_Less(checker.WinNumbers, item)) { bonusLevelList.Add(3); return(false); } return(true); }); } } }); } else if (BallNumber <= TotalNumber) // 任选的数量小于等于总号码数。如:任选四、任选五 { var p = new Combination(); p.Calculate(AnteCodeNumbers, BallNumber, (num) => { if (IsWin_Less(checker.WinNumbers, num)) { bonusLevelList.Add(0); } }); } else // 任选的数量大于等于总号码数。如:任选七 { var winTime = 0; foreach (var item in checker.WinNumbers) { if (AnteCodeNumbers.Contains(item)) { winTime++; } } if (winTime == TotalNumber) { var p = new Combination(); p.Calculate(AnteCodeNumbers.Take(AnteCodeNumbers.Length - 5).ToArray(), BallNumber - 5, (item) => { bonusLevelList.Add(0); }); } } return(bonusLevelList); }
public int CheckBettingOrderMoney(List <Sports_AnteCodeInfo> codeList, string gameCode, string gameType, string playType, int amount, decimal schemeTotalMoney, DateTime stopTime, bool isAllow = false, string userId = "") { //验证投注号码 if (stopTime < DateTime.Now) { throw new Exception("投注结束时间不能小于当前时间"); } //验证投注内容是否合法,或是否重复 foreach (var item in codeList) { var oneCodeArray = item.AnteCode.Split(','); if (oneCodeArray.Distinct().Count() != oneCodeArray.Length) { throw new Exception(string.Format("投注号码{0}中包括重复的内容", item.AnteCode)); } BettingHelper.CheckSportAnteCode(gameCode, string.IsNullOrEmpty(item.GameType) ? gameType : item.GameType.ToUpper(), oneCodeArray); } var tmp = playType.Split('|'); var totalMoney = 0M; var totalCount = 0; var c = new Combination(); foreach (var chuan in tmp) { var chuanArray = chuan.Split('_'); if (chuanArray.Length != 2) { continue; } var m = int.Parse(chuanArray[0]); var n = int.Parse(chuanArray[1]); //串关包括的真实串数 var countList = SportAnalyzer.AnalyzeChuan(m, n); if (n > 1) { //3_3类型 c.Calculate(codeList.ToArray(), m, (arr) => { //m场比赛 if (arr.Select(p => p.MatchId).Distinct().Count() == m) { foreach (var count in countList) { //M串1 c.Calculate(arr, count, (a1) => { var cCount = 1; foreach (var t in a1) { cCount *= t.AnteCode.Split(',').Length; } totalCount += cCount; }); } } }); } else { var ac = new ArrayCombination(); var danList = codeList.Where(a => a.IsDan).ToList(); //var tuoList = codeList.Where(a => !a.IsDan).ToList(); var totalCodeList = new List <Sports_AnteCodeInfo[]>(); foreach (var g in codeList.GroupBy(p => p.MatchId)) { totalCodeList.Add(codeList.Where(p => p.MatchId == g.Key).ToArray()); } //3_1类型 foreach (var count in countList) { //c.Calculate(totalCodeList.ToArray(), count - danList.Count, (arr2) => c.Calculate(totalCodeList.ToArray(), count, (arr2) => { ac.Calculate(arr2, (tuoArr) => { #region 拆分组合票 var isContainsDan = true; foreach (var dan in danList) { var con = tuoArr.FirstOrDefault(p => p.MatchId == dan.MatchId); if (con == null) { isContainsDan = false; break; } } if (isContainsDan) { var cCount = 1; foreach (var t in tuoArr) { cCount *= t.AnteCode.Split(',').Length; } totalCount += cCount; //if (!isAllow && BusinessHelper.IsSiteLimit(gameCode)) //{ // if (!string.IsNullOrEmpty(userId) && !BusinessHelper.IsSpecificUser(userId))//如果是特定用户,则不限制投注 // { // if ((cCount * amount * 2M) < 50) // throw new Exception("您好,根据您投注的内容将产生多张彩票,每张彩票金额不足50元,请您增加倍数以达到出票条件。"); // } //} } #endregion }); }); } } } totalMoney = totalCount * amount * 2M; if (totalMoney != schemeTotalMoney) { throw new ArgumentException(string.Format("订单金额不正确,应该为:{0};实际为:{1}。", totalMoney, schemeTotalMoney)); } return(totalCount); }