当前位置:网站首页>Thinking about the probability of drawing cards in the duel link of game king
Thinking about the probability of drawing cards in the duel link of game king
2022-06-12 16:14:00 【Impetuous wind】
I prefer to play the game king duel link , But as a programmer, I sometimes think about how to realize the functions in the game , Because I also want to be a game server engineer , This article shares my discussion and Simulation of the probability of using gem cards to draw card types 
This game draws four types of cards , Extraordinary card , Rare cards , Precious card , Ordinary card , Let's add up the probability of these four types of cards 100%, Of course, the number of each is determined by the planning , Just read the configuration table directly . Since it adds up to 100%, Then use 1~100 The integer of represents the range of probabilities of various card types , for example : The probability of drawing an extraordinary card is 3%, So the probability range is :1~3; The probability of drawing a rare card is 5%, So the probability range is :4~8; The probability of drawing precious cards is 20%, So the probability range is :9~28; The probability of drawing an ordinary card is 72%, So the probability range is :29~100; Each time a card is drawn, a random 1~100 Integer between , The range of this integer is the type of card drawn
@Data
public class CardType {
private String type; // Card type
private int probability;// Draw probability
private int min;// Minimum probability range
private int max;// Maximum probability range
public CardType(String type, int probability) {
this.type = type;
this.probability = probability;
}
}
The interesting thing about the game itself is randomness , But sometimes, in order to retain users, they will also be random , such as : Some players may smoke when they are lucky 10 You can draw several extraordinary cards with a second card , Some players have bad luck and even draw 100 If you can't get the super player every time, the game may lose this player , Therefore, the probability of human interference : for example ,1: Set the probability guarantee times of an extraordinary card , If the number of times a player draws a card continuously without drawing an extraordinary card reaches the minimum number of times , The system forces the player to obtain , After that, the minimum number of times is reset ;2: Set card drawing n The maximum number of times you can get an extraordinary card in times , Like smoking 100 Second card , But set the minimum number of guarantee for the extraordinary card to 10, Users can get 10 Zhang Chaofan card , I feel that the user has earned , If it is specified to smoke 100 Get... At most times 5 Zhang Chaofan card , It is not affected by the number of guaranteed times . Personally, I think the rules 1 Generally, it is aimed at users who draw cards less often at a time , The rules 2 It is generally aimed at those local tyrants ; Anyway, we can make flexible methods , The following is the simulation implementation I want :
/** * Simulation of the game king duel link in the draw card probability problem */
public class RateRandomNumber {
// Use LinkedHashMap reason , Make sure the lowest probability comes first ( Logical needs )
public static Map<String,CardType> cardTypes = new LinkedHashMap<>();
/** * @description: Initialization data * @return: * @author: Ming * @time: 2022/6/9 */
static {
cardTypes.put(" Extraordinary ",new CardType(" Extraordinary ",3));
cardTypes.put(" rare ",new CardType(" rare ",5));
cardTypes.put(" Precious ",new CardType(" Precious ",20));
cardTypes.put(" Ordinary ",new CardType(" Ordinary ",72));
setCardProbabilityRang();
}
/** * @description: Set the probability range according to the probability * explain : * Card drawing is random generation 1 To 100 Integer between , Because the total probability of various card types is 100%, Here is to 1~100 The number of indicates the probability range of various card types , * for example : Extraordinary card probability %3, Then the probability range is 1~3, Precious card probability %5, Then the probability range is 4~8, And so on , Finally, the range of randomly generated integers is the type of card drawn * @return: * @author: Ming * @time: 2022/6/9 */
public static void setCardProbabilityRang(){
int preMax = 0;// The maximum value of the probability range of the previous element
for (Map.Entry<String,CardType> m: cardTypes.entrySet()){
CardType cardType = m.getValue();
int max = cardType.getProbability()+preMax;// The maximum value of the current card probability range is : Probability of current card + The maximum value of the probability range of the previous element
cardType.setMax(max);
cardType.setMin(preMax+1);// The minimum value of the current card probability range is : The maximum value of the probability range of the previous element +1
preMax = max;
}
}
/** * @description: Draw card * @param aGuaranteed Extraordinary guaranteed times , If continuous n-1 I didn't draw the extraordinary , Is the first n Forced acquisition for times * @param aGetMax Parameters times How many extraordinary cards can you draw at most at a time ( Limit lucky users ) * @param times Number of cards drawn by the user * @return: * @author: Ming * @time: 2022/6/9 */
private static void drawCard(int aGuaranteed, int aGetMax, int times){
Random random = new Random();
CardType a = cardTypes.get(" Extraordinary ");
CardType b = cardTypes.get(" rare ");
CardType c = cardTypes.get(" Precious ");
int aGetTimes = 0;
int bGetTimes = 0;
int cGetTimes = 0;
int dGetTimes = 0;
int notTimes = 0; // The cumulative number of times you didn't win the game
// Start to draw cards
for (int i = 0; i < times; i++) {
// Random generation 1 To 100 Integer between , Because the probabilities of various cards add up to 100%, Here is to 1~100 The number of indicates the probability range of various card types ,
// for example : Extraordinary probability %3, Then the probability range is 1~3, Precious card probability %5, Then the probability range is 4~8, And so on
int num = random.nextInt(100)+1;
if(notTimes == aGuaranteed && aGetTimes < aGetMax){
System.out.println(" The system forces the issuance of extraordinary cards ");
aGetTimes++;
notTimes = 0;// Reset
}else {
notTimes++;
if(num <= a.getMax() && aGetTimes < aGetMax){
System.out.println(" Draw the extraordinary card ");
aGetTimes++;
notTimes = 0;
}else if(num <= b.getMax()){
System.out.println(" Draw a rare card ");
bGetTimes++;
}else if(num <= c.getMax()){
System.out.println(" Draw a precious card ");
cGetTimes++;
}else{
System.out.println(" Draw an ordinary card ");
dGetTimes++;
}
}
}
System.out.println(" The number of extraordinary cards drawn this time :"+aGetTimes);
System.out.println(" The number of rare cards drawn this time :"+bGetTimes);
System.out.println(" The number of precious cards drawn this time :"+cGetTimes);
System.out.println(" The number of ordinary cards drawn this time :"+dGetTimes);
}
public static void main(String[] args) {
drawCard(20,3,100);
}
}
test result 
The above is a simple implementation , In development , Some cardinalities are read configuration when the server starts , Data is preloaded into memory , for example : Probability of card type , Card deck, etc , For example, draw an extraordinary card , The system randomly allocates an extraordinary card from memory id To the user . The probability algorithm implemented by Netease is much more complicated , This is just a reflection of my own problems , discuss , Realization ; I hope you can correct me
边栏推荐
- 面试:什么是浅拷贝、深拷贝?
- Scanpy(六)空间转录组数据的分析与可视化
- 面试:hashCode()和equals()
- acwing 802. 区间和 (离散化)
- The small flying page is upgraded to be intelligent and the bug repair is faster
- Analysis on the current situation of China's antiarrhythmic drug industry in 2021: domestic R & D is further [figure]
- Homology? Cross domain? How to solve cross domain problems?
- Web UI automation test
- FPGA (III) trigger and latch
- Global and Chinese market of soft capsule manufacturing equipment 2022-2028: Research Report on technology, participants, trends, market size and share
猜你喜欢

