3 Replies - 8398 Views - Last Post: 06 March 2012 - 05:21 PM Rate Topic: -----

#1 emmmily  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 1
  • Joined: 02-February 12

GRIDWORLD HELP!

Posted 02 February 2012 - 10:30 AM

Hello!

so, my assignment is to print out the adjacent empty space in gridworld when the bug makes moves..

here is my unfinished code:


public class PrintBug extends Bug
{

Grid gr = getGrid();
ArrayList<Location> locs = gr.getEmptyAdjacentLocations(getLocation…

private int steps ;
private int sidelength;

public PrintBug(int length)
{
steps = 0;
sidelength = length;
}

public void act()
{
if (steps < sidelength && canMove())
{
move();
steps++;
}
else
{
turn();
turn();
steps = 0;
}



this is what I have... and I'm stuck =(

please please help me... THANK YOU!

Is This A Good Question/Topic? 0
  • +

Replies To: GRIDWORLD HELP!

#2 modi123_1  Icon User is offline

  • Suitor #2
  • member icon



Reputation: 9579
  • View blog
  • Posts: 36,290
  • Joined: 12-June 08

Re: GRIDWORLD HELP!

Posted 02 February 2012 - 10:33 AM

Moving to the 'gridworld' section..
Was This Post Helpful? 0
  • +
  • -

#3 phoenix23  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 1
  • Joined: 07-February 12

Re: GRIDWORLD HELP!

Posted 07 February 2012 - 07:55 PM

I don't have the gridWorld framework installed on the computer I'm using right now, but wouldn't:

System.out.println(locs);


do the job? I'm not sure if Location has a toString() method, but I imagine it does.
Was This Post Helpful? 0
  • +
  • -

#4 wrightm96  Icon User is offline

  • D.I.C Head

Reputation: 6
  • View blog
  • Posts: 51
  • Joined: 06-March 12

Re: GRIDWORLD HELP!

Posted 06 March 2012 - 05:21 PM

Is what you want is to print the Location where the bug was before is moves?

If so, then you just need to print out the Location.

public class PrintBug extends Bug
{

Grid gr = getGrid();
ArrayList<Location> locs = gr.getEmptyAdjacentLocations(getLocation…

private int steps ;
private int sidelength;

public PrintBug(int length)
{
steps = 0;
sidelength = length;
}

public void act()
{
if (steps < sidelength && canMove())
{
System.out.println(getLocation());
move();
steps++;
}
else
{
turn();
turn();
steps = 0;
}




Was This Post Helpful? 0
  • +
  • -

Page 1 of 1