首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >Deuces位运算符

Deuces位运算符
EN

Stack Overflow用户
提问于 2017-06-02 18:41:15
回答 2查看 293关注 0票数 2

所以我下载了Deuces,用于扑克手评估的代码,最初我认为是在Python 2中,因为所有的print语句都没有括号。我把所有这些都修好了,除了最后一部分,一切似乎都正常。这是它的代码:

代码语言:javascript
运行
复制
def get_lexographically_next_bit_sequence(self, bits):
    """
    Bit hack from here:
    http://www-graphics.stanford.edu/~seander/bithacks.html#NextBitPermutation

    Generator even does this in poker order rank 
    so no need to sort when done! Perfect.
    """
    t = (bits | (bits - 1)) + 1 
    next = t | ((((t & -t) / (bits & -bits)) >> 1) - 1)  
    yield next
    while True:
        t = (next | (next - 1)) + 1 
        next = t | ((((t & -t) / (next & -next)) >> 1) - 1)
        yield next

我在网上发现他们是位操作符,但我不明白为什么python不认识他们。我需要导入什么吗?还是那些运算符没有在python 3中使用?

代码语言:javascript
运行
复制
 File "/Volumes/PROJECTS/deuces/All_poker.py", line 709, in get_lexographically_next_bit_sequence
next = t | ((((t and -t) / (bits and -bits)) // 2) - 1)

TypeError:不支持的操作数类型(S),用于:“浮动”和“浮点数”

这是我得到的错误,代码可以在https://github.com/vitamins/deuces/tree/8222a6505979886171b8a0c581ef667f13c5d165找到

它是查找类的最后一部分。

当我写

代码语言:javascript
运行
复制
board = [ Card.new('Ah'), Card.new('Kd'), ('Jc') ]
hand = [ Card.new('Qs'),Card.new('Th')]
evaluator=Evaluator()

在最后一行代码中,我得到了错误。所有代码都可以在链接中找到。

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2017-06-03 01:26:40

这是/符号,就像这位先生上面说的,它应该是地板分割的,而且是快速修复的,它工作得很好。

票数 0
EN

Stack Overflow用户

发布于 2017-06-02 19:09:43

与Arrivillaga的评论一致,我刚刚修改了您在这里发布的内容。

代码语言:javascript
运行
复制
def get_lexographically_next_bit_sequence(bits):
    """
    Bit hack from here:
    http://www-graphics.stanford.edu/~seander/bithacks.html#NextBitPermutation

    Generator even does this in poker order rank 
    so no need to sort when done! Perfect.
    """
    t = (bits | (bits - 1)) + 1 
    next = t | ((((t & -t) // (bits & -bits)) >> 1) - 1)  
    yield next
    while True:
        t = (next | (next - 1)) + 1 
        next = t | ((((t & -t) // (next & -next)) >> 1) - 1)
        yield next

for i, g in enumerate(get_lexographically_next_bit_sequence(123)):
    print (g)
    if i > 10:
        break

这些结果是否合理?

代码语言:javascript
运行
复制
125
126
159
175
183
187
189
190
207
215
219
221
票数 3
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/44335494

复制
相关文章

相似问题

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