来自Deuces的位运算符

2024-06-16 11:23:22 发布

您现在位置:Python中文网/ 问答频道 /正文

所以我下载了Deuces,扑克手的求值代码,最初我认为它是用python2编写的,因为所有print语句都没有括号。我把这些都修好了,除了最后一部分,一切似乎都正常了。下面是它的代码:

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中,这些操作符是用来导入的

^{pr2}$

TypeError:|的操作数类型不受支持:“float”和“float”

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

查找是类的最后一个部分

当我写作的时候

board = [ Card.new('Ah'), Card.new('Kd'), ('Jc') ]
hand = [ Card.new('Qs'),Card.new('Th')]
evaluator=Evaluator()

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


Tags: 代码newdef错误语句floatcardbits
2条回答

根据阿里维拉加的评论,我刚刚修改了你在这上面的帖子。在

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

这些结果看起来合理吗?在

^{pr2}$

它是/符号,正如上面那位先生所说,它应该是用于楼层划分的,而且是快速修复的,它工作得很好。在

相关问题 更多 >