Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- n = int(input())
- galaxy = [[x for x in input()] for _ in range(n)]
- # print(galaxy)
- energy = 0
- def begin(g):
- for i in range(len(g)):
- for j in range(len(g)):
- if g[i][j] == 'S':
- s = [i, j]
- return s[0], s[1]
- def zero_position(galaxy):
- p = []
- for i in range(len(galaxy)):
- for j in range(len(galaxy)):
- if galaxy[i][j] == 'O':
- p.append(i)
- p.append(j)
- return p
- def moves(c, row, col, z):
- global galaxy
- directions = {
- 'up': [row-1, col],
- 'down': [row+1, col],
- 'left': [row, col-1],
- 'right': [row, col+1]
- }
- galaxy[row][col] = '-'
- if 0 <= directions[c][0] < len(galaxy) and 0 <= directions[c][1] < len(galaxy):
- p_1, p_2 = directions[c][0], directions[c][1]
- if galaxy[p_1][p_2] == 'O':
- galaxy[p_1][p_2] = '-'
- for i in range(0, len(z), 2):
- if p_1 != z[i]:
- galaxy[z[i]][z[i+1]] = 'S'
- p_1, p_2 = z[i], z[i+1]
- else:
- return
- return p_1, p_2
- def action(r, c):
- e = 0
- if galaxy[r][c].isdigit() and galaxy[r][c] != '0':
- e += int(galaxy[r][c])
- galaxy[r][c] = 'S'
- return e
- zeroes = zero_position(galaxy)
- start = begin(galaxy)
- while True:
- command = input()
- try:
- move_1, move_2 = moves(command, start[0], start[1], zeroes)
- energy += action(move_1, move_2)
- if energy >= 50:
- print("Good news! Stephen succeeded in collecting enough star power!")
- print(f"Star power collected: {energy}")
- break
- except TypeError:
- print("Bad news, the spaceship went to the void.")
- print(f"Star power collected: {energy}")
- break
- start = (move_1, move_2)
- [print(''.join(row)) for row in galaxy]
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement