Question: how to test We are given a two - dimensional board of size N M ( N rows and M columns ) . Each field

how to test We are given a two-dimensional board of size NM ( N rows and M columns). Each field of the board can be empty ((.)), may contain an obstacle ('X') or may have a character in it. The character might be either an assassin ('A') or a guard. Each guard stands still and looks straight ahead, in the direction they are facing. Every guard looks in one of four directions (up, down, left or right on the board) and is represented by one of four symbols. A guard denoted by 'e' is looking to the left; by '>', to the right; ''c', up; or ' v ', down. The guards can see everything in a straight line in the direction in which they are facing, as far as the first obstacle ('X' or any other guard) or the edge of the board. The assassin can move from the current field to any other empty field with a shared edge. The assassin cannot move onto fields containing obstacles or enemies. Write a function: class Solution \{ public boolean solution(String[] B); \} that, given an array B consisting of N strings denoting rows of the array, returns true if is it possible for the assassin to sneak from their current location to the bottom-right cell of the board undetected, and false otherwise. Examples: 1. Given B=['X.....>,",.v...X.",".>...X..","A......"], your function should return false. All available paths lead through a field observed by a guard. 2. Given B=[...Xv,"AX.. A",". XX.."], your function should return true. The guard in the second row is blocking the other one from watching the bottom-right square. 3. Given B=[,...,">,A], your function should return false, as the assassin gets spotted right at the start. 4. Given B =['A.v",..."], your function should return false. It's not possible for the assassin to enter the bottom-right cell undetected, as the cell is observed. Write an efficient algorithm for the following assumptions: - N is an integer within the range [1..500]; - all strings in B are of the same length M from range [1..500]; - there is exactly one assassin on the board; - there is no guard or wall on B[N1][M1]; - every string in B consists only of the following characters '..,'X','<','>','v',''n' and/or 'A'.
Guards can appear the following way in the matrix: '<' represents a guard that is looking to the left, '>' represents a guard that is looking to the right, '^' looks up, and 'v' is looking down. Their line of sight extends as long as there is an obstacle, edge of the matrix or another guard.
Write a function that calculates whether the assassin can reach the bottom-right corner of the matrix. The assassin can not step in the line of sight of any guard.

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 Programming Questions!