Advertisement
Nenogzar

02_the_gambler

Jun 18th, 2024
574
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.85 KB | None | 0 0
  1. https://judge.softuni.org/Contests/Practice/Index/4226#1
  2.  
  3. def directions(position, direction, rows, matrix):
  4.     row, col = position
  5.     matrix[row][col] = "-"
  6.  
  7.     moves = {
  8.         'up': (-1, 0),
  9.         'down': (1, 0),
  10.         'left': (0, -1),
  11.         'right': (0, 1)
  12.     }
  13.  
  14.     d_row, d_col = moves[direction]
  15.     row += d_row
  16.     col += d_col
  17.     if 0 <= row < rows and 0 <= col < rows:
  18.         return row, col, matrix
  19.     return None
  20.  
  21. def main():
  22.     rows = int(input())
  23.     game_board = []
  24.     gambler = "G"
  25.     amount = 0
  26.     position = (-1, -1)
  27.     neshto = {
  28.         'W': 100,
  29.         'P': -200,
  30.         'J': 100000
  31.     }
  32.  
  33.     for row_ in range(rows):
  34.         line = list(input())
  35.         if gambler in line:
  36.             amount += 100
  37.             position = (row_, line.index(gambler))
  38.         game_board.append(line)
  39.  
  40.     target = input()
  41.  
  42.     while target != "end":
  43.         result = directions(position, target, rows, game_board)
  44.         if result is None:
  45.             print("Game over! You lost everything!")
  46.             return
  47.         else:
  48.             new_row, new_col, game_board = result
  49.             new_position = (new_row, new_col)
  50.  
  51.             step = game_board[new_row][new_col]
  52.  
  53.             if step in neshto:
  54.                 amount += neshto[step]
  55.                 if amount <= 0:
  56.                     print("Game over! You lost everything!")
  57.                     return
  58.                 if step == "J":
  59.                     game_board[new_row][new_col] = gambler
  60.                     print("You win the Jackpot!")
  61.                     break
  62.  
  63.             game_board[new_row][new_col] = gambler
  64.             position = new_position
  65.  
  66.         target = input()
  67.  
  68.     print(f"End of the game. Total amount: {amount}$")
  69.     for pr in game_board:
  70.         print("".join(pr))
  71.  
  72. if __name__ == "__main__":
  73.     main()
  74.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement