Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7192303
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T19:54:46+00:00 2026-05-28T19:54:46+00:00

I am making a program using the LRV(Least recently visited) Algorithm. Basically, I design

  • 0

I am making a program using the LRV(Least recently visited) Algorithm. Basically, I design the algorithm for a robot to traverse through a grid (which is a 2D char array). The robot whilst traversing the grid checks whether each cell is either EMPTY (defined by ‘O’), OCCUPIED ( defined by ‘S’ ) or BLOCKED (defined by ‘X’). The cells can only be occupied by an object known as Sensor (this has its own class). BLOCKED cells cannot be traversed on. Each time the robot must move, it receives a direction from the sensor. So in the beginning the robot would be placed on the grid and it would drop a sensor and get a direction from it, or get a direction from a pre-existing sensor.

Now that I’ve explained my program, my specific question is,
I have a class Sensor that has a getVisitingDirection method that returns INT.
I have a counter for each direction (North, South, East and West of type INT)
Here is the class.

package ITI1121A;
public class Sensor {

private int cColumns;
private int cRows;
private int North;
private int South;
private int West;
private int East;

public Sensor(int sX, int sY) { 

cColumns = sX;
cRows = sY;
South= -1;
North = -1;
West = -1;
East = -1;

}
/* ADD YOUR CODE HERE */
public int getX ()
{return cColumns;}
public int getY ()
{return cRows;}

public int getVisitingDirection(GridMap g1)
  boolean temp;
{
  if(cRows==0){
  //top row
    if(cColumns==0){
    temp=g1.isCellBlocked(cColumns+1,cRows);
    if (temp=false){
    return West++;
    }

    }

  }

}

public void increaseCounter(int direction)
{}

}

Now where I am stuck is at getVisitingDirection, I’ve tried to make if statements to check the top left edge of the grid ( coordinates 0,0) and yeah that’s about it.
I want the method to give a direction to the robot and then increase the counter of that direction.
Having real difficulty even getting the concept here.
Any help will be highly appreciated!
Thanks
Varun

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T19:54:47+00:00Added an answer on May 28, 2026 at 7:54 pm

    I’ve put a function in pseudo-code that should set you in the right path.

    // lets assume binary code where 0000 represents top, right, bottom, left 
    // (0011 would mean can go bottom or left)
    public int getVisitingDirection()
    {
        String tmpBinary = "b"; // to initialize the field
    
        // check if can go up
        tmpBinary += (cCollums>0&&checkIfUpIsBlocked()) "1" : "0";
        // TODO check if can go right (compare with size + 1)
        // check if can go bottom (compare with size +1 )
        // check if can go left (check if > 0)
    
        // when this runs tmpBinary will be in the form of a binary representation
        // this will be passed to the robot that can then chooses where to go
        // 1111 would mean that all squares are clear to go
        // 1101 would mean top, right and left
        // etc...
    
    }
    
    private boolean checkIfUpIsBlocked()
    {
        // TODO must check if the cell is blocked
        return true;
    }
    

    Do notice that you have to create the checkIfUpIsBlocked + methods.

    On top of that seams pretty good.
    You may want to change the int fields by enums as they are easier to read and less prone to human errors.

    How to return directions with an int number?
    You can use the binary logic and return a single int to represent multiple directions.

    0000 (int 0)  => no possible direction
    0001 (int 1)  => left direction
    0010 (int 2)  => bottom direction
    0011 (int 3)  => left and bottom
    0100 (int 4)  => right direction
    (...)
    1111 (int 15) => all directions possible
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am making a program using the LRV(Least recently visited) Algorithm. Basically, I design
I am making a program in which I established connection with sql server using
I am making a program which plays minesweeper automaticaly. I am using the mouse
I'm making a program in vb6. i;d like to connect using a proxy through
I am using the cool map making program DIY map and i want to
I am making a request to a CGI program using AJAX. The response sends
I'm making a program which the user build directories (not in windows, in my
I'm making a program that retrieves decently large amounts of data through a python
I'm making a program using RBing. But I unable to get 50 links. How
I'm making a program which needs to be listening for UDP Data at all

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.