练习之彩票四 计算中奖数(结尾)
分析:
1、双色球复试计算千万不能拆成单注的。有固定算法的。(要不然福彩服务器早垮了)
2、双色球其实特点鲜明,是组合算法 。(只管数字,不管位置 01,02,03 和 03,02,01没区别)
3、福彩3D直选是排列,组三和组六和组合。
4、3D彩票中有个特点就是一份彩票不管复式还是单式中奖都只能是一注(双色球复式能中多注的)。
代码:
双色球:
注(WinAmount,WinAmountWithDan,Rank 三个方法是从360彩票网中脚本转来的)
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using TG.Package.Lottery.Base;
using TG.Package.Lottery.Calculate;
namespace TG.Package.Lottery.Win
{
public class TwoColor : IWinCalculate
{
public TwoColor()
{
}
private const Char SplitChar = ',';
public List<WinDetail> GetWinDetails(ILottery pLottery, Dictionary<NumericType, String> pWinNumber)
{
return GetWinDetailsByLottery(pLottery, pWinNumber);
}
/// <summary>
/// Get WinDetails By Lottery
/// </summary>
/// <param name="pLottery">Lottery</param>
/// <param name="pWinNumber">WinNumber</param>
/// <returns></returns>
private static List<WinDetail> GetWinDetailsByLottery(ILottery pLottery, Dictionary<NumericType, String> pWinNumber)
{
String[] redwins = pWinNumber[NumericType.Red].Split(SplitChar);
String bluewins = pWinNumber[NumericType.Blue];
List<WinDetail> result = new List<WinDetail>();
for (var i = 0; i < pLottery.Count; i++)
{
result.AddRange(GetWinDetailsByWelfareLottery(pLottery[i], redwins, bluewins, pLottery.LotteryIssue));
}
return result;
}
/// <summary>
/// Get WinDetails By WelfareLottery
/// </summary>
/// <param name="pWelfareLottery">WelfareLottery</param>
/// <param name="pRedWinNumbers">Red Win Numbers</param>
/// <param name="pBlueWinNumber"> Blue Win Number</param>
/// <param name="pLotteryIssue">Lottery Issue</param>
/// <returns></returns>
private static List<WinDetail> GetWinDetailsByWelfareLottery(WelfareLottery pWelfareLottery, String[] pRedWinNumbers, String pBlueWinNumber, String pLotteryIssue)
{
Int32[] winnumbers = null;
switch (pWelfareLottery.PlayType)
{
case PlayType.Normal: winnumbers =
GetWinNumberWithNormal(pWelfareLottery.Lottery[NumericType.Red], pWelfareLottery.Lottery[NumericType.Blue], pRedWinNumbers, pBlueWinNumber);
break;
case PlayType.DanTuo: winnumbers =
GetWinNumberWithDan(pWelfareLottery.Lottery[NumericType.Red], pWelfareLottery.Lottery[NumericType.Blue], pWelfareLottery.Lottery[NumericType.Dan], pRedWinNumbers, pBlueWinNumber);
break;
default: throw new FormatException("error: PlayType is error");
}
if (null == winnumbers)
{ throw new FormatException("error: winnumbers is null"); }
return WinAumountToWinDetails(winnumbers, pWelfareLottery, pLotteryIssue);
}
/// <summary>
/// Win Aumount To WinDetails
/// </summary>
/// <param name="pWinAumount">win aumount</param>
/// <param name="pWelfareLottery">Lottery</param>
/// <param name="pLotteryIssue">LotteryIssue</param>
/// <returns></returns>
private static List<WinDetail> WinAumountToWinDetails(Int32[] pWinAumount, WelfareLottery pWelfareLottery, String pLotteryIssue)
{
List<WinDetail> result = new List<WinDetail>();
for (var i = 0; i < pWinAumount.Length; i++)
{
if (pWinAumount[i] < 1)
{
continue;
}
WinDetail temp = new WinDetail();
temp.LotteryIssue = pLotteryIssue;
temp.LotteryNo = pWelfareLottery.ToString();
temp.LotteryType = LotteryType.TwoColor;
temp.PlayType = pWelfareLottery.PlayType;
temp.WinGrade = i + 1;
temp.WinMoney = 0;
temp.WinCount = pWinAumount[i];
result.Add(temp);
}
return result;
}
/// <summary>
/// Get Win number With Normal
/// </summary>
/// <param name="pRed">red buy</param>
/// <param name="pBlue">blue buy</param>
/// <param name="pRedWinNumbers">red match</param>
/// <param name="pBlueWinNumber">blue match</param>
/// <returns></returns>
private static Int32[] GetWinNumberWithNormal(String pRed, String pBlue, String[] pRedWinNumbers, String pBlueWinNumber)
{
Int32 redbuy = (pRed.Length / 3) + 1;
Int32 bluebuy = (pBlue.Length / 3) + 1;
Int32 redmatch = Calculate.NumberHelper.NumberEqual(pRedWinNumbers, pRed);
Int32 bluematch = Calculate.NumberHelper.NumberEqual(new String[] { pBlueWinNumber }, pBlue);
return WinAmount(redbuy, bluebuy, redmatch, bluematch);
}
/// <summary>
/// Get Win Number With Dan
/// </summary>
/// <param name="pRed">red buy</param>
/// <param name="pBlue">blue buy</param>
/// <param name="pDan">dan buy</param>
/// <param name="pRedWinNumbers">red winno</param>
/// <param name="pBlueWinNumber">blue winno</param>
/// <returns></returns>
private static Int32[] GetWinNumberWithDan(String pRed, String pBlue, String pDan, String[] pRedWinNumbers, String pBlueWinNumber)
{
Int32 redbuy = (pRed.Length / 3) + 1;
Int32 bluebuy = (pBlue.Length / 3) + 1;
Int32 danbuy = (pDan.Length / 3) + 1;
Int32 danmatch = Calculate.NumberHelper.NumberEqual(pRedWinNumbers, pDan);
Int32 redmatch = Calculate.NumberHelper.NumberEqual(pRedWinNumbers, pRed);
Int32 bluematch = Calculate.NumberHelper.NumberEqual(new String[] { pBlueWinNumber }, pBlue);
return WinAmountWithDan(danbuy, redbuy, bluebuy, danmatch, redmatch, bluematch);
}
#region Win Amount (not dan)
/// <summary>
/// Win Amount
/// </summary>
/// <param name="rl">red</param>
/// <param name="bl">blue</param>
/// <param name="red">match red</param>
/// <param name="blue">match blue</param>
/// <returns></returns>
private static Int32[] WinAmount(Int32 rl, Int32 bl, Int32 red, Int32 blue)
{
var result = new Int32[] { 0, 0, 0, 0, 0, 0 };
switch (red)
{
case 0:
case 1:
case 2:
#region red=2 blue=1
if (blue > 0)
{
result[5] += Discrete.C(rl, 6);
}
#endregion
break;
case 3:
#region red=3 blue=1
if (blue > 0)
{
result[5] += Discrete.C(rl - red, 4) * Discrete.C(red, 2);
result[5] += Discrete.C(rl - red, 5) * Discrete.C(red, 1);
result[5] += Discrete.C(rl - red, 6);
result[4] += Discrete.C(rl - red, 3);
}
#endregion
break;
case 4:
#region red=4 blue=1
if (blue > 0)
{
result[5] += Discrete.C(rl - red, 6);
result[5] += Discrete.C(rl - red, 5) * Discrete.C(red, 1);
result[5] += Discrete.C(rl - red, 4) * Discrete.C(red, 2);
result[4] += Discrete.C(rl - red, 3) * Discrete.C(red, 3);
result[4] += Discrete.C(rl - red, 2) * Discrete.C(red, 4) * (bl - 1);
result[3] += Discrete.C(rl - red, 2);
}
#endregion
#region red=4 blue=0
else
{
result[4] += Discrete.C(rl - red, 2) * bl;
}
#endregion
break;
case 5:
#region red=5 blue=1
if (blue > 0)
{
result[5] += Discrete.C(rl - red, 6);
result[5] += Discrete.C(rl - red, 5) * Discrete.C(red, 1);
result[5] += Discrete.C(rl - red, 4) * Discrete.C(red, 2);
result[4] += Discrete.C(rl - red, 3) * Discrete.C(red, 3);
result[4] += Discrete.C(rl - red, 2) * Discrete.C(red, 4) * (bl - 1);
result[3] += Discrete.C(rl - red, 2) * Discrete.C(red, 4);
result[3] += Discrete.C(rl - red, 1) * Discrete.C(red, 5) * (bl - 1);
result[2] += Discrete.C(rl - red, 1);
}
#endregion
#region red=5 blue=0
else
{
result[4] += Discrete.C(rl - red, 2) * Discrete.C(red, 4) * bl;
result[3] += Discrete.C(rl - red, 1) * Discrete.C(red, 5) * bl;
}
#endregion
break;
case 6:
#region red=6 blue=1
if (blue > 0)
{
result[5] += Discrete.C(rl - red, 6);
result[5] += Discrete.C(rl - red, 5) * Discrete.C(red, 1);
result[5] += Discrete.C(rl - red, 4) * Discrete.C(red, 2);
result[4] += Discrete.C(rl - red, 3) * Discrete.C(red, 3);
result[4] += Discrete.C(rl - red, 2) * Discrete.C(red, 4) * (bl - 1);
result[3] += Discrete.C(rl - red, 2) * Discrete.C(red, 4);
result[3] += Discrete.C(rl - red, 1) * Discrete.C(red, 5) * (bl - 1);
result[2] += Discrete.C(rl - red, 1) * Discrete.C(red, 5);
result[1] += bl - 1;
result[0]++;
}
#endregion
#region red=6 blue=0
else
{
result[4] += Discrete.C(rl - red, 2) * Discrete.C(red, 4) * bl;
result[3] += Discrete.C(rl - red, 1) * Discrete.C(red, 5) * bl;
result[1] += bl;
}
#endregion
break;
}
return result;
}
#endregion
#region Win Amount With Dan
/// <summary>
/// Win Amount With Dan
/// </summary>
/// <param name="d">dan</param>
/// <param name="t">tuo(red)</param>
/// <param name="b">blue</param>
/// <param name="md">match dan</param>
/// <param name="mt">match tuo(red)</param>
/// <param name="mb">match blue</param>
/// <returns></returns>
private static Int32[] WinAmountWithDan(Int32 d, Int32 t, Int32 b, Int32 md, Int32 mt, Int32 mb)
{
var mtmax = mt <= 6 - d ? mt : 6 - d;
//mt的最大有效值
var MR = new Int32[mtmax + 1];
//命中的红球的个数集合
for (var i = 0; i <= mtmax; i++)
{
MR[i] = md + i;
}
var Result = new Int32[] { 0, 0, 0, 0, 0, 0 };
var cur = 0;
if (mb == 1)
{
for (var i = 0; i <= mtmax; i++)
{
cur = Rank(MR[i], 0);
if (cur != -1)
{
Result[cur] += Discrete.C(t - mt, 6 - d - i) * (b - 1) * Discrete.C(mt, i);
}
cur = Rank(MR[i], 1);
Result[cur] += Discrete.C(t - mt, 6 - d - i) * Discrete.C(mt, i);
}
}
if (mb == 0)
{
for (var i = 0; i <= mtmax; i++)
{
cur = Rank(MR[i], 0);
if (cur != -1)
{
Result[cur] += Discrete.C(t - mt, 6 - d - i) * b * Discrete.C(mt, i);
}
}
}
return Result;
}
/// <summary>
/// Rank
/// </summary>
/// <param name="md">match dan</param>
/// <param name="b">blue</param>
/// <returns></returns>
private static Int32 Rank(Int32 md, Int32 b)
{
var src = md * 1 + b * 1;
switch (src)
{
case 7:
return 0;
case 6:
return (b == 1 ? 2 : 1);
case 5:
return 3;
case 4:
return 4;
default:
return (b == 1 ? 5 : -1);
}
}
#endregion
}//end TwoColor
}
using System.Collections.Generic;
using System.Linq;
using System.Text;
using TG.Package.Lottery.Base;
using TG.Package.Lottery.Calculate;
namespace TG.Package.Lottery.Win
{
public class TwoColor : IWinCalculate
{
public TwoColor()
{
}
private const Char SplitChar = ',';
public List<WinDetail> GetWinDetails(ILottery pLottery, Dictionary<NumericType, String> pWinNumber)
{
return GetWinDetailsByLottery(pLottery, pWinNumber);
}
/// <summary>
/// Get WinDetails By Lottery
/// </summary>
/// <param name="pLottery">Lottery</param>
/// <param name="pWinNumber">WinNumber</param>
/// <returns></returns>
private static List<WinDetail> GetWinDetailsByLottery(ILottery pLottery, Dictionary<NumericType, String> pWinNumber)
{
String[] redwins = pWinNumber[NumericType.Red].Split(SplitChar);
String bluewins = pWinNumber[NumericType.Blue];
List<WinDetail> result = new List<WinDetail>();
for (var i = 0; i < pLottery.Count; i++)
{
result.AddRange(GetWinDetailsByWelfareLottery(pLottery[i], redwins, bluewins, pLottery.LotteryIssue));
}
return result;
}
/// <summary>
/// Get WinDetails By WelfareLottery
/// </summary>
/// <param name="pWelfareLottery">WelfareLottery</param>
/// <param name="pRedWinNumbers">Red Win Numbers</param>
/// <param name="pBlueWinNumber"> Blue Win Number</param>
/// <param name="pLotteryIssue">Lottery Issue</param>
/// <returns></returns>
private static List<WinDetail> GetWinDetailsByWelfareLottery(WelfareLottery pWelfareLottery, String[] pRedWinNumbers, String pBlueWinNumber, String pLotteryIssue)
{
Int32[] winnumbers = null;
switch (pWelfareLottery.PlayType)
{
case PlayType.Normal: winnumbers =
GetWinNumberWithNormal(pWelfareLottery.Lottery[NumericType.Red], pWelfareLottery.Lottery[NumericType.Blue], pRedWinNumbers, pBlueWinNumber);
break;
case PlayType.DanTuo: winnumbers =
GetWinNumberWithDan(pWelfareLottery.Lottery[NumericType.Red], pWelfareLottery.Lottery[NumericType.Blue], pWelfareLottery.Lottery[NumericType.Dan], pRedWinNumbers, pBlueWinNumber);
break;
default: throw new FormatException("error: PlayType is error");
}
if (null == winnumbers)
{ throw new FormatException("error: winnumbers is null"); }
return WinAumountToWinDetails(winnumbers, pWelfareLottery, pLotteryIssue);
}
/// <summary>
/// Win Aumount To WinDetails
/// </summary>
/// <param name="pWinAumount">win aumount</param>
/// <param name="pWelfareLottery">Lottery</param>
/// <param name="pLotteryIssue">LotteryIssue</param>
/// <returns></returns>
private static List<WinDetail> WinAumountToWinDetails(Int32[] pWinAumount, WelfareLottery pWelfareLottery, String pLotteryIssue)
{
List<WinDetail> result = new List<WinDetail>();
for (var i = 0; i < pWinAumount.Length; i++)
{
if (pWinAumount[i] < 1)
{
continue;
}
WinDetail temp = new WinDetail();
temp.LotteryIssue = pLotteryIssue;
temp.LotteryNo = pWelfareLottery.ToString();
temp.LotteryType = LotteryType.TwoColor;
temp.PlayType = pWelfareLottery.PlayType;
temp.WinGrade = i + 1;
temp.WinMoney = 0;
temp.WinCount = pWinAumount[i];
result.Add(temp);
}
return result;
}
/// <summary>
/// Get Win number With Normal
/// </summary>
/// <param name="pRed">red buy</param>
/// <param name="pBlue">blue buy</param>
/// <param name="pRedWinNumbers">red match</param>
/// <param name="pBlueWinNumber">blue match</param>
/// <returns></returns>
private static Int32[] GetWinNumberWithNormal(String pRed, String pBlue, String[] pRedWinNumbers, String pBlueWinNumber)
{
Int32 redbuy = (pRed.Length / 3) + 1;
Int32 bluebuy = (pBlue.Length / 3) + 1;
Int32 redmatch = Calculate.NumberHelper.NumberEqual(pRedWinNumbers, pRed);
Int32 bluematch = Calculate.NumberHelper.NumberEqual(new String[] { pBlueWinNumber }, pBlue);
return WinAmount(redbuy, bluebuy, redmatch, bluematch);
}
/// <summary>
/// Get Win Number With Dan
/// </summary>
/// <param name="pRed">red buy</param>
/// <param name="pBlue">blue buy</param>
/// <param name="pDan">dan buy</param>
/// <param name="pRedWinNumbers">red winno</param>
/// <param name="pBlueWinNumber">blue winno</param>
/// <returns></returns>
private static Int32[] GetWinNumberWithDan(String pRed, String pBlue, String pDan, String[] pRedWinNumbers, String pBlueWinNumber)
{
Int32 redbuy = (pRed.Length / 3) + 1;
Int32 bluebuy = (pBlue.Length / 3) + 1;
Int32 danbuy = (pDan.Length / 3) + 1;
Int32 danmatch = Calculate.NumberHelper.NumberEqual(pRedWinNumbers, pDan);
Int32 redmatch = Calculate.NumberHelper.NumberEqual(pRedWinNumbers, pRed);
Int32 bluematch = Calculate.NumberHelper.NumberEqual(new String[] { pBlueWinNumber }, pBlue);
return WinAmountWithDan(danbuy, redbuy, bluebuy, danmatch, redmatch, bluematch);
}
#region Win Amount (not dan)
/// <summary>
/// Win Amount
/// </summary>
/// <param name="rl">red</param>
/// <param name="bl">blue</param>
/// <param name="red">match red</param>
/// <param name="blue">match blue</param>
/// <returns></returns>
private static Int32[] WinAmount(Int32 rl, Int32 bl, Int32 red, Int32 blue)
{
var result = new Int32[] { 0, 0, 0, 0, 0, 0 };
switch (red)
{
case 0:
case 1:
case 2:
#region red=2 blue=1
if (blue > 0)
{
result[5] += Discrete.C(rl, 6);
}
#endregion
break;
case 3:
#region red=3 blue=1
if (blue > 0)
{
result[5] += Discrete.C(rl - red, 4) * Discrete.C(red, 2);
result[5] += Discrete.C(rl - red, 5) * Discrete.C(red, 1);
result[5] += Discrete.C(rl - red, 6);
result[4] += Discrete.C(rl - red, 3);
}
#endregion
break;
case 4:
#region red=4 blue=1
if (blue > 0)
{
result[5] += Discrete.C(rl - red, 6);
result[5] += Discrete.C(rl - red, 5) * Discrete.C(red, 1);
result[5] += Discrete.C(rl - red, 4) * Discrete.C(red, 2);
result[4] += Discrete.C(rl - red, 3) * Discrete.C(red, 3);
result[4] += Discrete.C(rl - red, 2) * Discrete.C(red, 4) * (bl - 1);
result[3] += Discrete.C(rl - red, 2);
}
#endregion
#region red=4 blue=0
else
{
result[4] += Discrete.C(rl - red, 2) * bl;
}
#endregion
break;
case 5:
#region red=5 blue=1
if (blue > 0)
{
result[5] += Discrete.C(rl - red, 6);
result[5] += Discrete.C(rl - red, 5) * Discrete.C(red, 1);
result[5] += Discrete.C(rl - red, 4) * Discrete.C(red, 2);
result[4] += Discrete.C(rl - red, 3) * Discrete.C(red, 3);
result[4] += Discrete.C(rl - red, 2) * Discrete.C(red, 4) * (bl - 1);
result[3] += Discrete.C(rl - red, 2) * Discrete.C(red, 4);
result[3] += Discrete.C(rl - red, 1) * Discrete.C(red, 5) * (bl - 1);
result[2] += Discrete.C(rl - red, 1);
}
#endregion
#region red=5 blue=0
else
{
result[4] += Discrete.C(rl - red, 2) * Discrete.C(red, 4) * bl;
result[3] += Discrete.C(rl - red, 1) * Discrete.C(red, 5) * bl;
}
#endregion
break;
case 6:
#region red=6 blue=1
if (blue > 0)
{
result[5] += Discrete.C(rl - red, 6);
result[5] += Discrete.C(rl - red, 5) * Discrete.C(red, 1);
result[5] += Discrete.C(rl - red, 4) * Discrete.C(red, 2);
result[4] += Discrete.C(rl - red, 3) * Discrete.C(red, 3);
result[4] += Discrete.C(rl - red, 2) * Discrete.C(red, 4) * (bl - 1);
result[3] += Discrete.C(rl - red, 2) * Discrete.C(red, 4);
result[3] += Discrete.C(rl - red, 1) * Discrete.C(red, 5) * (bl - 1);
result[2] += Discrete.C(rl - red, 1) * Discrete.C(red, 5);
result[1] += bl - 1;
result[0]++;
}
#endregion
#region red=6 blue=0
else
{
result[4] += Discrete.C(rl - red, 2) * Discrete.C(red, 4) * bl;
result[3] += Discrete.C(rl - red, 1) * Discrete.C(red, 5) * bl;
result[1] += bl;
}
#endregion
break;
}
return result;
}
#endregion
#region Win Amount With Dan
/// <summary>
/// Win Amount With Dan
/// </summary>
/// <param name="d">dan</param>
/// <param name="t">tuo(red)</param>
/// <param name="b">blue</param>
/// <param name="md">match dan</param>
/// <param name="mt">match tuo(red)</param>
/// <param name="mb">match blue</param>
/// <returns></returns>
private static Int32[] WinAmountWithDan(Int32 d, Int32 t, Int32 b, Int32 md, Int32 mt, Int32 mb)
{
var mtmax = mt <= 6 - d ? mt : 6 - d;
//mt的最大有效值
var MR = new Int32[mtmax + 1];
//命中的红球的个数集合
for (var i = 0; i <= mtmax; i++)
{
MR[i] = md + i;
}
var Result = new Int32[] { 0, 0, 0, 0, 0, 0 };
var cur = 0;
if (mb == 1)
{
for (var i = 0; i <= mtmax; i++)
{
cur = Rank(MR[i], 0);
if (cur != -1)
{
Result[cur] += Discrete.C(t - mt, 6 - d - i) * (b - 1) * Discrete.C(mt, i);
}
cur = Rank(MR[i], 1);
Result[cur] += Discrete.C(t - mt, 6 - d - i) * Discrete.C(mt, i);
}
}
if (mb == 0)
{
for (var i = 0; i <= mtmax; i++)
{
cur = Rank(MR[i], 0);
if (cur != -1)
{
Result[cur] += Discrete.C(t - mt, 6 - d - i) * b * Discrete.C(mt, i);
}
}
}
return Result;
}
/// <summary>
/// Rank
/// </summary>
/// <param name="md">match dan</param>
/// <param name="b">blue</param>
/// <returns></returns>
private static Int32 Rank(Int32 md, Int32 b)
{
var src = md * 1 + b * 1;
switch (src)
{
case 7:
return 0;
case 6:
return (b == 1 ? 2 : 1);
case 5:
return 3;
case 4:
return 4;
default:
return (b == 1 ? 5 : -1);
}
}
#endregion
}//end TwoColor
}
福彩3D:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using TG.Package.Lottery.Base;
namespace TG.Package.Lottery.Win
{
public class FuCai3D : IWinCalculate
{
public FuCai3D()
{
}
private const Char SplitChar = ',';
public List<WinDetail> GetWinDetails(ILottery pLottery, Dictionary<NumericType, String> pWinNumber)
{
return GetWinDetailsWithLottery(pLottery, pWinNumber);
}
/// <summary>
/// Get WinDetails By Lottery
/// </summary>
/// <param name="pLottery">Lottery</param>
/// <param name="pWinNumber">WinNumber</param>
/// <returns></returns>
private static List<WinDetail> GetWinDetailsWithLottery(ILottery pLottery, Dictionary<NumericType, String> pWinNumber)
{
List<WinDetail> reslut = new List<WinDetail>();
String[] winnumbers=new String[]{pWinNumber[NumericType.Ones],pWinNumber[NumericType.Tens],pWinNumber[NumericType.Hundreds]};
for (var i = 0; i < pLottery.Count; i++)
{
reslut.Add(GetWinDetailsByWelfareLottery(pLottery[i], winnumbers, pLottery.LotteryIssue));
}
return reslut;
}
/// <summary>
/// Get WinDetails By WelfareLottery
/// </summary>
/// <param name="pWelfareLottery">WelfareLottery</param>
/// <param name="pRedWinNumbers">Red Win Numbers</param>
/// <param name="pBlueWinNumber"> Blue Win Number</param>
/// <param name="pLotteryIssue">Lottery Issue</param>
/// <returns></returns>
private static WinDetail GetWinDetailsByWelfareLottery(WelfareLottery pWelfareLottery, String[] pWinNumbers, String pLotteryIssue)
{
Int32 winamount = 0;
switch (pWelfareLottery.PlayType)
{
case PlayType.Normal:
winamount = GetNormalWinAmount(pWelfareLottery, pWinNumbers);
break;
case PlayType.Zu3:
winamount = GetZu3WinAmount(pWelfareLottery, pWinNumbers);
break;
case PlayType.Zu6:
winamount = GetZu6WinAmount(pWelfareLottery, pWinNumbers);
break;
case PlayType.Normal | PlayType.DanTuo:
winamount = GetNormalDanWinAmount(pWelfareLottery, pWinNumbers);
break;
case PlayType.Zu3 | PlayType.DanTuo:
winamount = GetZu3DanWinAmount(pWelfareLottery, pWinNumbers);
break;
case PlayType.Zu6 | PlayType.DanTuo:
winamount = GetZu6DanWinAmount(pWelfareLottery, pWinNumbers);
break;
default: throw new FormatException("error:PlayType is error");
}
if (winamount == 1)
{
return GetWinDetailsModel(pWelfareLottery, pLotteryIssue);
}
return null;
}
/// <summary>
/// pWelfareLottery to WinDetail
/// </summary>
private static WinDetail GetWinDetailsModel(WelfareLottery pWelfareLottery, String pLotteryIssue)
{
WinDetail temp = new WinDetail();
temp.LotteryIssue = pLotteryIssue;
temp.LotteryNo = pWelfareLottery.ToString();
temp.LotteryType = LotteryType.FuCai3D;
temp.PlayType = pWelfareLottery.PlayType;
temp.WinGrade = 1;
temp.WinMoney = 0;
temp.WinCount = 1;
return temp;
}
#region Get Win Amount
/// <summary>
/// Get Normal WinAmount
/// </summary>
/// <param name="pWelfareLottery">WelfareLottery</param>
/// <param name="pWinNumbers">WinNumbers</param>
/// <returns></returns>
private static Int32 GetNormalWinAmount(WelfareLottery pWelfareLottery, String[] pWinNumbers)
{
String one = pWelfareLottery.Lottery[NumericType.Ones];
String ten = pWelfareLottery.Lottery[NumericType.Tens];
String hundred = pWelfareLottery.Lottery[NumericType.Hundreds];
if (Calculate.NumberHelper.NumberEqual(new String[] { pWinNumbers[0] }, one) > 0
&& Calculate.NumberHelper.NumberEqual(new String[] { pWinNumbers[1] }, ten) > 0
&& Calculate.NumberHelper.NumberEqual(new String[] { pWinNumbers[2] }, hundred) > 0
)
{
return 1;
}
return 0;
}
/// <summary>
/// Get Zu3 WinAmount
/// </summary>
/// <param name="pWelfareLottery">WelfareLottery</param>
/// <param name="pWinNumbers">WinNumbers</param>
/// <returns></returns>
private static Int32 GetZu3WinAmount(WelfareLottery pWelfareLottery, String[] pWinNumbers)
{
if (!Calculate.NumberHelper.IsZu3WinNo(pWinNumbers))
{
return 0;
}
String zu3 = pWelfareLottery.Lottery[NumericType.Zu3];
if (Calculate.NumberHelper.NumberEqual(new String[] { pWinNumbers[0] }, zu3) > 0
&& Calculate.NumberHelper.NumberEqual(new String[] { pWinNumbers[2] }, zu3) > 0
)
{
return 1;
}
return 0;
}
/// <summary>
/// Get Zu6 WinAmount
/// </summary>
/// <param name="pWelfareLottery">WelfareLottery</param>
/// <param name="pWinNumbers">WinNumbers</param>
/// <returns></returns>
private static Int32 GetZu6WinAmount(WelfareLottery pWelfareLottery, String[] pWinNumbers)
{
if (Calculate.NumberHelper.IsZu3WinNo(pWinNumbers))
{
return 0;
}
String zu6 = pWelfareLottery.Lottery[NumericType.Zu6];
if (Calculate.NumberHelper.NumberEqual(new String[] { pWinNumbers[0] }, zu6) > 0
&& Calculate.NumberHelper.NumberEqual(new String[] { pWinNumbers[1] }, zu6) > 0
&& Calculate.NumberHelper.NumberEqual(new String[] { pWinNumbers[2] }, zu6) > 0
)
{
return 1;
}
return 0;
}
/// <summary>
/// Get Normal Dan WinAmount
/// </summary>
/// <param name="pWelfareLottery">WelfareLottery</param>
/// <param name="pWinNumbers">WinNumbers</param>
/// <returns></returns>
private static Int32 GetNormalDanWinAmount(WelfareLottery pWelfareLottery, String[] pWinNumbers)
{
String winno = String.Format("{0},{1},{2}", pWinNumbers[0], pWinNumbers[1], pWinNumbers[2]);
return GetDanWinAmount(pWelfareLottery, winno);
}
/// <summary>
/// Get Zu3 Dan WinAmount
/// </summary>
/// <param name="pWelfareLottery">WelfareLottery</param>
/// <param name="pWinNumbers">WinNumbers</param>
/// <returns></returns>
private static Int32 GetZu3DanWinAmount(WelfareLottery pWelfareLottery, String[] pWinNumbers)
{
if (!Calculate.NumberHelper.IsZu3WinNo(pWinNumbers))
{
return 0;
}
String winno = String.Format("{0},{1}", pWinNumbers[0], pWinNumbers[2]);
return GetDanWinAmount(pWelfareLottery, winno);
}
/// <summary>
/// Get Zu6 DanWinAmount
/// </summary>
/// <param name="pWelfareLottery">WelfareLottery</param>
/// <param name="pWinNumbers">WinNumbers</param>
/// <returns></returns>
private static Int32 GetZu6DanWinAmount(WelfareLottery pWelfareLottery, String[] pWinNumbers)
{
if (Calculate.NumberHelper.IsZu3WinNo(pWinNumbers))
{
return 0;
}
String winno = String.Format("{0},{1},{2}", pWinNumbers[0], pWinNumbers[1], pWinNumbers[2]);
return GetDanWinAmount(pWelfareLottery, winno);
}
/// <summary>
/// Get Dan WinAmount
/// </summary>
/// <param name="pWelfareLottery">WelfareLottery</param>
/// <param name="pWinNo">WinNo (ex: "1,2,3")</param>
/// <returns></returns>
private static Int32 GetDanWinAmount(WelfareLottery pWelfareLottery, String pWinNo)
{
String dan = pWelfareLottery.Lottery[NumericType.Dan];
String tuo = pWelfareLottery.Lottery[NumericType.Tuo];
if (Calculate.NumberHelper.NumberEqual(dan.Split(SplitChar), pWinNo) > 0
&& Calculate.NumberHelper.NumberEqual(tuo.Split(SplitChar), pWinNo) > 0
)
{
return 1;
}
return 0;
}
#endregion
}//end FuCai3D
}
using System.Collections.Generic;
using System.Linq;
using System.Text;
using TG.Package.Lottery.Base;
namespace TG.Package.Lottery.Win
{
public class FuCai3D : IWinCalculate
{
public FuCai3D()
{
}
private const Char SplitChar = ',';
public List<WinDetail> GetWinDetails(ILottery pLottery, Dictionary<NumericType, String> pWinNumber)
{
return GetWinDetailsWithLottery(pLottery, pWinNumber);
}
/// <summary>
/// Get WinDetails By Lottery
/// </summary>
/// <param name="pLottery">Lottery</param>
/// <param name="pWinNumber">WinNumber</param>
/// <returns></returns>
private static List<WinDetail> GetWinDetailsWithLottery(ILottery pLottery, Dictionary<NumericType, String> pWinNumber)
{
List<WinDetail> reslut = new List<WinDetail>();
String[] winnumbers=new String[]{pWinNumber[NumericType.Ones],pWinNumber[NumericType.Tens],pWinNumber[NumericType.Hundreds]};
for (var i = 0; i < pLottery.Count; i++)
{
reslut.Add(GetWinDetailsByWelfareLottery(pLottery[i], winnumbers, pLottery.LotteryIssue));
}
return reslut;
}
/// <summary>
/// Get WinDetails By WelfareLottery
/// </summary>
/// <param name="pWelfareLottery">WelfareLottery</param>
/// <param name="pRedWinNumbers">Red Win Numbers</param>
/// <param name="pBlueWinNumber"> Blue Win Number</param>
/// <param name="pLotteryIssue">Lottery Issue</param>
/// <returns></returns>
private static WinDetail GetWinDetailsByWelfareLottery(WelfareLottery pWelfareLottery, String[] pWinNumbers, String pLotteryIssue)
{
Int32 winamount = 0;
switch (pWelfareLottery.PlayType)
{
case PlayType.Normal:
winamount = GetNormalWinAmount(pWelfareLottery, pWinNumbers);
break;
case PlayType.Zu3:
winamount = GetZu3WinAmount(pWelfareLottery, pWinNumbers);
break;
case PlayType.Zu6:
winamount = GetZu6WinAmount(pWelfareLottery, pWinNumbers);
break;
case PlayType.Normal | PlayType.DanTuo:
winamount = GetNormalDanWinAmount(pWelfareLottery, pWinNumbers);
break;
case PlayType.Zu3 | PlayType.DanTuo:
winamount = GetZu3DanWinAmount(pWelfareLottery, pWinNumbers);
break;
case PlayType.Zu6 | PlayType.DanTuo:
winamount = GetZu6DanWinAmount(pWelfareLottery, pWinNumbers);
break;
default: throw new FormatException("error:PlayType is error");
}
if (winamount == 1)
{
return GetWinDetailsModel(pWelfareLottery, pLotteryIssue);
}
return null;
}
/// <summary>
/// pWelfareLottery to WinDetail
/// </summary>
private static WinDetail GetWinDetailsModel(WelfareLottery pWelfareLottery, String pLotteryIssue)
{
WinDetail temp = new WinDetail();
temp.LotteryIssue = pLotteryIssue;
temp.LotteryNo = pWelfareLottery.ToString();
temp.LotteryType = LotteryType.FuCai3D;
temp.PlayType = pWelfareLottery.PlayType;
temp.WinGrade = 1;
temp.WinMoney = 0;
temp.WinCount = 1;
return temp;
}
#region Get Win Amount
/// <summary>
/// Get Normal WinAmount
/// </summary>
/// <param name="pWelfareLottery">WelfareLottery</param>
/// <param name="pWinNumbers">WinNumbers</param>
/// <returns></returns>
private static Int32 GetNormalWinAmount(WelfareLottery pWelfareLottery, String[] pWinNumbers)
{
String one = pWelfareLottery.Lottery[NumericType.Ones];
String ten = pWelfareLottery.Lottery[NumericType.Tens];
String hundred = pWelfareLottery.Lottery[NumericType.Hundreds];
if (Calculate.NumberHelper.NumberEqual(new String[] { pWinNumbers[0] }, one) > 0
&& Calculate.NumberHelper.NumberEqual(new String[] { pWinNumbers[1] }, ten) > 0
&& Calculate.NumberHelper.NumberEqual(new String[] { pWinNumbers[2] }, hundred) > 0
)
{
return 1;
}
return 0;
}
/// <summary>
/// Get Zu3 WinAmount
/// </summary>
/// <param name="pWelfareLottery">WelfareLottery</param>
/// <param name="pWinNumbers">WinNumbers</param>
/// <returns></returns>
private static Int32 GetZu3WinAmount(WelfareLottery pWelfareLottery, String[] pWinNumbers)
{
if (!Calculate.NumberHelper.IsZu3WinNo(pWinNumbers))
{
return 0;
}
String zu3 = pWelfareLottery.Lottery[NumericType.Zu3];
if (Calculate.NumberHelper.NumberEqual(new String[] { pWinNumbers[0] }, zu3) > 0
&& Calculate.NumberHelper.NumberEqual(new String[] { pWinNumbers[2] }, zu3) > 0
)
{
return 1;
}
return 0;
}
/// <summary>
/// Get Zu6 WinAmount
/// </summary>
/// <param name="pWelfareLottery">WelfareLottery</param>
/// <param name="pWinNumbers">WinNumbers</param>
/// <returns></returns>
private static Int32 GetZu6WinAmount(WelfareLottery pWelfareLottery, String[] pWinNumbers)
{
if (Calculate.NumberHelper.IsZu3WinNo(pWinNumbers))
{
return 0;
}
String zu6 = pWelfareLottery.Lottery[NumericType.Zu6];
if (Calculate.NumberHelper.NumberEqual(new String[] { pWinNumbers[0] }, zu6) > 0
&& Calculate.NumberHelper.NumberEqual(new String[] { pWinNumbers[1] }, zu6) > 0
&& Calculate.NumberHelper.NumberEqual(new String[] { pWinNumbers[2] }, zu6) > 0
)
{
return 1;
}
return 0;
}
/// <summary>
/// Get Normal Dan WinAmount
/// </summary>
/// <param name="pWelfareLottery">WelfareLottery</param>
/// <param name="pWinNumbers">WinNumbers</param>
/// <returns></returns>
private static Int32 GetNormalDanWinAmount(WelfareLottery pWelfareLottery, String[] pWinNumbers)
{
String winno = String.Format("{0},{1},{2}", pWinNumbers[0], pWinNumbers[1], pWinNumbers[2]);
return GetDanWinAmount(pWelfareLottery, winno);
}
/// <summary>
/// Get Zu3 Dan WinAmount
/// </summary>
/// <param name="pWelfareLottery">WelfareLottery</param>
/// <param name="pWinNumbers">WinNumbers</param>
/// <returns></returns>
private static Int32 GetZu3DanWinAmount(WelfareLottery pWelfareLottery, String[] pWinNumbers)
{
if (!Calculate.NumberHelper.IsZu3WinNo(pWinNumbers))
{
return 0;
}
String winno = String.Format("{0},{1}", pWinNumbers[0], pWinNumbers[2]);
return GetDanWinAmount(pWelfareLottery, winno);
}
/// <summary>
/// Get Zu6 DanWinAmount
/// </summary>
/// <param name="pWelfareLottery">WelfareLottery</param>
/// <param name="pWinNumbers">WinNumbers</param>
/// <returns></returns>
private static Int32 GetZu6DanWinAmount(WelfareLottery pWelfareLottery, String[] pWinNumbers)
{
if (Calculate.NumberHelper.IsZu3WinNo(pWinNumbers))
{
return 0;
}
String winno = String.Format("{0},{1},{2}", pWinNumbers[0], pWinNumbers[1], pWinNumbers[2]);
return GetDanWinAmount(pWelfareLottery, winno);
}
/// <summary>
/// Get Dan WinAmount
/// </summary>
/// <param name="pWelfareLottery">WelfareLottery</param>
/// <param name="pWinNo">WinNo (ex: "1,2,3")</param>
/// <returns></returns>
private static Int32 GetDanWinAmount(WelfareLottery pWelfareLottery, String pWinNo)
{
String dan = pWelfareLottery.Lottery[NumericType.Dan];
String tuo = pWelfareLottery.Lottery[NumericType.Tuo];
if (Calculate.NumberHelper.NumberEqual(dan.Split(SplitChar), pWinNo) > 0
&& Calculate.NumberHelper.NumberEqual(tuo.Split(SplitChar), pWinNo) > 0
)
{
return 1;
}
return 0;
}
#endregion
}//end FuCai3D
}
结束语:
写这些4篇连续随笔,主要是记录下 当我接到模块后,的思维过程的编码过程。
希望在过2年又能有所不一样(当然是网好的方面发展 嘻嘻)
我的开源的地址https://github.com/tianjing/
大家踊跃拍砖共同成长,拍砖的同时记得附上意见或者建议。!!谢谢 谢谢