Bullfight (beef) winning hand simulated probability calculator

Recently made a beef simulation of small programs, generally speaking difficult, the key is to optimize the place, improve computing speed.

Rules are user aware of their four hands, then simulated and their winning percentage gains.

Probably the idea is to give the user as well as the user's own analog simulation licensing, the final calculation of the weights for all, find the maximum weights to determine benefits.

52 cards I m = 1-52 by the numerals, m% 13 represents the size of each card, m / 13 represented by the suit, 13,26,39,52 course, this special number returned specific color.

1. Calculate the suit

/// <summary>
/// 返回牌的花色
/// </summary>
/// <param name="brand"></param>
/// <returns></returns>
private static int BackColor(int brand)
{
if (brand == 13) return 0;
if (brand == 26) return 1;
if (brand == 39) return 2;
if (brand == 52) return 3;
return brand / 13;
}
2.计算牌的大小

/// <Summary>
/// Returns sfsa
/// </ Summary>
/// <param name = "Brand"> brand </ param>
/// <Returns> </ Returns>
Private static int BackValue (int brand)
{
IF (% brand 13 is == 0) return 13 is;
return 13 is brand%;
}
because doing sfsa accumulation time, 10, J, Q, K are calculated in accordance with 0, it is necessary to accumulate time, need another method

/// <Summary>
/// Returns the size of the card if more than 9 returns 0
/// </ Summary>
/// <param name = "Brand"> </ param>
/// <Returns> </ Returns >
Private BackZero static int (int brand)
{
IF (brand 13 is%>. 9)
{
return 0;
}
the else
{
return 13 is brand%;
}
}
3. return two big cards

Two cards must have a big one small, because beef rule is if the card size equal, then the suit.

/// <Summary>
/// Returns the larger card and two
/// </ Summary>
/// <param name = "Abrand"> </ param>
/// <param name = "Bbrand"> </ param>
/// <Returns> </ Returns>
Private static int BackCompareMax (Abrand int, int Bbrand)
{
IF (BackValue (Abrand)> BackValue (Bbrand))
{
return Abrand;
}
the else IF (BackValue (Abrand) <BackValue (Bbrand))
{
return Bbrand;
}
the else
{
IF (the BackColor (Abrand)> the BackColor (Bbrand))
{
return Abrand;
}
the else
{
return Bbrand;
}
}
}
4. the user's hand four ascending large sorted in the order

 Because the size of the weights in addition to the comparison value is even compare the suit, it is not directly own list sorting method

/// <Summary>
/// small hand according to the value and suit of the large size of the sort
/// </ Summary>
/// <Returns> </ Returns>
Private static List <int> ListSort (List <int> LIS)
{
for (int I = 0; I <lis.Count -. 1; I ++)
{
for (int I = J +. 1; J <lis.Count; J ++)
{
IF (LIS [I] == BackCompareMax (LIS [I], LIS [J]))
{
LIS [I] = LIS [I] + LIS [J];
LIS [J] = LIS [I] - LIS [J];
LIS [I] = LIS [I] - LIS [J];
}
}
}
return LIS;
}
 5. the acquisition and hand

 And obtaining the time 10, J, Q, K are in accordance with the count 0, and is licensed for the handle back to facilitate determination of the type of hand

/// <Summary>
/// Gets a value and a hand (10, J, Q, K count 0)
/// </ Summary>
/// <param name = "LIS"> </ param>
// / <Returns> </ Returns>
Private static int GetSum (List <int> LIS)
{
int SUM = 0;
for (int I = 0; I <lis.Count; I ++)
{
SUM + = BackZero (LIS [I] );
}
return SUM;
}
 6. the user then inputs the card apart from the rest of the deck of cards stored together as a list, and then select a random set of cards inside a card assigned to the user, randomly selects five cards assigned to an analog user, and then calculate the weight of five cards.

Here I Cheng Hoon is in accordance with the type of beef the size down from the upper row, because card type is selected the biggest card type to compare.

Here I put every different type of cards are represented by four digits.

The thousand represents the type of card, the hundreds digit is designed for preparation of cattle, hundreds digit is cattle X, the back of double-digit is the biggest card of five cards inside. Because Taurus rules compare the size when the first is the comparison type, the type of big win, if the same type then compare the highest card (cattle except), if the same cow, then the type of relatively cattle size, if cattle the same, then you compare the biggest brand values, if the comparison value is equal color.

