假设x是一只全息牌(棋盘+孔牌),其中J:A = 11:14,A可能= 1。西装不重要。你只是在检查直线。
x <- c(2,5,6,7,8,9,14)这是来自holdem包的straight1函数。除了函数末尾的for循环之外,我什么都能理解。有谁能解释一下这部分是怎么工作的吗?我迷路了。
function(x){
a1 = sort(unique(x))
if (length(a1)<4.5) return(0)
a3 = 0
n = length(a1)
if(a1[n] == 14) a1 = c(1,a1) ## count ace as both 1 and 14
a2 = length(a1)
for(j in c(5:a2)){ ## j will be the potential highest card of straight
if( sum(15^c(1:5) * a1[(j-4):j]) == sum(15^c(1:5) * ((a1[j]-4):a1[j]))) a3 = a1[j]
}
a3
} ## end of straight1发布于 2016-10-22 03:37:33
我认为这个问题需要澄清一下:
Qstraight <-function(x){
a1 = sort(unique(x))
if (length(a1)<4.5) return(0)
a3 = 0
n = length(a1)
if(a1[n] == 14) a1 = c(1,a1) ## count ace as both 1 and 14
a2 = length(a1)
for(j in c(5:a2)){
## j will be the potential highest card of straight
if( sum(15^c(1:5) * a1[(j-4):j]) ==
sum(15^c(1:5) * ((a1[j]-4):a1[j]))) a3 = a1[j]
}
a3
} ## end所以结果是..。
Qstraight(x)
#[1] 9 # i.e a "nine-high straight
x2 <- c(2,5,6,7,8,10,14)
Qstraight(x2)
#[1] 0 # i.e not a straight at all.我可能会对唯一值进行排序,然后取$values == 1的最大长度(diff(唯一(排序(X)。或者不那么依赖于模数运算。
https://stackoverflow.com/questions/40187362
复制相似问题