viligen

darts

Jan 30th, 2022
821
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.82 KB | None | 0 0
  1. size = 7
  2. player_1, player_2 = input().split(', ')
  3.  
  4. total_points_player1, total_points_player2 = 501, 501
  5. total_count = 0
  6. winner = ''
  7. matrix = []
  8. for _ in range(size):
  9.     matrix.append(input().split())
  10.  
  11. while total_points_player1 > 0 and total_points_player2 > 0:
  12.     total_count += 1
  13.     current_points = 0
  14.     if total_count % 2 == 0:
  15.         current_player = player_2
  16.     else:
  17.         current_player = player_1
  18.  
  19.     coordinates = input().split(', ')
  20.     current_row, current_col = int(coordinates[0][1]), int(coordinates[1][0])
  21.     if current_row < 0 or current_col < 0 or current_row >= size or current_col >= size:
  22.         continue
  23.     if matrix[current_row][current_col] == 'B':
  24.         winner = current_player
  25.         if current_player == player_1:
  26.             total_points_player1 = 0
  27.         else:
  28.             total_points_player2 = 0
  29.         break
  30.     elif matrix[current_row][current_col].isdigit():
  31.         current_points = int(matrix[current_row][current_col])
  32.     elif matrix[current_row][current_col] == 'D':
  33.         current_points = (int(matrix[current_row][0]) + int(matrix[current_row][size - 1]) + int(matrix[0][current_col])
  34.                           + int(matrix[size - 1][current_col])) * 2
  35.     elif matrix[current_row][current_col] == 'T':
  36.         current_points = (int(matrix[current_row][0]) + int(matrix[current_row][size - 1]) + int(matrix[0][current_col])
  37.                           + int(matrix[size - 1][current_col])) * 3
  38.     if current_player == player_1:
  39.         total_points_player1 -= current_points
  40.     else:
  41.         total_points_player2 -= current_points
  42.  
  43. if total_points_player1 > 0:
  44.     winner = player_2
  45.     total_count //= 2
  46. else:
  47.     winner = player_1
  48.     total_count = total_count % 2 + total_count // 2
  49.  
  50. print(f"{winner} won the game with {total_count} throws!")
  51.  
  52.  
  53.  
  54.  
Advertisement
Add Comment
Please, Sign In to add comment