小飞页升级变智能修复Bug更快速了

Redis string type common commands

2022.02.28 - SX11-05. The largest rectangle in the histogram

RTOS rt-thread裸机系统与多线程系统

鼻孔插灯,智商上升,风靡硅谷,3万就成

连续八年包装饮用水市占率第一,这个品牌DTC是如何持续增长的?

Project training of Software College of Shandong University rendering engine system basic renderer (VII)

acwing 798二维差分(差分矩阵)

< 山东大学软件学院项目实训 > 渲染引擎系统——基础渲染器(四)

Redis General Command
随机推荐
acwing795 前缀和(一维)
acwing 800. 数组元素的目标和
C packing and unpacking
Global and Chinese market of soft capsule manufacturing equipment 2022-2028: Research Report on technology, participants, trends, market size and share
Apache Kylin 历险记
连续八年包装饮用水市占率第一,这个品牌DTC是如何持续增长的?
[weekly replay] game 80 of leetcode
Analysis of China's cargo transport volume, cargo transport turnover and port cargo in 2021 [figure]
Project training of Software College of Shandong University rendering engine system basic renderer (IV)
Global and Chinese markets for air sampling calibration pumps 2022-2028: Research Report on technology, participants, trends, market size and share
盒马,最能代表未来的零售
go net库(待续)
C language partition bin file program
Applet: how to get the user's mobile number in the plug-in
Project training of Software College of Shandong University rendering engine system radiation pre calculation (IX)
PHP builds a high-performance API architecture based on sw-x framework (II)
[automation] kolla Based Automated Deployment CEPH cluster
Global and Chinese market of medical ECG telemetry equipment 2022-2028: Research Report on technology, participants, trends, market size and share
tinyint和int区别
Reprise de Google net