Имея проблемы с получением результатов для обновления в Mancala Code Player 2 Оценка остается на ноль.Python

Программы на Python
Anonymous
 Имея проблемы с получением результатов для обновления в Mancala Code Player 2 Оценка остается на ноль.

Сообщение Anonymous »

player1 = [4, 4, 4, 4, 4, 4, 0] # карманы 1 игрока + Mancala
player2 = [4, 4, 4, 4, 4, 4, 0] # Игрок 2 карманы + mancala < /p>
print («Добро пожаловать в Mancala!») Игрокам. - Камни распределены против часовой стрелки, один за другим, в каждый карман. , вы захватываете камни из противоположного кармана.
- игра заканчивается, когда карманы одной стороны пусты. p> def table ():
"" "" Печать текущее состояние платы с правильным выравниванием. "" "
pocket_labels =" 6 5 4 3 2 1 "
print (f" \ n Pocket #: {pocket_labels} ")
print (f'p2 -> [{" ".join (f" {p:> 2} "для p in reversed (player2 [: 6])) }] ', f "Оценка: {player2 [6]:> 2}")
print (f'p1 -> [{"" .join (f "{p:> 2}" для p in Player1 [: 6])}] ', f "Оценка: {player1 [6]:> 2}")
print (f "Pocket #: {pocket_labels} \ n") < /p>
original_stones = stones # Store the original number of stones
current_index = pocket_index + 1 # Start distributing from the next pocket

for _ in range(stones):
if player_num == 1:
if current_index > 13:
current_index = 0
if current_index == 6:
player[6] += 1
elif current_index < 6:
player[current_index] += 1
elif current_index > 6 and current_index < 13:
opponent[current_index - 7] += 1
current_index += 1

elif player_num == 2:
if current_index > 13:
current_index = 0
if current_index == 6:
opponent[6] += 1
elif current_index < 6:
player[current_index] += 1
elif current_index > 6 and current_index < 13:
opponent[current_index - 7] += 1
current_index += 1
return current_index - 1, original_stones # Return both last_index and original_stones
< /code>
def capture_stones (Player, Oppent, Player_num, Index, Original_stones):
"" "Ручка захвата камней, когда последний камень приземляется в пустом кармане." "
Если индекс 0: # Player 1 Capture Logic
Player [6] + = Opponent [5 - index] + original_stones # захватывает камни в противоположном кармане противника
player [index] = 0 # опустошить карман игрока
oponer [5 - индекс ] = 0 # опустошить захваченный карман противника
elif player_num == 2 и противник [index]> 0: # логика захвата плеера 2
противник [6] + = player [5-index] + original_stones # Захватить камни в противоположном кармане противника
Opponent [index] = 0 # опустошить карман противника
player [5 - index] = 0 # пусто захваченный карман игрока < /p>
def Move_Player (Player, Oppent, Player_num):
"" "" Обработайте поворот игрока, раздавая камни и применив правила игры "" "
while true:
try:
# Получите выбор кармана и проверьте вход
move = input (f "\ nplayer {player_num}, выберите карман для перемещения (1-6 или 'Q', чтобы бросить):") < /p>
if move.lower() == 'q': # Quit the game
print("Game quit. Final scores:")
return False

move = int(move) # Convert to integer
if move < 1 or move > 6: # Validate pocket number
print("Invalid input. Please choose a pocket between 1 and 6.")
continue
except ValueError: # Handle non-numeric input
print("Invalid input. Please enter a number between 1 and 6.")
continue

# Check if the chosen pocket is empty
stones = player[move - 1]
if stones == 0:
print("That pocket is empty. Choose a different pocket.")
continue

# Clear the chosen pocket and distribute stones
player[move - 1] = 0
last_index, original_stones = distribute_stones(player, opponent, player_num, move - 1, stones)

# Handle capture condition
capture_stones(player, opponent, player_num, last_index, original_stones)

table()

# Check if the player gets another turn (if last stone lands in their Mancala)
if (player_num == 1 and last_index == 6) or (player_num == 2 and last_index == 13):
print("You get another turn!")
continue
else:
break

return True # Continue game
< /code>
def game ():
"" "Основной игров ) < /p>
while True:
# Check if either side of the board is empty
p1_total = sum(player1[:6])
p2_total = sum(player2[:6])

if p1_total == 0 or p2_total == 0:
player1[6] += p1_total
player2[6] += p2_total
for i in range(6):
player1 = 0
player2 = 0
break

if not move_player(player1, player2, 1): # Player 1's turn
return
if sum(player2[:6]) != 0 and not move_player(player2, player1, 2): # Player 2's turn
return

# Game Over - Display results with "Score: #"
print('\nGAME OVER.')
print(f'Player 1 Score: {player1[6]}')
print(f'Player 2 Score: {player2[6]}')
if player1[6] > player2[6]:
print("Player 1 wins!")
elif player2[6] > player1[6]:
print("Player 2 wins!")
else:
print("It's a tie!")
< /code>
запустить игру < /h1>
game () < /p>
Пожалуйста, помогите с обновленной версией. /п>

Подробнее здесь: https://stackoverflow.com/questions/793 ... -remains-a

Вернуться в «Python»