Advertisement
Help Keep Boards Alive. Support us by going ad free today. See here: https://subscriptions.boards.ie/.
If we do not hit our goal we will be forced to close the site.

Current status: https://keepboardsalive.com/

Annual subs are best for most impact. If you are still undecided on going Ad Free - you can also donate using the Paypal Donate option. All contribution helps. Thank you.
https://www.boards.ie/group/1878-subscribers-forum

Private Group for paid up members of Boards.ie. Join the club.

Tell my robot where to go

  • 25-03-2013 04: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,559 ✭✭✭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