Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

python 3 Write a function move.up) that takes one argument, board, which represe

ID: 3595715 • Letter: P

Question

python 3

Write a function move.up) that takes one argument, board, which represents the current state of the game board. Your function should move Starman up by one row, update the game board (if needed), and then return Starman's new location as [row number, column number]. Please 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: board! [[,.,, ,.,, ,.,, ,.,, ,N'] W' board2 board3 = [ [ , . , , Return Value Function Call move.up (board1) [2, 3] move.up (board2)[-1, -1] move.up (board3)[-1, -1] Updated boards: board! [[,.,, ,.,, ,.,, ,.,, ,N'] board2= [[,.,, ,*,, ,.. board3= [[, .,, ,0, , ,.,, ,.,, ,.,j,

Explanation / Answer

def move_up(board):
for i in range(len(board)):
for j in range(len(board[i])):
if board[i][j] == '*':
if i-1 >= 0 and board[i-1][j] != 'W':
board[i-1][j] = '*'
board[i][j] = '.'
return [i, j+1]
return [-1, -1]
return [-1, -1]

board1 = [['.', '.', '.', '.', 'W'],
['.', '.', '.', '.', '.'],
['.', 'F', '*', 'F', '.'],
['.', '.', 'O', '.', 'W'],
['.', '.', 'O', '.', '.']]
print(move_up(board1))
print(board1)

board1 = [['.', 'O', '.', '.', '.'],
['.', '.', 'F', '.', '.'],
['W', '.', 'F', '.', '.'],
['*', 'O', '.', '.', '.'],
['.', '.', '.', '.', 'F']]
print(move_up(board1))
print(board1)

# copy pastable version: https://paste.ee/p/Mg9et