首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >扑克: Holdem包straight1功能?

扑克: Holdem包straight1功能?
EN

Stack Overflow用户
提问于 2016-10-22 01:09:29
回答 1查看 149关注 0票数 0

假设x是一只全息牌(棋盘+孔牌),其中J:A = 11:14,A可能= 1。西装不重要。你只是在检查直线。

代码语言:javascript
复制
x <- c(2,5,6,7,8,9,14)

这是来自holdem包的straight1函数。除了函数末尾的for循环之外,我什么都能理解。有谁能解释一下这部分是怎么工作的吗?我迷路了。

代码语言:javascript
复制
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
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2016-10-22 03:37:33

我认为这个问题需要澄清一下:

代码语言:javascript
复制
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

所以结果是..。

代码语言:javascript
复制
 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)。或者不那么依赖于模数运算。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/40187362

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档