Advertisement
pacho_the_python

dartz

Jul 21st, 2022
122
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.16 KB | None | 0 0
  1. import re
  2.  
  3.  
  4. def is_inside(x, y, num):
  5.     return 0 <= x < num and 0 <= y < num
  6.  
  7.  
  8. players = input().split(", ")
  9. regex = r"\d+"
  10. matrix = []
  11. player_stat = [[players[0], 501], [players[1], 501]]
  12. size = 7
  13.  
  14. for _ in range(size):
  15.     row = input().split()
  16.     matrix.append(row)
  17.  
  18. turns = 1
  19. counter = 0
  20. coordinates = input()
  21. while True:
  22.     reg_result = re.finditer(regex, coordinates)
  23.     player_coordinates = []
  24.     for i in reg_result:
  25.         player_coordinates.append(int(i.group()))
  26.     player_row, player_col = player_coordinates
  27.  
  28.     if not is_inside(player_row, player_col, size):
  29.         counter += 1
  30.         player_switch = player_stat[0]
  31.         player_stat.pop(0)
  32.         player_stat.append(player_switch)
  33.         coordinates = input()
  34.         if counter % 2 == 0:
  35.             turns += 1
  36.         continue
  37.  
  38.     if matrix[player_row][player_col] == "B":
  39.         print(f"{player_stat[0][0]} won the game with {turns} throws!")
  40.         break
  41.     elif matrix[player_row][player_col] == "D":
  42.         current_points = (int(matrix[0][player_col]) + int(matrix[size - 1][player_col]) + int(matrix[player_row][0])
  43.                           + int(matrix[player_row][size - 1])) * 2
  44.         player_stat[0][1] -= current_points
  45.         if player_stat[0][1] <= 0:
  46.             print(f"{player_stat[0][0]} won the game with {turns} throws!")
  47.             break
  48.     elif matrix[player_row][player_col] == "T":
  49.         current_points = (int(matrix[0][player_col]) + int(matrix[size - 1][player_col]) + int(matrix[player_row][0])
  50.                           + int(matrix[player_row][size - 1])) * 3
  51.         player_stat[0][1] -= current_points
  52.         if player_stat[0][1] <= 0:
  53.             print(f"{player_stat[0][0]} won the game with {turns} throws!")
  54.             break
  55.     else:
  56.         player_stat[0][1] -= int(matrix[player_row][player_col])
  57.         if player_stat[0][1] <= 0:
  58.             print(f"{player_stat[0][0]} won the game with {turns} throws!")
  59.             break
  60.  
  61.     current_player = player_stat[0]
  62.     player_stat.pop(0)
  63.     player_stat.append(current_player)
  64.     counter += 1
  65.     if counter % 2 == 0:
  66.         turns += 1
  67.     coordinates = input()
  68.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement