Python programming Part V: Move Starman Right (15 points) Write a function move.
ID: 3596159 • Letter: P
Question
Python programming
Part V: Move Starman Right (15 points) Write a function move.right o that takes one argument, board, which represents the curent state of the CSE 101-Fall 2017 Homework #3 Page 7 game board Your function should move Starman right by one column, update the game hoard Gif needed), and then return Starman's new location as [row number, column number]. Plcase note that these are the real row and column numbers, not the indexes in the board list. Special rules apply: please check General Tasks for Parts II through V above. Examples: boardiIEEW wr board2 LFWE', board3 -o., Function Call Return Value move.right 14, 31 move.right 13, 31 move.right [3, Updated boards: SAMSUNExplanation / Answer
def move_right(board):
list = []
for i in range(len(board)):
for j in range(len(board[i])):
if board[i][j] == '*':
if board[i][j+1] == '.':
board[i][j] = '.'
board[i][j+1] = '*'
list.extend((i+1,j+2))
break
if board[i][j+1] == 'F':
board[i][j] = '.'
board[i][j+1] = '*'
list.extend((i+1,j+2))
break
if board[i][j+1] == 'O':
board[i][j] = '.'
board[i][j+1] = 'X'
list.extend((i+1,j+2))
break
return list
board1 = [['F','F','F','.','W'],
['.','.','.','.','.'],
['.','F','O','F','.'],
['.','*','.','.','.'],
['.','O','O','.','.']]
board2 = [['F','W','F','.','W'],
['.','.','.','.','.'],
['.','*','O','F','.'],
['W','.','.','.','.'],
['.','W','O','.','.']]
board3 = [['.','O','.','.','.'],
['.','.','F','.','.'],
['W','*','F','.','.'],
['W','O','.','.','.'],
['.','.','.','.','F']]
print(move_right(board1))
print(move_right(board2))
print(move_right(board3))
print("Updated boards")
print("board1")
for i in range(len(board1)):
print(board1[i])
print("board2")
for i in range(len(board2)):
print(board2[i])
print("board3")
for i in range(len(board3)):
print(board3[i])
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.