GP_KLPK3_ShanDong.cs 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170
  1. using System;
  2. using TrendChartSDK.Entity.Base;
  3. namespace TrendChartSDK.Entity.Lottery.QTC
  4. {
  5. /// <summary>
  6. /// 山东快乐PK3
  7. /// </summary>
  8. public class GP_KLPK3_ShanDong : LotteryOpenCode
  9. {
  10. #region 字段
  11. /// <summary>
  12. /// 扑克牌花色
  13. /// </summary>
  14. private static readonly string[] _pokerSuitName = new string[] { "", "fangpian", "meihua", "hongtao", "heitao" };
  15. #endregion
  16. /// <summary>
  17. /// 号码1
  18. /// </summary>
  19. public int OpenCode1 { get; set; }
  20. /// <summary>
  21. /// 号码2
  22. /// </summary>
  23. public int OpenCode2 { get; set; }
  24. /// <summary>
  25. /// 号码3
  26. /// </summary>
  27. public int OpenCode3 { get; set; }
  28. #region 扩展
  29. public static Tuple<int, int> SplitOpenCodeTo(int openCode)
  30. {
  31. if (openCode < 100) throw new ArgumentOutOfRangeException("openCode");
  32. return Tuple.Create<int, int>(openCode / 100, openCode % 100);
  33. }
  34. internal static Tuple<string, string> GetPokerOpenCode(int openCode)
  35. {
  36. Tuple<int, int> ptp = SplitOpenCodeTo(openCode);
  37. return Tuple.Create(_pokerSuitName[ptp.Item1], PokerNumToName((ptp.Item2)));
  38. }
  39. internal static string PokerNumToName(int num)
  40. {
  41. switch (num)
  42. {
  43. case 1: return "A";
  44. case 11: return "J";
  45. case 12: return "Q";
  46. case 13: return "K";
  47. default: return num.ToString();
  48. }
  49. }
  50. /// <summary>
  51. /// 判断是否为豹子
  52. /// </summary>
  53. /// <param name="opencodes"></param>
  54. /// <returns></returns>
  55. public static bool IsAllSame(params int[] opencodes)
  56. {
  57. var _feed = -1;
  58. foreach (var op in opencodes)
  59. {
  60. if (_feed == -1)
  61. {
  62. _feed = op;
  63. continue;
  64. }
  65. if (op != _feed)
  66. return false;
  67. }
  68. return true;
  69. }
  70. /// <summary>
  71. /// 判断是否为对子
  72. /// </summary>
  73. /// <param name="opencodes"></param>
  74. /// <returns></returns>
  75. public static bool IsPair(params int[] opencodes)
  76. {
  77. for (int i = 0, n = opencodes.Length; i < n; i++)
  78. {
  79. var op1 = opencodes[i];
  80. for (int j = i + 1; j < n; j++)
  81. {
  82. var op2 = opencodes[j];
  83. if (op1 == op2) return true;
  84. }
  85. }
  86. return false;
  87. }
  88. /// <summary>
  89. /// 判断是否为顺子(前提是不重复数)
  90. /// </summary>
  91. /// <param name="opencodes"></param>
  92. /// <returns></returns>
  93. public static bool IsStraight(params int[] opencodes)
  94. {
  95. int min = 0, max = 0;
  96. var len = opencodes.Length;
  97. for (int i = 0; i < len; i++)
  98. {
  99. var op = opencodes[i];
  100. if (i == 0)
  101. {
  102. min = max = op;
  103. continue;
  104. }
  105. if (min > op)
  106. {
  107. min = op;
  108. continue;
  109. }
  110. if (max < op)
  111. max = op;
  112. }
  113. return (max - min) == len - 1;
  114. }
  115. public static string GetPokerReleaseName(int[] openCodes, bool isAllSameSuit)
  116. {
  117. if (IsAllSame(openCodes))
  118. return "豹子";
  119. if (IsPair(openCodes))
  120. return "对子";
  121. if (IsStraight(openCodes))
  122. {
  123. if (isAllSameSuit)
  124. return "同花顺";
  125. return "顺子";
  126. }
  127. if (isAllSameSuit)
  128. return "同花";
  129. return "散牌";
  130. }
  131. /// <summary>
  132. /// 出牌大小名称
  133. /// </summary>
  134. /// <returns></returns>
  135. public string PokerShowName()
  136. {
  137. var tp1 = SplitOpenCodeTo(OpenCode1);
  138. var tp2 = SplitOpenCodeTo(OpenCode2);
  139. var tp3 = SplitOpenCodeTo(OpenCode3);
  140. var openCodes = new int[] { tp1.Item2, tp2.Item2, tp3.Item2 };
  141. var isAllSameSuit = (tp1.Item1 == tp2.Item1 && tp1.Item1 == tp3.Item1);
  142. return GetPokerReleaseName(openCodes, isAllSameSuit);
  143. }
  144. /// <summary>
  145. /// 开奖号码(花色/排号)
  146. /// </summary>
  147. public Tuple<string, string> TpOpenCode1 { get { return GetPokerOpenCode(OpenCode1); } }
  148. public Tuple<string, string> TpOpenCode2 { get { return GetPokerOpenCode(OpenCode2); } }
  149. public Tuple<string, string> TpOpenCode3 { get { return GetPokerOpenCode(OpenCode3); } }
  150. #endregion
  151. }
  152. }