关于足彩任选九的组合算法

      最近互联网彩票被国家叫停进行整改了,整改后互联网公司获取利润肯定会降低,但是不得不说中国的互联网彩票销售需要进行整改了,虽然对行业是阵痛,但是能够更好的规范彩票市场,对整个市场都会起到积极的作用。前段时间在做互联网彩票时也遇到了一些问题,特别是足彩任选九的复试组合算法。

     足彩标注投注玩法:从14场比赛中任意选择9场比赛,每场比赛选择1种比赛结果为1注,每场比赛最多可选3种结果,单注最高奖金500万元!标准投注时可选择1~8场比赛结果作为胆码,其它比赛场次结果作为拖码进行胆拖投注,单注最高奖金500万元! 

     足彩标准投注是只从14场比赛中选9场比赛,而我们提交给第三方接口的必须是标准投注方式,也就是每次提交投注都是只能选择九场进行提交,但是在大部分的互联网彩票投注站都允许超过9场比赛的一个投注方式,这里就是各个互联网投注终端自己做的一个循环提交的处理了,所以这个需要一个自己组合算法,下面是该算法的代码,用C#代码实现:

    这是足彩类型

  1  public class FootBallItem : PropertyChangedBase
  2     {
  3         #region Property
  4         private string lotteryId;
  5         /// <summary>
  6         /// 彩种编号
  7         /// </summary>
  8         public string LotteryId
  9         {
 10             get { return lotteryId; }
 11             set { lotteryId = value; }
 12         }
 13 
 14         private string endTime;
 15         /// <summary>
 16         /// 结束时间
 17         /// </summary>
 18         public string EndTime
 19         {
 20             get { return endTime; }
 21             set { endTime = value; }
 22         }
 23         private string finalScore;
 24 
 25         public string FinalScore
 26         {
 27             get { return finalScore; }
 28             set { finalScore = value; }
 29         }
 30 
 31         private string guestName;
 32         /// <summary>
 33         /// 客场
 34         /// </summary>
 35         public string GuestName
 36         {
 37             get { return guestName; }
 38             set { guestName = value; }
 39         }
 40         private string index;
 41         /// <summary>
 42         /// 序列
 43         /// </summary>
 44         public string Index
 45         {
 46             get { return index; }
 47             set { index = value; }
 48         }
 49 
 50         private string leageName;
 51         /// <summary>
 52         /// 赛事
 53         /// </summary>
 54         public string LeageName
 55         {
 56             get { return leageName; }
 57             set { leageName = value; }
 58         }
 59 
 60         private string masterName;
 61         /// <summary>
 62         /// 主场
 63         /// </summary>
 64         public string MasterName
 65         {
 66             get { return masterName; }
 67             set { masterName = value; }
 68         }
 69         private string result;
 70 
 71         public string Result
 72         {
 73             get { return result; }
 74             set { result = value; }
 75         }
 76         private string resultDes;
 77 
 78         public string ResultDes
 79         {
 80             get { return resultDes; }
 81             set { resultDes = value; }
 82         }
 83         private string scoreAtHalf;
 84 
 85         public string ScoreAtHalf
 86         {
 87             get { return scoreAtHalf; }
 88             set { scoreAtHalf = value; }
 89         }
 90         private string secondHalfTheScore;
 91 
 92         public string SecondHalfTheScore
 93         {
 94             get { return secondHalfTheScore; }
 95             set { secondHalfTheScore = value; }
 96         }
 97 
 98         private string startTime;
 99         /// <summary>
100         /// 开赛时间
101         /// </summary>
102         public string StartTime
103         {
104             get { return startTime; }
105             set { startTime = value; }
106         }
107 
108         private bool _scoreThree;
109         /// <summary>
110         /// 全场赢或者客场进3个球及以上
111         /// </summary>
112         public bool ScoreThree
113         {
114             get { return _scoreThree; }
115             set
116             {
117                 string strNum = LotteryId.Equals("302") ? "3+" : "3";
118                 if (value)
119                 {
120                     StrFootBallNumber += strNum;
121                     nSelectedCount++;
122                 }
123                 else
124                 {
125                     nSelectedCount--;
126                     if (StrFootBallNumber.Contains(strNum))
127                     {
128                         StrFootBallNumber = StrFootBallNumber.Replace(strNum, null);
129                     }
130                 }
131                 _scoreThree = value;
132                 NotifyOfPropertyChange("ScoreThree");
133             }
134         }
135 
136         private bool _scoreTwo;
137         /// <summary>
138         /// 全场平或者客场进2个球
139         /// </summary>
140         public bool ScoreTwo
141         {
142             get { return _scoreTwo; }
143             set
144             {
145                 string strNum = LotteryId.Equals("302") ? "2" : "1";
146                 if (value)
147                 {
148                     StrFootBallNumber += strNum;
149                     nSelectedCount++;
150                 }
151                 else
152                 {
153                     nSelectedCount--;
154                     if (StrFootBallNumber.Contains(strNum))
155                     {
156                         StrFootBallNumber = StrFootBallNumber.Replace(strNum, null);
157                     }
158                 }
159                 _scoreTwo = value;
160                 NotifyOfPropertyChange("ScoreTwo");
161             }
162         }
163 
164         private bool _scoreOne;
165         /// <summary>
166         /// 全场负或者客场进1个球
167         /// </summary>
168         public bool ScoreOne
169         {
170             get { return _scoreOne; }
171             set
172             {
173                 string strNum = LotteryId.Equals("302") ? "1" : "0";
174                 if (value)
175                 {
176                     StrFootBallNumber += strNum;
177                     nSelectedCount++;
178                 }
179                 else
180                 {
181                     nSelectedCount--;
182                     if (StrFootBallNumber.Contains(strNum))
183                     {
184                         StrFootBallNumber = StrFootBallNumber.Replace(strNum, null);
185                     }
186                 }
187                 _scoreOne = value;
188                 NotifyOfPropertyChange("ScoreOne");
189             }
190         }
191 
192         private bool _scoreZero;
193         /// <summary>
194         /// 客场进0个球
195         /// </summary>
196         public bool ScoreZero
197         {
198             get { return _scoreZero; }
199             set
200             {
201                 if (value)
202                 {
203                     StrFootBallNumber += "0";
204                     nSelectedCount++;
205                 }
206                 else
207                 {
208                     nSelectedCount--;
209                     if (StrFootBallNumber.Contains("0"))
210                     {
211                         StrFootBallNumber = StrFootBallNumber.Replace("0", null);
212                     }
213                 }
214                 _scoreZero = value;
215                 NotifyOfPropertyChange("ScoreZero");
216             }
217         }
218 
219         private bool _scoreThreeHalf;
220         /// <summary>
221         /// 半场赢或者主场进3个球及以上
222         /// </summary>
223         public bool ScoreThreeHalf
224         {
225             get { return _scoreThreeHalf; }
226             set
227             {
228                 string strNum = LotteryId.Equals("302") ? "3+" : "3";
229                 if (value)
230                 {
231                     strNumberHalf += strNum;
232                     nSelectHalfCount++;
233                 }
234                 else
235                 {
236                     nSelectHalfCount--;
237                     if (strNumberHalf.Contains(strNum))
238                     {
239                         strNumberHalf = strNumberHalf.Replace(strNum, null);
240                     }
241                 }
242                 _scoreThreeHalf = value;
243                 NotifyOfPropertyChange("ScoreThreeHalf");
244             }
245         }
246 
247         private bool _scoreTwoHalf;
248         /// <summary>
249         /// 半场平或者主场2个球
250         /// </summary>
251         public bool ScoreTwoHalf
252         {
253             get { return _scoreTwoHalf; }
254             set
255             {
256                 string strNum = LotteryId.Equals("302") ? "2" : "1";
257                 if (value)
258                 {
259                     nSelectHalfCount++;
260                     strNumberHalf += strNum;
261                 }
262                 else
263                 {
264                     nSelectHalfCount--;
265                     if (strNumberHalf.Contains(strNum))
266                     {
267                         strNumberHalf = strNumberHalf.Replace(strNum, null);
268                     }
269                 }
270                 _scoreTwoHalf = value;
271                 NotifyOfPropertyChange("ScoreTwoHalf");
272             }
273         }
274 
275         private bool _scoreOneHalf;
276         /// <summary>
277         /// 半场负或者主场进1个球
278         /// </summary>
279         public bool ScoreOneHalf
280         {
281             get { return _scoreOneHalf; }
282             set
283             {
284                 string strNum = LotteryId.Equals("302") ? "1" : "0";
285                 if (value)
286                 {
287                     nSelectHalfCount++;
288                     strNumberHalf += strNum;
289                 }
290                 else
291                 {
292                     nSelectHalfCount--;
293                     if (strNumberHalf.Contains(strNum))
294                     {
295                         strNumberHalf = strNumberHalf.Replace(strNum, null);
296                     }
297                 }
298                 _scoreOneHalf = value;
299                 NotifyOfPropertyChange("ScoreOneHalf");
300             }
301         }
302 
303         private bool _scoreZeroHalf;
304         /// <summary>
305         /// 主场进0个球
306         /// </summary>
307         public bool ScoreZeroHalf
308         {
309             get { return _scoreZeroHalf; }
310             set
311             {
312                 if (value)
313                 {
314                     nSelectHalfCount++;
315                     strNumberHalf += "0";
316                 }
317                 else
318                 {
319                     nSelectHalfCount--;
320                     if (strNumberHalf.Contains("0"))
321                     {
322                         strNumberHalf = strNumberHalf.Replace("0", null);
323                     }
324                 }
325                 _scoreZeroHalf = value;
326                 NotifyOfPropertyChange("ScoreZeroHalf");
327             }
328         }
329 
330         private string strNumber = "";
331         /// <summary>
332         /// 单场选择记录
333         /// </summary>
334         public string StrFootBallNumber
335         {
336             get { return strNumber; }
337             set { strNumber = value; }
338         }
339 
340         private string strNumberHalf = "";
341         /// <summary>
342         /// 半场选择记录
343         /// </summary>
344         public string StrFootBallNumberHalf
345         {
346             get { return strNumberHalf; }
347             set { strNumberHalf = value; }
348         }
349 
350         private int nselectedcount;
351         /// <summary>
352         /// 全场已选择(胜、负、平)的数量
353         /// </summary>
354         public int nSelectedCount
355         {
356             get { return nselectedcount; }
357             set { nselectedcount = value; }
358         }
359         private int nselecthalfcount;
360         /// <summary>
361         /// 半场已选择(胜、负、平)的数量
362         /// </summary>
363         public int nSelectHalfCount
364         {
365             get { return nselecthalfcount; }
366             set { nselecthalfcount = value; }
367         }
368         #endregion
369     }
View Code


    足彩类型中的属性有一个是场次索引,通过足彩的索引进行组合

  1  
  2 
  3 public static Dictionary<string, int> ResumeCount(List<FootBallItem> footBallLists)
  4         {
  5             Dictionary<string, int> dicList = new Dictionary<string, int>();
  6             int dicCount = footBallLists.Count();
  7             for (int i = 0; i <= dicCount - 9; i++)
  8             {
  9                 for (int i1 = i + 1; i1 <= dicCount - 8; i1++)
 10                 {
 11                     for (int i2 = i1 + 1; i2 <= dicCount - 7; i2++)
 12                     {
 13                         for (int i3 = i2 + 1; i3 <= dicCount - 6; i3++)
 14                         {
 15                             for (int i4 = i3 + 1; i4 <= dicCount - 5; i4++)
 16                             {
 17                                 for (int i5 = i4 + 1; i5 <= dicCount - 4; i5++)
 18                                 {
 19                                     for (int i6 = i5 + 1; i6 <= dicCount - 3; i6++)
 20                                     {
 21                                         for (int i7 = i6 + 1; i7 <= dicCount - 2; i7++)
 22                                         {
 23                                             for (int i8 = i7 + 1; i8 <= dicCount - 1; i8++)
 24                                             {
 25                                                 int sum = 1;
 26                                                 int index =0;
 27                                                 StringBuilder sb = new StringBuilder();
 28                                                 for (int j = 1; j <= 14; j++)
 29                                                 {
 30                                                     if (int.Parse(footBallLists[i].Index)==j)
 31                                                     {
 32                                                         index=0;
 33                                                         if (footBallLists[i].ScoreOne)
 34                                                         {
 35                                                             sb.Append("0");
 36                                                             index++;
 37                                                         }
 38                                                         if (footBallLists[i].ScoreTwo)
 39                                                         {
 40                                                             sb.Append("1");
 41                                                             index++;
 42                                                         }
 43                                                         if (footBallLists[i].ScoreThree)
 44                                                         {
 45                                                             sb.Append("3");
 46                                                             index++;
 47                                                         }
 48                                                         sb.Append("*");
 49                                                         sum *=index;
 50                                                     }
 51                                                     else if (int.Parse(footBallLists[i1].Index) == j)
 52                                                     {
 53                                                         index = 0;
 54                                                         if (footBallLists[i1].ScoreOne)
 55                                                         {
 56                                                             sb.Append("0");
 57                                                             index++;
 58                                                         }
 59                                                         if (footBallLists[i1].ScoreTwo)
 60                                                         {
 61                                                             sb.Append("1");
 62                                                             index++;
 63                                                         }
 64                                                         if (footBallLists[i1].ScoreThree)
 65                                                         {
 66                                                             sb.Append("3");
 67                                                             index++;
 68                                                         }
 69                                                         sb.Append("*");
 70                                                         sum *= index;
 71                                                     }
 72                                                     else if (int.Parse(footBallLists[i2].Index) == j)
 73                                                     {
 74                                                         index = 0;
 75                                                         if (footBallLists[i2].ScoreOne)
 76                                                         {
 77                                                             sb.Append("0");
 78                                                             index++;
 79                                                         }
 80                                                         if (footBallLists[i2].ScoreTwo)
 81                                                         {
 82                                                             sb.Append("1");
 83                                                             index++;
 84                                                         }
 85                                                         if (footBallLists[i2].ScoreThree)
 86                                                         {
 87                                                             sb.Append("3");
 88                                                             index++;
 89                                                         }
 90                                                         sb.Append("*");
 91                                                         sum *= index;
 92                                                     }
 93                                                     else if (int.Parse(footBallLists[i3].Index) == j)
 94                                                     {
 95                                                         index = 0;
 96                                                         if (footBallLists[i3].ScoreOne)
 97                                                         {
 98                                                             sb.Append("0");
 99                                                             index++;
100                                                         }
101                                                         if (footBallLists[i3].ScoreTwo)
102                                                         {
103                                                             sb.Append("1");
104                                                             index++;
105                                                         }
106                                                         if (footBallLists[i3].ScoreThree)
107                                                         {
108                                                             sb.Append("3");
109                                                             index++;
110                                                         }
111                                                         sb.Append("*");
112                                                         sum *= index;
113                                                     }
114                                                     else if (int.Parse(footBallLists[i4].Index) == j)
115                                                     {
116                                                         index = 0;
117                                                         if (footBallLists[i4].ScoreOne)
118                                                         {
119                                                             sb.Append("0");
120                                                             index++;
121                                                         }
122                                                         if (footBallLists[i4].ScoreTwo)
123                                                         {
124                                                             sb.Append("1");
125                                                             index++;
126                                                         }
127                                                         if (footBallLists[i4].ScoreThree)
128                                                         {
129                                                             sb.Append("3");
130                                                             index++;
131                                                         }
132                                                         sb.Append("*");
133                                                         sum *= index;
134                                                     }
135                                                     else if (int.Parse(footBallLists[i5].Index) == j)
136                                                     {
137                                                         index = 0;
138                                                         if (footBallLists[i5].ScoreOne)
139                                                         {
140                                                             sb.Append("0");
141                                                             index++;
142                                                         }
143                                                         if (footBallLists[i5].ScoreTwo)
144                                                         {
145                                                             sb.Append("1");
146                                                             index++;
147                                                         }
148                                                         if (footBallLists[i5].ScoreThree)
149                                                         {
150                                                             sb.Append("3");
151                                                             index++;
152                                                         }
153                                                         sb.Append("*");
154                                                         sum *= index;
155                                                     }
156                                                     else if (int.Parse(footBallLists[i6].Index) == j)
157                                                     {
158                                                         index = 0;
159                                                         if (footBallLists[i6].ScoreOne)
160                                                         {
161                                                             sb.Append("0");
162                                                             index++;
163                                                         }
164                                                         if (footBallLists[i6].ScoreTwo)
165                                                         {
166                                                             sb.Append("1");
167                                                             index++;
168                                                         }
169                                                         if (footBallLists[i6].ScoreThree)
170                                                         {
171                                                             sb.Append("3");
172                                                             index++;
173                                                         }
174                                                         sb.Append("*");
175                                                         sum *= index;
176                                                     }
177                                                     else if (int.Parse(footBallLists[i7].Index) == j)
178                                                     {
179                                                         index = 0;
180                                                         if (footBallLists[i7].ScoreOne)
181                                                         {
182                                                             sb.Append("0");
183                                                             index++;
184                                                         }
185                                                         if (footBallLists[i7].ScoreTwo)
186                                                         {
187                                                             sb.Append("1");
188                                                             index++;
189                                                         }
190                                                         if (footBallLists[i7].ScoreThree)
191                                                         {
192                                                             sb.Append("3");
193                                                             index++;
194                                                         }
195                                                         sb.Append("*");
196                                                         sum *= index;
197                                                     }
198                                                     else if (int.Parse(footBallLists[i8].Index) == j)
199                                                     {
200                                                         index = 0;
201                                                         if (footBallLists[i8].ScoreOne)
202                                                         {
203                                                             sb.Append("0");
204                                                             index++;
205                                                         }
206                                                         if (footBallLists[i8].ScoreTwo)
207                                                         {
208                                                             sb.Append("1");
209                                                             index++;
210                                                         }
211                                                         if (footBallLists[i8].ScoreThree)
212                                                         {
213                                                             sb.Append("3");
214                                                             index++;
215                                                         }
216                                                         sb.Append("*");
217                                                         sum *= index;
218                                                     }
219                                                     else
220                                                     {
221                                                         sb.Append("4*");
222                                                     }
223                                                 }
224 
225                                                 dicList.Add(sb.Remove(sb.Length - 1, 1).ToString(), sum);
226                                             }
227                                         }
228                                     }
229                                 }
230                             }
231                         }
232                     }
233                 }
234             }
235             return dicList;
236         }
View Code

    返回一个字典集合,字典的key为9场比赛的一个组合,而value为这9场比赛有多长中组合方式,因为一场比赛可以选择三种比赛结果,所以需要知道每一种标准投注有多少注,再把字典中所有的value值求和就能知道该复试一共选择了多少注,需要多少钱,能够再未提交之前知道需要的投注注数和总金额。最后循环调用投注接口把投注结果提交上去。

     为了实现功能而做的,如果有更好的组合公式的请提出建议,谢谢!

posted @ 2015-03-03 10:56  Eric-Li  阅读(3893)  评论(6编辑  收藏  举报