/// <Summary>
/// Returns the maximum of five cards in card type 9-1 to five calves San card
/// </ Summary>
/// <param name = "listbrand"> cards in hand. 5 </ param>
/// <Returns> </ Returns>
Private static int BackMaxType (List <int> listbrand)
{
// ATA [10] ++;
listbrand = ListSort (listbrand);
int = GetSum sums (listbrand);
// determines whether five calves
int SUM = 0;
iF (sums == 10 && BackValue (listbrand [. 4]) <. 5) return (listbrand [. 4] + 9000);
// determines whether the bomb
if (BackValue ( listbrand [0]) == BackValue (listbrand [. 3]))
{
return listbrand [. 3] + 8000;
}
IF (BackValue (listbrand [. 1]) == BackValue (listbrand [. 4]))
{
return listbrand [. 4] + 8,000;
}
//判断是否是葫芦牛 (AAABB or AABBB)
if (BackValue(listbrand[0]) == BackValue(listbrand[2]) && BackValue(listbrand[3]) == BackValue(listbrand[4]))
{
return listbrand[2] + 7000;
}
if (BackValue(listbrand[0]) == BackValue(listbrand[1]) && BackValue(listbrand[2]) == BackValue(listbrand[4]))
{
return listbrand[4] + 7000;
}
//判断是否是五花牛
if (BackValue(listbrand[0]) > 10) return listbrand[4] + 6000;
//判断是否是同花牛
if (BackColor(listbrand[0]) == BackColor(listbrand[1]) && BackColor(listbrand[1]) == BackColor(listbrand[2]) && BackColor(listbrand[2]) == BackColor(listbrand[3])
&& BackColor(listbrand[3]) == BackColor(listbrand[4]))
{
return listbrand[4] + 5000;
}
// determines whether straight bovine
IF (BackValue (listbrand [. 4]) - BackValue (listbrand [. 3]) == BackValue. 1 && (listbrand [. 3]) - BackValue (listbrand [2]) ==. 1 &&
BackValue (listbrand [2]) - BackValue (listbrand [. 1]) == BackValue. 1 && (listbrand [. 1]) - BackValue (listbrand [0]) ==. 1)
{
return listbrand [. 4] + 4000;
}
// Analyzing whether beef
// first five cards must be a multiple of 10 by adding
iF (sums% 10 == 0)
{
// then take the sum is a multiple of 10 where two of the three further combined must also be 10 multiple
// beef i.e.
for (int I = 0; I <listbrand.Count; I ++)
{
for (int I = J +. 1; J <listbrand.Count; J ++)
{
IF ((BackZero (listbrand [I]) + BackZero (listbrand [J]))% 10 == 0)
{
return listbrand [. 4] + 3000;
}
}
}
}
// determine whether bovine
SUM = sums;
for (int I = 0; I <listbrand.Count -. 1; I ++)
{
for (int I = J +. 1; J <listbrand.Count; J ++)
{
IF ( (SUM - BackZero (listbrand [I]) - BackZero (listbrand [J]))% 10 == 0)
{
int = VA (BackZero (listbrand [I]) + BackZero (listbrand [J])) 10%; / / bovine values acquired

return listbrand [. 4] + 100 2000+ VA *;
}
}
}
// Analyzing San card
return listbrand [. 4] + 1000;
}
7. the five cards according to a weight value to compare the size

Here is relatively simple, and so wanted to compare rule 6 which says,

/// <the Summary>
/// find two big cards
/// </ the Summary>
/// <param name = "Brand"> </ param>
/// <returns A> </ returns A>
Private static BackMaxBrand int (Abrand int, int Bbrand)
{
IF (the Math.Abs (Abrand - Bbrand)> 51 is) // not of the same type
{
return math.max (Abrand, Bbrand);
}
the else // same type
{
int A Abrand =;
int = B Bbrand;
// removing sfsa type comparison
if (a> 2000 && a < 3000) // determines whether the cow
{
// more cattle size
if ((a - 2000) / 100> ( B - 2000) / 100)
{
return Abrand;
}
the else IF ((A - 2000) / 100 <(B - 2000) / 100)
{
return Bbrand;
}
The else // equality comparisons largest cattle brand
{
A = A - 2000;
B = B - 2000;
the while (A> B 52 is &&> 52 is)
{
A = A - 100;
B = B - 100;
}
IF (A == BackCompareMax (A, B))
{
Abrand return;
}
the else
{
return Bbrand;
}
}
}
A = Abrand;
B = Bbrand;
the while (A> B 52 is &&> 52 is)
{
A = A - 1000;
B = B - 1000;
}
IF (A == BackCompareMax (a, B))
{
it returns Abrand;
}
the else
{
return Bbrand;
}
}
}
 8. the multiple card counting, not the same card type are not the same multiple of their own can be modified according to the rules of play

