Algorithm for detecting windows in a room

Posted by user2733436 on Programmers See other posts from Programmers or by user2733436
Published on 2014-05-27T00:08:07Z Indexed on 2014/05/27 3:40 UTC
Read the original article Hit count: 265

Filed under:

enter image description here

I am dealing with the following problem and i was looking to write a Pseudo-code for developing an algorithm that can be generic for such a problem.

Here is what i have come up with thus far.

STEP 1

In this step i try to get the robot where it maybe placed to the top left corner.

Turn Left -> If no window or Wall detected keep going forward 1 unit..

if window or wall detected ->Turn right --> if no window or Wall detected keep going forward..

if window or wall detected then top left corner is reached.

STEP 2 (We start counting windows after we get to this stage to avoid miscounting)

I would like to declare a variable called turns as it will help me keep track if robot has gone around entire room.

Turns = 4;

Now we are facing north and placed on top left corner.

while(turns>0){

If window or wall detected (if window count++)

Turn Right

Turn--;

While(detection!=wall || detection!=window){

move 1 unit forward

Turn left (if window count++)

Turn right

}

}

I believe in doing so the robot will go around the entire room and count windows and it will stop once it has gone around the entire room as the turns get decremented. I don't feel this is the best solution and would appreciate suggestions on how i can improve my Pseudo-code. I am not looking for any code just a algorithm on solving such a problem and that is why i have not posted this in stack overflow. I apologize if my Pseudo-code is poorly written please make suggestions if i can improve that as i am new to this. Thanks.

© Programmers or respective owner

Related posts about algorithms