using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Models
{
public class DobuleChromosphere
{
//红色球蓝色球
public List<string>RedBalls { get; set; }
public List<string>BlueBalls{ get; set; }
/// <summary>
/// 投注方式
/// </summary>
public string BallType { get; set; }
/// <summary>
/// 价格默认是单式,一注是2元
/// </summary>
public int Price { get; set; } = 2;
#region 构造方法
/// <summary>
/// 用于显示的红色球和蓝色球组合字符串
/// </summary>
public string BallsShow
{
get
{
string nums = string.Join(" ", RedBalls) + "|";
if (BlueBalls.Count > 1)
return nums += " " + string.Join(" ", BlueBalls);
else
return nums += " " + BlueBalls[0];
}
}
public string PriceShow =>Price + "元";
#endregion
//构造方法(用于计算当前投注的金额)复式金额算法:A!/((A-6)!*6!)*B
/// <summary>
///
/// </summary>
/// <param name="redBalls">红色球集合</param>
/// <param name="bluBalls">蓝色球集合</param>
public DobuleChromosphere(List<string> redBalls, List<string> bluBalls)
{
this.RedBalls = redBalls;
this.BlueBalls = BlueBalls;
//投注的方式推算
BallType = bluBalls.Count > 1 || redBalls.Count > 6 ? "复式" : "单式";
//根根红色球和蓝色球开始计算价格(请根据网易彩票的算法实现)
int a = redBalls.Count;
int b = bluBalls.Count;
if (a > 6)
{
Price = Factorial(a) / (Factorial(a - 6) * Factorial(6)) * b;
}
else
{
Price *= b;
}
}
/// <summary>
/// 递归实现阶乘
/// </summary>
/// <param name="n"></param>
/// <returns></returns>
private int Factorial(int n)
{
if (n < 1) return 0;
if (n == 1) return 1;
return n * (Factorial(n - 1));
}
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Models
{
/// <summary>
/// 选号器类
/// </summary>
public class Selector
{
//红色、蓝色球池
public List<string> RedBallList { get; set; }
public List<string> BlueBallList { get; set; }
//存储选中的号码
public List<DobuleChromosphere> SelectedBalls { get; set; } = new List<DobuleChromosphere>();
private Random random = new Random();
public Selector()
{
RedBallList = new List<string> {
"01","02","03","04","05","06","07","08","09","10",
"11","12","13","14","15","16","17","18","19","20",
"21","22","23","24","25","26","27","28","29","30",
"31","32","33"
};
BlueBallList = new List<string> {
"01","02","03","04","05","06","07","08","09","10",
"11","12","13","14","15","16"
};
}
#region 方法:生成随机的蓝色球和红色球。
public List<string> CreateRedNum(int count)
{
List<string> numList = new List<string>();
while (true)
{
if (numList.Count == count) break;//如果达到随机数个数,就跳出
string num = RedBallList[random.Next(33)];
if (numList.Contains(num)) continue;
else
numList.Add(num);
}
return numList;
}
public List<string> CreateBlueNum(int count)
{
List<string> numList = new List<string>();
while (true)
{
if (numList.Count == count) break;//如果达到随机数个数,就跳出
string num = BlueBallList[random.Next(16)];
if (numList.Contains(num)) continue;
else
numList.Add(num);
}
return numList;
}
#endregion
#region 扩展方法:打印、保存到数据库(选择性作业、自行完成
#endregion
}
}