/// <Summary>
/// Returns multiple cards
/// </ Summary>
/// <param name = "Brand"> </ param>
/// <Returns> </ Returns>
Private static int BackTimes ( Brand int)
{
IF (Brand <2000)
{
return. 1; // bovine
}
the else IF (Brand <3000) bovine //
{
// Analyzing bovine cattle 7 or 8 or 9 cattle Bos
if (brand - 2900> 0) return. 3;
IF (Brand - 2800> 0) return 2;
IF (Brand - 2700> 0) return 2;
return. 1;
}
the else IF (Brand <4000) // beef
{
return. 4;
}
the else IF (Brand <5000) straight bovine //
{
return. 5;
}
the else IF (Brand <6000) // flush cow
{
return 5;
}
The else IF (Brand <7000) // streaky
{
return. 5;
}
the else IF (Brand <8000) // hoist
{
return. 6;
}
the else IF (Brand <9000) // bomb
{
return. 6;
}
the else // five small
{
return. 8;
}
}
10. The analog user licensing

 First, to simulate a user send a card, which weights are calculated, and then determine his type, and finally make a type of accumulation.

Then, after the user to simulate analog licensing, weights are calculated to compare the size of the user card, leaving big.

Whether the final judgment is the user's left of the big brand, if not then subtract multiples of earnings on the biggest brand, if it is a multiple of the largest brand on the increase

Of course, if winning or losing record the frequency and probability calculations to facilitate a winning hand.

/// <summary>
/// 线程跑动
/// </summary>
/// <param name="num">发牌次数</param>
/// <param name="lis">剩余牌</param>
/// <param name="bran">用户手牌</param>
/// <param name="user">用户数</param>
/// <returns></returns>
private static void ThreadBackA(int num, List<int> list, List<int> brans, int user)
{
Random rd = new Random();
List<int> lis = new List<int>();
List<int> bran = new List<int>();
while (num > 0)
{
lis.Clear();
lis.AddRange(list);
bran.Clear();
bran.AddRange(brans);
int next = rd.The Next (0, lis.Count); lis.RemoveAt (next);
bran.Add (LIS [Next]); // hand to the user

BackMaxType YH = int (Bran);
IF (YH <2000)
{
Data [. 1] ++; // Bovine
}
the else IF (YH <3000) Bovine //
{
Data [2] ++;
}
the else IF (YH <4000) // beef
{
Data [. 3] ++;
}
the else IF (YH <5000) straight bovine //
{
Data [. 4] ++;
}
the else IF (YH <6000) // flush cattle
{
Data [. 5] ++;
}
the else IF (YH <7000) // bovine streaky
{
Data [. 6] ++;
}
the else IF (YH <8000) // bovine hoist
{
Data [. 7] ++;
}
the else IF (YH <9000) // bomb
{
Data [. 8] ++;
}
the else
{
Data [. 9] ++; // five calves
}
int max = YH; //最大牌
//int cesji = BackMaxType(bran);
for (int i = 0; i < user; i++)
{
List<int> us = new List<int>();
for (int j = 0; j < 5; j++)
{
next = rd.Next(0, lis.Count);
us.Add(lis[next]);
lis.RemoveAt(next);
}
max = BackMaxBrand(max, BackMaxType(us));
}
if (max != YH)
{
data[0]++;
data[11] = data[11] - BackTimes(max);
}
else
{
data[10]++;
data[11] = data[11] + BackTimes(max);
}
num--;
}
}
 11.异步task跑动

How long Tsak array there are a few asynchronous task running, I have here is a total of five threads analog licensing a million times (personally feel no need to be so many times, 100,000 times is enough, however, a difference of a few tenths of final results error, dispensable.)

Finally, a number of the returned array, there are winners and losers, the number of types of total revenue, as well as user hand occur

public static int[] GetTransport(List<int> lis,int user)
{
data=new int[12];
HandAardA = lis;
GetAllHandAard(HandAardA);
//异步task
Task[] tasks = new Task[5];
for (int i = 0; i < tasks.Length; i++)
{
tasks[i] = new Task(() => { ThreadBackA(200000, AllHandAard, HandAardA, user); });
tasks[i].Start();
}
//Thread.Sleep(1000);
Task.WaitAll(tasks);
return data;
}
12.简陋界面 

 

Probably so much.

end 

 

A friend in need can contact me weixin: 7350815

(Paid)

 

Guess you like

Origin www.cnblogs.com/niuniugailv/p/12363682.html