ウォー カード ゲーム シミュレーターを構築しようとしていますが、問題が発生しています。何らかの理由で、ハンド a が常に勝ちます。これが私のコードです:
import random
def war(A,B): ##determines which player A or B wins or if its a tie
if A > B:
return 'a'
elif A < B:
return 'b'
else:
return 'tie'
def battle(frombefore,hand_a,hand_b): ##using winner, it transfers the cards, or if tie, it does another war and battelma
winner = war(hand_a[0],hand_b[0])
for k in frombefore:
temp.append(k)
if winner == 'a':
hand_a.append(hand_a.pop(0))
hand_a.append(hand_b.pop(0))
elif winner == 'b':
hand_b.append(hand_b.pop(0))
hand_b.append(hand_a.pop(0))
else:
if len(hand_a)>5 and len(hand_b)>5:
temp = []
temp.append(hand_a.pop(0))
temp.append(hand_b.pop(0))
temp.append(hand_a.pop(0))
temp.append(hand_a.pop(0))
temp.append(hand_a.pop(0))
temp.append(hand_b.pop(0))
temp.append(hand_b.pop(0))
temp.append(hand_b.pop(0))
winner2 = war(hand_a[0],hand_b[0])
if winner2 == 'a':
temp.append(hand_a.pop(0))
temp.append(hand_b.pop(0))
for j in temp:
hand_a.append(j)
if winner2 == 'b':
temp.append(hand_a.pop(0))
temp.append(hand_b.pop(0))
for j in temp:
hand_a.append(j)
if winner2 == 'tie':
battle(frombefore,hand_a,hand_b)
else:
if len(hand_a) > len(hand_b):
hand_b = []
if len(hand_b) > len(hand_a):
hand_a = []
return hand_a,hand_b
def playgame():
handd_a = [2,3,4,5,6,7,8,9,10,11,12,13,14,2,3,4,5,6,7,8,9,10,11,12,13,14]
handd_b = [2,3,4,5,6,7,8,9,10,11,12,13,14,2,3,4,5,6,7,8,9,10,11,12,13,14]
random.shuffle(handd_a)
random.shuffle(handd_b)
while len(handd_a)>0 and len(handd_b)>0:
handd_a,handd_b = battle([],handd_a,handd_b)
if len(handd_a)>0:
return 'a'
elif len(handd_b)>0:
return 'b'
##print(playgame())
Awins = 0
Bwins = 0
for i in range(5):
current = playgame()
print(current)
if current == 'a':
Awins = Awins + 1
if current == 'b':
Bwins = Bwins + 1
print(Awins)
print(Bwins)
おそらく私は自分自身の中で関数を呼び出しているので、おそらく私の問題は関係を扱っていると思いますか? 私はこれで少し迷っています。