VBScript扑克游戏--我有什么牌?
我正在做一个奇怪的小项目。在您回答之前,是的,我知道vbscript可能是最糟糕的语言 我需要帮助确定每个球员都有什么。每张牌都有一个唯一的号码(我用一个字母“翻译”成它的扑克值)♥♦♣♠ 旁边)。例如:VBScript扑克游戏--我有什么牌?,vbscript,poker,Vbscript,Poker,我正在做一个奇怪的小项目。在您回答之前,是的,我知道vbscript可能是最糟糕的语言 我需要帮助确定每个球员都有什么。每张牌都有一个唯一的号码(我用一个字母“翻译”成它的扑克值)♥♦♣♠ 旁边)。例如: A♥ = 0 2♥ = 1 3♥ = 2 ... 等等。我需要帮助确定我的手。我想了几个办法。第一种方法是使用每张卡价值之间的差值。例如,直线是: n n +/- (1+ (13 * (0 or 1 or 2 or 3))) n +/- (2 + (13 * (0 or 1 or 2 or
A♥ = 0
2♥ = 1
3♥ = 2
...
等等。我需要帮助确定我的手。我想了几个办法。第一种方法是使用每张卡价值之间的差值。例如,直线是:
n
n +/- (1+ (13 * (0 or 1 or 2 or 3)))
n +/- (2 + (13 * (0 or 1 or 2 or 3 )))
...
等等。例如卡片3、3+1+0、3+2+13、3+3+(13*3)、3+4+(13*2)
你能给我:
4.♥ 5.♥ 6.♦ 7.♠ 8.♣
我的问题是,我是否应该尝试使用正则表达式来实现这一点?不必对每只手进行硬编码,告诉计算机他有哪只手的最好方法是什么
编辑:此处的完整代码:扑克牌都取决于相对等级和/或牌套 我建议编写一些实用函数,从确定等级和等级开始 因此,您表示的卡是0..51中的
int
。以下是一些有用的函数(伪代码):
现在您可以获得一组手的等级和套装,您可以编写一些实用程序来处理这些
// sort and return the list of cards ordered by rank
orderByRank(cards) {
// ranked = []
// for each card in cards:
// get the rank
// insert into ranked list in correct place
}
// given a ranked set of cards return highest number of identical ranks
getMaxSameRank(ranked) {
duplicates = {} // map / hashtable
for each rank in ranked {
duplicates[rank] += 1
}
return max(duplicates.vals())
}
// count the number of cards of same suit
getSameSuitCount(cards) {
suitCounts = {} // a map or hashtable if possible
// for each card in cards:
// suitCounts{getSuit(card)} += 1
// return max suit count (highest value of suitCounts)
}
您将需要更多的实用功能,但有了这些功能,您现在可以寻找齐平或直边:
isFlush(cards) {
if (getSameSuitCount(cards) == 5) {
return true
}
return false
}
isStraight(cards) {
ranked = orderByRank(cards)
return ranked[4] - ranked[0] == 3 && getMaxSameRank(ranked) == 1
}
isStraightFlush(cards) {
return isFlush(cards) && isStraight(cards)
}
等等
一般来说,你需要检查每一手牌与可能的扑克牌,从最好的开始,一直到高牌。在实践中,你需要比这更多的东西来区分关系(两名球员有一个全场,胜利者是一种排名较高的三名球员的全场)。因此,您需要存储更多的信息来对两只手进行排名,例如踢球者
// simplistic version
getHandRanking(cards) {
if (isStraightFlush()) return STRAIGHT_FLUSH
if (isQuads()) return QUADS
...
if (isHighCard) return HIGH_CARD
}
getWinner(handA, handB) {
return max(getHandRanking(handA), getHandRanking(handB))
}
这将是我的一般做法。有大量关于扑克手排名算法的信息。你可能会喜欢第1单元:从Peter Norvig的Udacity课程中赢得扑克手扑克手都取决于相对等级和/或牌套 我建议编写一些实用函数,从确定等级和等级开始 因此,您表示的卡是0..51中的
int
。以下是一些有用的函数(伪代码):
现在您可以获得一组手的等级和套装,您可以编写一些实用程序来处理这些
// sort and return the list of cards ordered by rank
orderByRank(cards) {
// ranked = []
// for each card in cards:
// get the rank
// insert into ranked list in correct place
}
// given a ranked set of cards return highest number of identical ranks
getMaxSameRank(ranked) {
duplicates = {} // map / hashtable
for each rank in ranked {
duplicates[rank] += 1
}
return max(duplicates.vals())
}
// count the number of cards of same suit
getSameSuitCount(cards) {
suitCounts = {} // a map or hashtable if possible
// for each card in cards:
// suitCounts{getSuit(card)} += 1
// return max suit count (highest value of suitCounts)
}
您将需要更多的实用功能,但有了这些功能,您现在可以寻找齐平或直边:
isFlush(cards) {
if (getSameSuitCount(cards) == 5) {
return true
}
return false
}
isStraight(cards) {
ranked = orderByRank(cards)
return ranked[4] - ranked[0] == 3 && getMaxSameRank(ranked) == 1
}
isStraightFlush(cards) {
return isFlush(cards) && isStraight(cards)
}
等等
一般来说,你需要检查每一手牌与可能的扑克牌,从最好的开始,一直到高牌。在实践中,你需要比这更多的东西来区分关系(两名球员有一个全场,胜利者是一种排名较高的三名球员的全场)。因此,您需要存储更多的信息来对两只手进行排名,例如踢球者
// simplistic version
getHandRanking(cards) {
if (isStraightFlush()) return STRAIGHT_FLUSH
if (isQuads()) return QUADS
...
if (isHighCard) return HIGH_CARD
}
getWinner(handA, handB) {
return max(getHandRanking(handA), getHandRanking(handB))
}
这将是我的一般做法。有大量关于扑克手排名算法的信息。你可能会喜欢Peter Norvig的Udacity课程中的第1单元:赢得扑克手有很多用于获得扑克手的资源-例如,也有很多用于获得扑克手的资源-例如,谢谢你的链接。我一直在使用素数方法来存储它是哪只手。问题是我需要一个数据库来存储手。另一个问题是,如果我尝试做一个像hold'em这样的游戏,我必须决定21只手中哪只手是最好的(7C5)。谢谢你的链接。我一直在使用素数方法来存储它是哪只手。问题是我需要一个数据库来存储手牌。另一个问题是,如果我想做一个像hold'em这样的游戏,我必须决定21只手牌中哪只手是最好的(7C5)。