Advertisement
Guest User

Untitled

a guest
Feb 2nd, 2022
318
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.66 KB | None | 0 0
  1. def calculate_scored_points(m, i, j):
  2.     scored_points = 0
  3.     if m[i][j].isdigit():
  4.         scored_points = int(m[i][j])
  5.     elif m[i][j] == 'D':
  6.         scored_points = (int(m[i][0]) + int(m[i][-1]) + int(m[0][j]) + int(m[-1][j])) * 2
  7.     elif m[i][j] == 'T':
  8.         scored_points = (int(m[i][0]) + int(m[i][-1]) + int(m[0][j]) + int(m[-1][j])) * 3
  9.     elif m[i][j] == 'B':
  10.         return scored_points
  11.     return scored_points
  12.  
  13.  
  14. first_player, second_player = input().split(', ')
  15. matrix = [[char for char in input().split()] for row in range(7)]
  16.  
  17. first_player_score = 501
  18. second_player_score = 501
  19.  
  20. first_player_turns = 0
  21. second_player_turns = 0
  22.  
  23. turns = 1
  24.  
  25. while True:
  26.     coordinates = eval(input())
  27.     row = coordinates[0]
  28.     col = coordinates[1]
  29.  
  30.     if row in range(len(matrix)) and col in range(len(matrix)):
  31.         if turns % 2 != 0:
  32.             first_player_turns += 1
  33.             result = calculate_scored_points(matrix, row, col)
  34.             if result == 0:
  35.                 first_player_score = 0
  36.                 break
  37.             else:
  38.                 first_player_score -= result
  39.         else:
  40.             second_player_turns += 1
  41.             result = calculate_scored_points(matrix, row, col)
  42.             if result == 0:
  43.                 second_player_score = 0
  44.                 break
  45.             else:
  46.                 second_player_score -= result
  47.  
  48.     turns += 1
  49.  
  50.     if first_player_score <= 0 or second_player_score <= 0:
  51.         break
  52.  
  53. if first_player_score <= 0:
  54.     print(f'{first_player} won the game with {first_player_turns} throws!')
  55. else:
  56.     print(f'{second_player} won the game with {second_player_turns} throws!')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement