为了回答该知乎问题(https://www.zhihu.com/question/57408133/answer/152920354)而写就的程序。

6+德州扑克的规则,就是在传统52张牌德州扑克的基础上,去掉了2到5,只留下6到A共计36张牌;另外最小的顺子就成了A6789。此外,牌型大小变成了:同花>葫芦>三条>顺子。其他规则都不变。

新的概率表(根据本程序跑出的结果)变为:

计算6+德州扑克各个牌型的概率-编程知识网

Chrome浏览器按F12打开控制台,把下面代码贴进去,回车,等待几十秒,即可出结果。欢迎大牛来做代码正确性审核。

function isPair(cards) {for (var i = 0; i < cards.length - 1; i++) {if (cards[i][0] == cards[i + 1][0]) return true;}return false;
}function isTwoPair(cards) {var hasPair = false;for (var i = 0; i < cards.length - 1; i++) {if (cards[i][0] == cards[i + 1][0]) {if (hasPair) return true;i++;hasPair = true;}}return false;
}function isSet(cards) {for (var i = 0; i < cards.length - 2; i++) {if (cards[i][0] == cards[i + 1][0] && cards[i][0] == cards[i + 2][0]) return true;}return false;
}function isFourOfAKind(cards) {for (var i = 0; i < cards.length - 3; i++) {if (cards[i][0] == cards[i + 1][0] && cards[i][0] == cards[i + 2][0]&& cards[i][0] == cards[i + 3][0]) return true;}return false;
}function isFullHouse(cards) {for (var i = 0; i < cards.length - 2; i++) {if (cards[i][0] == cards[i + 1][0] && cards[i][0] == cards[i + 2][0]) {//is set, find another pairfor (var j = 0; j < cards.length - 1; j++) {if (cards[i][0] == cards[j][0]) continue;if (cards[j][0] == cards[j + 1][0]) return true;}}}return false;
}function isStraight(cards) {var index = 0;var result = [cards[index]];while (index < cards.length && result.length < 5) {var next = index + 1;while (next < cards.length && cards[index][0] == cards[next][0]) next++;if (next >= cards.length) return false;if (cards[index][0] + 1 == cards[next][0]) {result.push(cards[next]);if (result[0][0] == 6 && result.length == 4) {//额外处理6、7、8、9、A的顺子                var hasA = false;var i = 0;for (i = 0; i < cards.length; i++)if (cards[i][0] == 14) {hasA = true;break;}if (hasA) result.push(cards[i]);}} else {result = [cards[next]];}index = next;}return result.length >= 5;
}function isFlush(cards) {var colors = [0, 0, 0, 0];for (var i = 0; i < cards.length; i++) {colors[cards[i][1]]++;}for (var j = 0; j < 4; j++) {if (colors[j] >= 5) return true;}return false;
}function isStraightFlush(cards) {//先找出同花的颜色var colors = [0, 0, 0, 0];for (var i = 0; i < cards.length; i++) {colors[cards[i][1]]++;}var flushColor = -1;for (var j = 0; j < 4; j++) {if (colors[j] >= 5) {flushColor = j;break;}}if (flushColor == -1) return false;var flushCards = [];for (var i = 0; i < cards.length; i++) {if (cards[i][1] == flushColor) {flushCards.push(cards[i]);}}//再根据这个花色找同花顺for (var i = 0; i < flushCards.length - 4; i++) {if (flushCards[i][0] + 1 == flushCards[i + 1][0]&& flushCards[i + 1][0] + 1 == flushCards[i + 2][0]&& flushCards[i + 2][0] + 1 == flushCards[i + 3][0]) {if (flushCards[i + 3][0] + 1 == flushCards[i + 4][0]) return true;//额外处理6、7、8、9、A的顺子if (flushCards[i][0] == 6 && flushCards[flushCards.length - 1][0] == 14) {return true;}}}return false;
}function isRoyalFlush(cards) {//先找出同花的颜色var colors = [0, 0, 0, 0];for (var i = 0; i < cards.length; i++) {colors[cards[i][1]]++;}var flushColor = -1;for (var j = 0; j < 4; j++) {if (colors[j] >= 5) {flushColor = j;break;}}if (flushColor == -1) return false;var flushCards = [];for (var i = 0; i < cards.length; i++) {if (cards[i][1] == flushColor) {flushCards.push(cards[i]);}}//再根据这个花色找皇家同花顺for (var i = 0; i < flushCards.length - 4; i++) {if (flushCards[i][0] == 10&& flushCards[i][0] + 1 == flushCards[i + 1][0]&& flushCards[i + 1][0] + 1 == flushCards[i + 2][0]&& flushCards[i + 2][0] + 1 == flushCards[i + 3][0]&& flushCards[i + 3][0] + 1 == flushCards[i + 4][0]) return true;}return false;
}/*** 从0开始递增,序号依次对应,皇家同花顺>同花顺>四条>同花>葫芦>三条>顺子>两对>一对>高牌*/
function checkType(cards) {if (isRoyalFlush(cards)) return 0;if (isStraightFlush(cards)) return 1;if (isFourOfAKind(cards)) return 2;if (isFlush(cards)) return 3;if (isFullHouse(cards)) return 4;if (isSet(cards)) return 5;if (isStraight(cards)) return 6;if (isTwoPair(cards)) return 7;if (isPair(cards)) return 8;return 9;
}/*** 生成6-A四种花色的所有牌,其中A代表14,四种花色分别是0到3*/
function getAllCard() {var cards = [];for (var i = 6; i <= 14; i++) {for (var j = 0; j < 4; j++) {temp = [i, j];cards.push(temp);}}return cards;
}//输出arr牌组中,取num张牌,各有几种牌型
function combine(arr, num) {var result = [];for (var i = 0; i <= 9; i++) {result.push(0);}(function f(t, a, n) {if (n == 0) {//此时t就是一个num张牌的组合var type = checkType(t);result[type]++;return;}for (var i = 0, l = a.length; i <= l - n; i++) {f(t.concat([a[i]]), a.slice(i + 1), n - 1);}})([], arr, num);return result;
}function printResult(result) {console.log("高牌:".concat(result[9]) +"\n对子:".concat(result[8]) +"\n两对:".concat(result[7]) +"\n顺子:".concat(result[6]) +"\n三条:".concat(result[5]) +"\n葫芦:".concat(result[4]) +"\n同花:".concat(result[3]) +"\n金刚:".concat(result[2]) +"\n同花顺:".concat(result[1]) +"\n皇家同花顺:".concat(result[0]))
}function main() {var card = getAllCard();var result = combine(card, 7);printResult(result);console.log(result);
}//-----------------------------
main();