I am writing code for Robot moving on a floor in the room ( considered center of the floor is origin (0,0)). Robot can move in any direction(south, east, west, north), touching different vertices in the floor. I would like to know how many unique vertices it touched.
For this, I am using a dynamic 2D array which records each stores vertex touches. So, the logic like this…if robot touches a vertex, that vertex will be checked in the array. If it is there, I do not increment my counter. At the end, I will get all unique vertices robot touched.
Is there any other better approach to find unique vertices robot touches.
Thanks.
I am writing code in C#. Size of the floor x-axis(-1,00,000 to 1,00,000), y-axis(-1,00,000 to 1,00,000)
It depends on the size of the floor. If it is small, then your approach is probably the best. Alternatively, if the floor size is so large that it is impractical to keep a complete map of it in memory, then rather use an associative array (or whatever the equivalent is in C#) with vertex coords as keys, and a simple boolean as the value, which will only record the vertices actually visited.