9 Replies - 12289 Views - Last Post: 08 September 2009 - 02:34 PM Rate Topic: -----

#1 hlln   User is offline

  • D.I.C Head

Reputation: 5
  • View blog
  • Posts: 89
  • Joined: 12-July 09

GridWorld help?

Post icon  Posted 03 September 2009 - 06:34 PM

i have a program to move the actor to the leftbut all it does is mirror it self and
how come its starting location is on the left and it is supposed to be in the middle and move left.
mport java.awt.Color;
import info.gridworld.grid.Grid;
import info.gridworld.actor.Actor;
import info.gridworld.grid.Location;
import info.gridworld.actor.ActorWorld;

public class MoveLeftActor extends Actor
{
	public void act()
	{
		Location loc = getLocation();
		
		//add code here to make the actor
		//move to the right
		int row = loc.getRow();
		int col = loc.getCol();
		Location loc2 = new Location(row, col+1);
		moveTo(loc2);
	}
}


and u need a second one to extend the actor
import java.awt.Color;
import info.gridworld.actor.Actor;
import info.gridworld.grid.Location;
import info.gridworld.grid.BoundedGrid;
import info.gridworld.actor.ActorWorld;

public class MoveLeftActorRunner
{
	public static void main(String[] args)
	{
		ActorWorld world = new ActorWorld();
		world.add(new Location(1, 0), new Actor());
		world.show(); 
	}
}


ty if you help

Is This A Good Question/Topic? 0
  • +

Replies To: GridWorld help?

#2 Fuzzyness   User is offline

  • Comp Sci Student
  • member icon

Reputation: 669
  • View blog
  • Posts: 2,438
  • Joined: 06-March 09

Re: GridWorld help?

Posted 04 September 2009 - 12:39 AM

Your act method is going to move it to the right by one column, and as far as it supposedly going to be in the middle that is incorrect. It is prolly in top left corner right?

world.add(new Location(1, 0), new Actor());

Because that is where you put it to add.

Mirrors itself? Not sure I understand what your trying to say there
Was This Post Helpful? 0
  • +
  • -

#3 hlln   User is offline

  • D.I.C Head

Reputation: 5
  • View blog
  • Posts: 89
  • Joined: 12-July 09

Re: GridWorld help?

Posted 05 September 2009 - 07:21 PM

i got it to run and it moves BUTT it makes exceptions on the cmd prompt becuase it cannot go off the gird. I have to move it back to the same row but all the way to the right and loop it. so it will keep going left
Was This Post Helpful? 0
  • +
  • -

#4 Fuzzyness   User is offline

  • Comp Sci Student
  • member icon

Reputation: 669
  • View blog
  • Posts: 2,438
  • Joined: 06-March 09

Re: GridWorld help?

Posted 06 September 2009 - 11:33 PM

Um.. do youhave to use an Actor or can you use a bug? a Bug automatically has the preset in it. if not just make an if statement for it
if(getLocation().getCol() == getGrid().getNumCols())
	 if(getLocation().getRow() == getGrid().getNumRows())
		moveTo(new Location(0,0));
	 else moveTo(new Location(getLocation.getLoc() +1, 0));


Will check to see if it is in the max column, if not will continue to move normally, if it is, will check the row, if in max row as well, it will move it to the very first row and column, otehrwise will move down a row and start at the 0 column.

Hope this helps!

This post has been edited by Fuzzyness: 07 September 2009 - 11:11 AM

Was This Post Helpful? 0
  • +
  • -

#5 carltech   User is offline

  • What did you call me?
  • member icon

Reputation: 28
  • View blog
  • Posts: 997
  • Joined: 19-October 07

Re: GridWorld help?

Posted 07 September 2009 - 12:48 AM

i would agree with fuzzyness.

@hlln don't forget that the top left corner is coordinate (0,0) and moves right and down

(0,0).---------->
|
|
|
v
Was This Post Helpful? 0
  • +
  • -

#6 SpeedisaVirus   User is offline

  • Baller

Reputation: 115
  • View blog
  • Posts: 855
  • Joined: 06-October 08

Re: GridWorld help?

Posted 07 September 2009 - 09:44 AM

You could use this to provide wrap around:

Something like index % length.

Say you had a 6x6 grid. Your token is in the last spot on the right and you try to move right. You would be reaching for index 6 which doesn't exist and you would have 6 % 6 = 0. Putting you to the left side. Applies to rows and columns. No more going off the grid because it will come out the other side.

Oh, I could have screwed up here. Partied too hard yesterday...brain is slow.

This post has been edited by SpeedisaVirus: 07 September 2009 - 09:45 AM

Was This Post Helpful? 0
  • +
  • -

#7 Fuzzyness   User is offline

  • Comp Sci Student
  • member icon

Reputation: 669
  • View blog
  • Posts: 2,438
  • Joined: 06-March 09

Re: GridWorld help?

Posted 07 September 2009 - 11:12 AM

Well, Gridworld isnt just a manual made grid, it actually has its own classes and actors and rules and what not. so there is no index, there is location column and row, and what I did was pretty much wbat your saying.

If I misunderstood you then my apologies, but Gridworld is its own thing.

I quite hate it actually ^^
Was This Post Helpful? 0
  • +
  • -

#8 SpeedisaVirus   User is offline

  • Baller

Reputation: 115
  • View blog
  • Posts: 855
  • Joined: 06-October 08

Re: GridWorld help?

Posted 07 September 2009 - 01:59 PM

Yeah, I guess I didn't explain it well or maybe I don't quite get whats going on. I bet it's that I am lost :P

Still though you can use modulo math to make sure your new locations end up in the grid and wrap around when you get to the ends. This is what I was primarily talking about:

Quote

i got it to run and it moves BUTT it makes exceptions on the cmd prompt becuase it cannot go off the gird. I have to move it back to the same row but all the way to the right and loop it. so it will keep going left


That would indicate to me that you have a function somewhere that translates that loc2 data to a location on the grid and the grid has a maxRow and maxCol. You can use module math to ensure the parameters of the new location either fall in or wrap around to the other side.
Was This Post Helpful? 0
  • +
  • -

#9 hlln   User is offline

  • D.I.C Head

Reputation: 5
  • View blog
  • Posts: 89
  • Joined: 12-July 09

Re: GridWorld help?

Posted 08 September 2009 - 09:48 AM

i have 10x10 grid
Was This Post Helpful? 0
  • +
  • -

#10 Fuzzyness   User is offline

  • Comp Sci Student
  • member icon

Reputation: 669
  • View blog
  • Posts: 2,438
  • Joined: 06-March 09

Re: GridWorld help?

Posted 08 September 2009 - 02:34 PM

yes yes, but sometimes you can change the bounded grid to something bigger and I dont like using magic numbers so I used the maxNumCol to see if it is on the last column. and as I sit here thinking about it you need to change it to
getGrid().getNumCols() -1 because the grid starts at 0 and will go to 9 if you have a 10 x 10.

Did your problems get solved? Errors in code still there? Where do you stand now?

Update please!! :)


Edit - Just read and if your just keeping it on the same row then it is a very very simple process that can be done with a single if statement
if(getLocation().getCol() == getGrid().getNumCols() -1)
	 moveTo(new Location(getLocation.getRow(),0));


That will keep it running on same row, what I did before was have it go left to right bottom to top, my bad missread :)

This post has been edited by Fuzzyness: 08 September 2009 - 02:38 PM

Was This Post Helpful? 1
  • +
  • -

Page 1 of 1