斗牛众所周知的一款扑克牌游戏,其核心规则是需要对牌面进行计算出牛几或者牛牛的。我们看看程序上怎么去实现算法
首先,斗牛的规则是:
1.一副牌,去掉两个王,总共52张牌,2-6个人玩,每人发5张牌。
2.5张牌中的任意3张加起来不能成为10的倍数(如5,6,8,10,J)则是 无牛
3.张牌中的任意3张加起来为10的倍数,但另外2张不为10的倍数。至于到底是牛几,就要看另外2张牌相加之后的个位数。(如5,6,7,9,J 为牛7)
4.5张牌中的任意3张加起来为10的倍数,且另外2张也为10的倍数(如5,6,9,10,J)。
弄清除基本规则后,直接上代码,代码中有注释。
public static String syncBull(Integer[] cards) {
// 计算总点数
int sums = 0;
for (int i = 0; i < c