關於足彩任選九的組合算法

      最近互聯網彩票被國家叫停進行整改了,整改後互聯網公司獲取利潤確定會下降,可是不得不說中國的互聯網彩票銷售須要進行整改了,雖然對行業是陣痛,可是可以更好的規範彩票市場,對整個市場都會起到積極的做用。前段時間在作互聯網彩票時也遇到了一些問題,特別是足彩任選九的複試組合算法。算法

     足彩標註投注玩法:從14場比賽中任意選擇9場比賽,每場比賽選擇1種比賽結果爲1注,每場比賽最多可選3種結果,單注最高獎金500萬元!標準投注時可選擇1~8場比賽結果做爲膽碼,其它比賽場次結果做爲拖碼進行膽拖投注,單注最高獎金500萬元! ide

     足彩標準投注是隻從14場比賽中選9場比賽,而咱們提交給第三方接口的必須是標準投注方式,也就是每次提交投注都是隻能選擇九場進行提交,可是在大部分的互聯網彩票投注站都容許超過9場比賽的一個投注方式,這裏就是各個互聯網投注終端本身作的一個循環提交的處理了,因此這個須要一個本身組合算法,下面是該算法的代碼,用C#代碼實現:ui

    這是足彩類型spa

  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


    足彩類型中的屬性有一個是場次索引,經過足彩的索引進行組合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值求和就能知道該複試一共選擇了多少注,須要多少錢,可以再未提交以前知道須要的投注注數和總金額。最後循環調用投注接口把投注結果提交上去。blog

     爲了實現功能而作的,若是有更好的組合公式的請提出建議,謝謝!索引

相關文章
相關標籤/搜索