Question: Write a function move() that takes the following arguments, in this order: 1. board: A game board. 2. movement: A string that represents what kind

Write a function move() that takes the following arguments, in this order:

1. board: A game board.

2. movement: A string that represents what kind of movement that Starman needs to perform. Four movement commands are listed below:

U: go up one row

D: go down one row

L: go left one column

R: go right one column

Note: You may assume that the movement is always one of the four valid ones in this part.

This function should call the four functions you wrote for Parts II through V.

Your move() function should check the value of movement and then perform the corresponding movement by calling the appropriate function you write in Part II through V. move() must also return the value that is returned from the function that it calls. As an example, if the value of movement is U, then move() will

return whatever value is returned by move up().

Hint: Dont over-think this problem it is literally four conditional statements based on movements value. Under each conditional statement you call one of the move X() functions and return the result from the function call.

Examples:

board1 = [[., W, W, ., W],

[F, F, ., ., F],

[., O, ., W, *],

[., ., ., W, .],

[O, ., O, ., .]]

board2 = [[., F, ., F, .],

[., ., O, ., .],

[., ., O, *, .],

[W, W, ., O, .],

[., ., ., W, .]]

board3 = [[F, W, F, ., W],

[., ., ., ., .],

[W, *, O, F, .],

[W, ., ., ., .],

[., W, O, ., .]]

board4 = [[., O, ., ., .],

[., F, F, ., .],

[W, *, F, F, .],

[F, O, ., ., .],

[., ., ., ., F]]

Function Call Return Value

move(board1, U) [2, 5]

move(board2, D) [4, 4]

move(board3, L) [-1, -1]

move(board4, R) [3, 3]

Updated boards:

board1 = [[., W, W, ., W],

[F, F, ., ., *],

[., O, ., W, .],

[., ., ., W, .],

[O, ., O, ., .]]

board2 = [[., F, ., F, .],

[., ., O, ., .],

[., ., O, ., .],

[W, W, ., X, .],

[., ., ., W, .]]

board3 = [[F, W, F, ., W],

[., ., ., ., .],

[W, *, O, F, .],

[W, ., ., ., .],

[., W, O, ., .]]

board4 = [[., O, ., ., .],

[., F, F, ., .],

[W, ., *, F, .],

[F, O, ., ., .],

[., ., ., ., F]]

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!