def run_counter(card_list, num_cards):
hand = functions1.hand_sample(card_list, num_cards)
hand1 = functions1.hand_shuffle(card_list, num_cards)
srt_hand = sorted(hand)
srt_hand1 = sorted(hand1)
prop_hand = functions1.proper_hand(srt_hand)
prop_hand1 = functions1.proper_hand(srt_hand1)
run1 = 0
i = 0
for count in range(len(srt_hand)-1):
if srt_hand[i] == srt_hand[i+1] - 1:
run1 += 1
run2 = 0
i = 0
for count in range(len(srt_hand1)-1):
if srt_hand1[i] == srt_hand1[i+1] - 1:
run2 += 1
return run1+1, run2+1, prop_hand, prop_hand1
私は生成したカードの手札を持っており、ソートされたリスト「srt_hand」と「srt_hand1」に保存しています。ハンドのランの長さをカウントする関数を作成しました。私はそれをテストしに行きましたが、「if srt_hand[i] == srt_hand[i+1] - 1:」はサポートされていないオペランド型であると言い続けています。何故ですか?整数のリストにインデックスを付けているので、意味がありません...
私は以前にこれを持っていましたが、同じソート手法を使用して機能しました(最初の実行後に停止したことを除いて):
run1 = 0
i = 0
while i < len(srt_hand)-1 and run1 < 2:
while i < len(srt_hand)-1 and srt_hand[i] == srt_hand[i+1] - 1:
if srt_hand[i] == srt_hand[i+1]:
i += 1
run1 += 1
i += 1
i += 1
run2 = 0
i = 0
while i < len(srt_hand1)-1 and run2 < 2:
while i < len(srt_hand1)-1 and srt_hand1[i] == srt_hand1[i+1] - 1:
if srt_hand[i] == srt_hand[i+1]:
i += 1
run2 += 1
i += 1
i += 1
return run1+1, run2+1, prop_hand, prop_hand1