中秋博饼是闽南一带的习俗,之前刚好在中秋之前写了 个博饼开奖的东西,用随机数
状元插金花出现的概率还是比较难的,当然一秀的是最多的,看到网上有分析这个的概率
我还是直接上代码吧,代码可以直接运行
package com.fh.util;
/**
* <p>Title: drawLottery</p>
* <p>Description: 博饼开奖工具</p>
* @author hlg
* @date 2017年9月20日
*/
public class DrawLotteryUtil {
/**
* <p>Title: roomDrawLottery</p>
* <p>Description: 房间开奖 </p>
* @return
*/
public static PageData roomDrawLottery(){
PageData data = new PageData();
int[] fre = new int[7]; // 牺牲一个空间来换取程序的可读性
int[] die = new int[7];// 各色子的点数
int level = 0;
String levelName = "";
int one = 0;
int two = 0;
int three = 0;
int four = 0;
int five = 0;
int six = 0;
int charmValue = 0; //魅力值
StringBuffer num = new StringBuffer();
for (int i = 1; i < die.length; i++) {
die[i] = 1 + (int) (Math.random() * 6);
fre[die[i]]++;
num.append(die[i]);
num.append(",");
// System.out.println("die"+i+"= "+die[i]);
if(die[i] == 1){
one++;
}
if(die[i] == 2){
two++;
}
if(die[i] == 3){
three++;
}
if(die[i] == 4){
four++;
}
if(die[i] == 5){
five++;
}
if(die[i] == 6){
six++;
}
}
num.deleteCharAt(num.length() -1);
String openResult = num.toString();
System.out.println("色子:"+openResult);
System.out.println("one= "+one +" two= "+two+" three= "+three+" four= "+four+" five= "+five+" six="+six);
if(four == 1){ //一秀
level = 1;
levelName = "一秀";
charmValue += 2;
}
if(four == 2){ //二举
level = 2;
levelName = "二举";
charmValue += 6;
}
if(four != 4){ //四进-进士(4颗相同点数(除去四点))
if(one == 4 || two == 4 || three == 4 || five == 4 || six == 4){
level = 3;
levelName = "四进";
charmValue += 8;
}
}
if(four == 3){ //三红-探花(3颗四点)
level = 4;
levelName = "三红";
charmValue += 10;
}
if(one == 1 && two == 1 && three == 1 && four == 1 && five == 1 && six == 1){ //对堂-榜眼(顺子123456)
level = 5;
levelName = "对堂";
charmValue += 12;
}
if(one != 2){ //四红-状元(4颗四点和2颗其他点数(2颗一点不属于四红))
if(four == 4){
level = 6;
levelName = "四红";
charmValue += 14;
}
}
if(one != 5 && four != 5){ //五子-状元(5颗相同点数(除去四点)和一颗其他点数)
if(two == 5 || three == 5 || five == 5 || six == 5){
level = 7;
levelName = "五子登科";
charmValue += 18;
}
}
if(four == 5){ //五红-状元(5颗四点和1颗其他点数)
level = 8;
levelName = "五红";
charmValue += 25;
}
if(one != 6 && four != 6){ //黑六博-状元(除4和1外别的点数全部相同)
if(two == 6 || three == 6 || five == 6 || six == 6){
level = 9;
levelName = "黑六博";
charmValue += 25;
}
}
if(one == 6){ //遍地锦-状元(全部为1)
level = 10;
levelName = "遍地锦";
charmValue += 30;
}
if(four == 6){ //红六博-状元(全部为4)
level = 11;
levelName = "红六博";
charmValue += 50;
}
if(one == 2 && four == 4){ //状元插金花-状元(4个4,2个1)
level = 12;
levelName = "状元插金花";
charmValue += 80;
}
data.put("level", level);
data.put("levelName", levelName);
data.put("openResult", openResult);
data.put("charmValue", charmValue);
return data;
}
/**
* <p>Title: lobbyDrawLottery</p>
* <p>Description: 大厅开奖 </p>
* @return
*/
public static PageData lobbyDrawLottery(){
PageData data = new PageData();
int[] fre = new int[7]; // 牺牲一个空间来换取程序的可读性
int[] die = new int[7];// 各色子的点数
int level = 0;
String levelName = "";
int one = 0;
int two = 0;
int three = 0;
int four = 0;
int five = 0;
int six = 0;
int charmValue = 0; //魅力值
int integralValue = 0; //积分值
StringBuffer num = new StringBuffer();
for (int i = 1; i < die.length; i++) {
die[i] = 1 + (int) (Math.random() * 6);
fre[die[i]]++;
num.append(die[i]);
num.append(",");
// System.out.println("die"+i+"= "+die[i]);
if(die[i] == 1){
one++;
}
if(die[i] == 2){
two++;
}
if(die[i] == 3){
three++;
}
if(die[i] == 4){
four++;
}
if(die[i] == 5){
five++;
}
if(die[i] == 6){
six++;
}
}
num.deleteCharAt(num.length() -1);
String openResult = num.toString();
System.out.println("色子:"+openResult);
System.out.println("one= "+one +" two= "+two+" three= "+three+" four= "+four+" five= "+five+" six="+six);
if(four == 1){ //一秀
level = 1;
levelName = "一秀";
integralValue += 1;
charmValue += 0;
}
if(four == 2){ //二举
level = 2;
levelName = "二举";
integralValue += 2;
charmValue += 2;
}
if(four != 4){ //四进-进士(4颗相同点数(除去四点))
if(one == 4 || two == 4 || three == 4 || five == 4 || six == 4){
level = 3;
levelName = "四进";
integralValue += 5;
charmValue += 4;
}
}
if(four == 3){ //三红-探花(3颗四点)
level = 4;
levelName = "三红";
integralValue += 5;
charmValue += 5;
}
if(one == 1 && two == 1 && three == 1 && four == 1 && five == 1 && six == 1){ //对堂-榜眼(顺子123456)
level = 5;
levelName = "对堂";
integralValue += 7;
charmValue += 7;
}
if(one != 2){ //四红-状元(4颗四点和2颗其他点数(2颗一点不属于四红))
if(four == 4){
level = 6;
levelName = "四红";
integralValue += 10;
charmValue += 10;
}
}
if(four != 5){ //五子-状元(5颗相同点数(除去四点)和一颗其他点数)
if(two == 5 || three == 5 || five == 5 || six == 5){
level = 7;
levelName = "五子登科";
integralValue += 18;
charmValue += 15;
}
}
if(four == 5){ //五红-状元(5颗四点和1颗其他点数)
level = 8;
levelName = "五红";
integralValue += 20;
charmValue += 15;
}
if(one != 6 && four != 6){ //黑六博-状元(除4和1外别的点数全部相同)
if(two == 6 || three == 6 || five == 6 || six == 6){
level = 9;
levelName = "黑六博";
integralValue += 20;
charmValue += 20;
}
}
if(one == 6){ //遍地锦-状元(全部为1)
level = 10;
levelName = "遍地锦";
integralValue += 25;
charmValue += 20;
}
if(four == 6){ //红六博-状元(全部为4)
level = 11;
levelName = "红六博";
integralValue += 30;
charmValue += 30;
}
if(one == 2 && four == 4){ //状元插金花-状元(4个4,2个1)
level = 12;
levelName = "状元插金花";
integralValue += 50;
charmValue += 50;
}
data.put("level", level);
data.put("levelName", levelName);
data.put("openResult", openResult);
data.put("integralValue", integralValue);
data.put("charmValue", charmValue);
return data;
}
public static void main(String[] args) {
roomDrawLottery();
}
}