Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie
Hi there,
There is an issue with role permissions that is being worked on at the moment.
If you are having trouble with access or permissions on regional forums please post here to get access: https://www.boards.ie/discussion/2058365403/you-do-not-have-permission-for-that#latest

Tell my robot where to go

  • 25-03-2013 4:30pm
    #1
    Registered Users, Registered Users 2 Posts: 22


    I am writing a Java program that allows a user to send messages to a robot to tell it where to go on a 5x5 grid. E.g, if I send it 'FRFFLF', this means go forward, run right 90 degrees, forward twice, turn left 90 degrees and then go forward. The program then returns the robot's new position on the grid.

    I'm not seeking a solution, just some guidelines on my approach. Are there already design patterns available for such a program (so I'm not reinventing the wheel) or is it possible to write from scratch?

    The bottom of the grid is (0,0 and the top would be (4,4).

    I'm thinking that the Robots position could be defined as a Java Point class and the grid would be a 2D array?

    Is it as simple as this approach?
    public Point forward(Point p) {
        p.x +=1;
        return p;
    }
    
    Has anyone every tried to write such a program? Is it possible?


Comments

  • Registered Users, Registered Users 2 Posts: 2,588 ✭✭✭KonFusion


    AbuseMePlz wrote: »
    Has anyone every tried to write such a program? Is it possible?

    Yup. Was a second year college project. Presume this is for college too? Out of curiosity, what college are you in?

    There's quite a few of these types of programs out there. Common enough college projects.


  • Registered Users, Registered Users 2 Posts: 22 AbuseMePlz


    KonFusion wrote: »
    Yup. Was a second year college project. Presume this is for college too? Out of curiosity, what college are you in?

    There's quite a few of these types of programs out there. Common enough college projects.

    Nope, not a college project. I am working on grid traversal in my job and was told solving this type of puzzle is a good way to learn before moving on to moe complex grids.


  • Registered Users, Registered Users 2 Posts: 851 ✭✭✭TonyStark


    AbuseMePlz wrote: »
    I am writing a Java program that allows a user to send messages to a robot to tell it where to go on a 5x5 grid. E.g, if I send it 'FRFFLF', this means go forward, run right 90 degrees, forward twice, turn left 90 degrees and then go forward. The program then returns the robot's new position on the grid.

    I'm not seeking a solution, just some guidelines on my approach. Are there already design patterns available for such a program (so I'm not reinventing the wheel) or is it possible to write from scratch?

    The bottom of the grid is (0,0 and the top would be (4,4).

    I'm thinking that the Robots position could be defined as a Java Point class and the grid would be a 2D array?

    Is it as simple as this approach?
    public Point forward(Point p) {
        p.x +=1;
        return p;
    }
    
    Has anyone every tried to write such a program? Is it possible?


    Firstly you need the direction of the robot and its current position. From there you will be encapsulating the grid creating a few rules around boundaries. Basically you will update the position of the robot interpreting the commands passed to it and updating the position based of the robot. Obviously the robot will need to only move within the bounds of the grid.


Advertisement