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

You are asked to write a program for a game using a Brain-Computer-Interface whe

ID: 3835626 • Letter: Y

Question

You are asked to write a program for a game using a Brain-Computer-Interface where the user gives left/right/up/down commands to move on a board and collect points. Write a function bciboardgame(m,x,y,moves) that takes a matrix m representing the board and x,y coordinates representing the row and column indices of the user's current location. The moves represents the sequence of user commands, as a vector of integers between 1 and 4 (1: left, 2:right, 3:up, 4:down). Your program should start at x,y coordinates, and move around the board according to user's commands and return the total number of points the user collects, including the points on the starting position. Assume that the user will not try to move off the board.

Explanation / Answer

PROGRAM CODE:

function sum = bciboardgame(m, x, y, moves)
   sum = m(x,y)
   for i = 1:length(moves)
       if moves(i) == 1
           y = y-1
       elseif moves(i) == 2
           y = y+1
       elseif moves(i) == 3
           x = x-1
       else
           x = x+1
       end
       sum += m(x,y)
   end
end

disp(bciboardgame([10 20; 30 40], 1, 1, [2 4 1 3 2 4 1 3]))

OUTPUT:

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote