Advertisement
George_Ivanov05

0.2

Oct 6th, 2021
143
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 3.05 KB | None | 0 0
  1. def read_matrix():
  2.     size = 7
  3.     matrx = []
  4.     for i in range(size):
  5.         matrx.append(input().split())
  6.  
  7.     return matrx
  8.  
  9.  
  10. def is_index_valid(r, c, mat_size):
  11.     if 0 <= r < mat_size and 0 <= c < mat_size:
  12.         return True
  13.     return False
  14.  
  15.  
  16. PLAYER1, PLAYER2 = input().split(", ")
  17. matrix = read_matrix()
  18. n = len(matrix)
  19.  
  20. player1_points = 501
  21. player2_points = 501
  22.  
  23. player_one_throws = 0
  24. player_two_throws = 0
  25.  
  26. players_turn = 1
  27. while True:
  28.     command = input()
  29.     row, col = int(command[1]), int(command[4])
  30.     if players_turn % 2 != 0:
  31.         player_one_throws += 1
  32.         players_turn += 1
  33.         if is_index_valid(row, col, n):
  34.             if matrix[row][col] == "D":
  35.                 total = 0
  36.                 total += int(matrix[0][col]) + int(matrix[6][col]) + int(matrix[row][0]) + int(matrix[row][6])
  37.                 player1_points -= total * 2
  38.                 if player1_points <= 0:
  39.                     print(f"{PLAYER1} won the game with {player_one_throws} throws!")
  40.                     break
  41.             elif matrix[row][col] == "T":
  42.                 total = 0
  43.                 total += int(matrix[0][col]) + int(matrix[6][col]) + int(matrix[row][0]) + int(matrix[row][6])
  44.                 player1_points -= total * 3
  45.             if player1_points <= 0:
  46.                 print(f"{PLAYER1} won the game with {player_one_throws} throws!")
  47.                 break
  48.             elif matrix[row][col] == "B":
  49.                 print(f"{PLAYER1} won the game with {player_one_throws} throws!")
  50.                 break
  51.             elif matrix[row][col].isdigit():
  52.                 player1_points -= int(matrix[row][col])
  53.                 if player1_points <= 0:
  54.                     print(f"{PLAYER1} won the game with {player_one_throws} throws!")
  55.                     break
  56.     elif players_turn % 2 == 0:
  57.         player_two_throws += 1
  58.         players_turn += 1
  59.         if is_index_valid(row, col, n):
  60.             if matrix[row][col] == "D":
  61.                 total = 0
  62.                 total += int(matrix[0][col]) + int(matrix[6][col]) + int(matrix[row][0]) + int(matrix[row][6])
  63.                 player2_points -= total * 2
  64.                 if player2_points <= 0:
  65.                     print(f"{PLAYER2} won the game with {player_two_throws} throws!")
  66.                     break
  67.             elif matrix[row][col] == "T":
  68.                 total = 0
  69.                 total += int(matrix[0][col]) + int(matrix[6][col]) + int(matrix[row][0]) + int(matrix[row][6])
  70.                 player2_points -= total * 3
  71.             if player2_points <= 0:
  72.                 print(f"{PLAYER2} won the game with {player_two_throws} throws!")
  73.                 break
  74.             elif matrix[row][col] == "B":
  75.                 print(f"{PLAYER2} won the game with {player_two_throws} throws!")
  76.                 break
  77.             elif matrix[row][col].isdigit():
  78.                 player2_points -= int(matrix[row][col])
  79.                 if player2_points <= 0:
  80.                     print(f"{PLAYER2} won the game with {player_two_throws} throws!")
  81.                     break
  82.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement