2017-06-02 13 views
1

私はDeucesをダウンロードして、ポーカーハンド評価用のコードを作成しました。元々は、すべてのprint文に括弧がないため、Python 2であったと思います。私はそれらのすべてを修正し、この最後の部分を除いてすべてが機能するように見えます。ここではそのためのコードは次のとおりです。ビット演算子Deuces

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のdoesntのは、それらを認識し、なぜ理解しません。私は、これは誤りである「フロート」と「フロート」

:|のためのサポートされていないオペランドのタイプ(S):

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私は何かをインポートする必要がありますか、またはこれらの演算子は、Python 3で使用されていませんそれは私が書くのルックアップクラス

の最後の部分で取得し、コードがhttps://github.com/vitamins/deuces/tree/8222a6505979886171b8a0c581ef667f13c5d165

で発見することができます

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

最後のコード行でエラーが表示されます。すべてのコードはリンクにあります

+0

エラーが表示される理由を教えてください。一見したところで、あなたが投稿したコードに何か間違ったことはありません。 –

+0

あなたは問題を説明していません。 *具体的に何をお手伝いできますか? –

+2

私はエラーの原因がPython 2と3の '/'の意味の違いだと思っています。Python 2では、 '/'は床の分割で、Python 3ではwherasであり、真の除算であり、 'float 'これは、ビット演算子で' TypeError'を送出します。 –

答えて

0

これは紳士がフロア分割のためのものであると言われていたので、/シンボルであり、クイックフィックスとうまく動作します。

2

Arrivillagaのコメントによれば、私はあなたがこれに投稿した内容を変更しました。

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 

これらの結果は妥当と思われますか?

125 
126 
159 
175 
183 
187 
189 
190 
207 
215 
219 
221 
+0

いいえわからない –

+0

質問を編集してサンプルの入力と出力を行い、その後私にコメントを残してください。 –

+0

私はちょうど、ビルベル –