In [40]:
def roll_dice(map_size, location, space, orders):
dice_ew = [0,0]
dice_ns = [0,0]
dice_tb = [0,0]
for order in orders:
if order=="1":
if location[1] < map_size[1] -1:
location[1] += 1
dice_ew.reverse()
a = dice_ew
dice_ew = dice_tb
dice_tb = a
if space[location[0]][location[1]] != 0:
dice_tb[1] = space[location[0]][location[1]]
space[location[0]][location[1]] = 0
print(dice_tb[0])
else:
space[location[0]][location[1]] = dice_tb[1]
print(dice_tb[0])
else:
continue
elif order == "2":
if location[1] > 0:
location[1] -= 1
dice_tb.reverse()
a = dice_ew
dice_ew = dice_tb
dice_tb = a
if space[location[0]][location[1]] != 0:
dice_tb[1] = space[location[0]][location[1]]
space[location[0]][location[1]] = 0
print(dice_tb[0])
else:
space[location[0]][location[1]] = dice_tb[1]
print(dice_tb[0])
else:
continue
elif order == "3":
if location[0] > 0 :
location[0] -= 1
dice_ns.reverse()
a = dice_ns
dice_ns = dice_tb
dice_tb = a
if space[location[0]][location[1]] != 0:
dice_tb[1] = space[location[0]][location[1]]
space[location[0]][location[1]] = 0
print(dice_tb[0])
else:
space[location[0]][location[1]] = dice_tb[1]
print(dice_tb[0])
else:
continue
elif order == "4":
if location[0] < map_size[0]-1:
location[0] += 1
dice_tb.reverse()
a = dice_ns
dice_ns = dice_tb
dice_tb = a
if space[location[0]][location[1]] != 0:
dice_tb[1] = space[location[0]][location[1]]
space[location[0]][location[1]] = 0
print(dice_tb[0])
else:
space[location[0]][location[1]] = dice_tb[1]
print(dice_tb[0])
else:
continue
In [39]:
first_input = list(map(int,input().split()))
map_size = [first_input[0],first_input[1]]
location = [first_input[2],first_input[3]]
space = []
for i in range(map_size[0]):
sp = list(map(int,input().split()))
space.append(sp)
orders = list(input().split())
roll_dice(map_size, location, space, orders)
In [41]:
first_input = list(map(int,input().split()))
map_size = [first_input[0],first_input[1]]
location = [first_input[2],first_input[3]]
space = []
for i in range(map_size[0]):
sp = list(map(int,input().split()))
space.append(sp)
orders = list(input().split())
roll_dice(map_size, location, space, orders)
In [42]:
first_input = list(map(int,input().split()))
map_size = [first_input[0],first_input[1]]
location = [first_input[2],first_input[3]]
space = []
for i in range(map_size[0]):
sp = list(map(int,input().split()))
space.append(sp)
orders = list(input().split())
roll_dice(map_size, location, space, orders)
In [43]:
first_input = list(map(int,input().split()))
map_size = [first_input[0],first_input[1]]
location = [first_input[2],first_input[3]]
space = []
for i in range(map_size[0]):
sp = list(map(int,input().split()))
space.append(sp)
orders = list(input().split())
roll_dice(map_size, location, space, orders)