Java Forums

Main Menu
Home
Today's Posts
FAQ
Search
Contact Us

Java Network
Java Tips
Java Tips Blog

Sponsored Links





Welcome to the Java Forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community, you will:

  • have access to post topics
  • communicate privately with other members (PM)
  • not see advertisements between posts
  • have the possibility to earn one of our surprises if you are an active member
  • access many other special features that will be introduced later.

Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact us.

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 07-04-2007, 05:58 PM
Member
 
Join Date: Jul 2007
Posts: 1
L67Pontiac is on a distinguished road
Need help with becker robots problem please.
Hi, I've been having trouble with this problem. I can't seem to make the robot move for very long or go many places, but I need him to go everywhere and pick everything up. All help would be greatly appreciated.



/**
Main Task: Pick up all the things inside the wall.
Note: The robot does not know where all the things are.
nor does it know if there is anthing obstructing its way.
Use selection, iteration, and sequence to create this algorithm.

Notes:
1. The robot should be able to pick up everything within the walls
2. The size of the walls and the number of objects WILL be different
when running the program
4. It is possible to have several Things on the same space
3. Please do not change the name of the class
*/

Code:
import becker.robots.*; import java.math.*; import java.awt.Rectangle; import java.awt.Color; import java.awt.geom.Rectangle2D; public class Problem { public static void main(String[] arg) { // Initialize the setup randomly int height = 0, width = 0, top = 1, left = 1, thingCount = 5, startx = 0, starty = 0; height = (int)(Math.random() * 5) + 3; width = (int)(Math.random() * 5) + 3; startx = (int)(Math.random() * width) + left; starty = (int)(Math.random() * height) + top; City newYork = new City(); Robot guy = new Robot(newYork, starty, startx, Direction.EAST); Wall[] cityWalls = makeWalls(newYork, width, height, top, left); Thing[] things = fillWalls(newYork, width, height, top, left, thingCount); // Your code goes here while(guy.frontIsClear()) { guy.move(); } while(guy.canPickThing()) { guy.pickThing(); } guy.turnLeft(); while (guy.frontIsClear()) { guy.move(); while (guy.canPickThing()) { guy.pickThing(); uTurn(guy); } } uTurn(guy); } private static void faceDirection(Robot r, Direction dir) { while(r.getDirection() != dir) { r.turnLeft(); } } private static void uTurn(Robot r) { for (int i = 0; i < 2; i++) { r.turnLeft(); } } private static Wall[] makeWalls(City city, int width, int height, int top, int left){ Wall[] walls = new Wall[width * 2 + height * 2]; int i = 0; int index = 0; // create top and bottom for (i = 0; i < width; i++){ walls[i] = new Wall(city, top, left + i, Direction.NORTH); walls[i + width] = new Wall(city, top + height - 1, left + i, Direction.SOUTH); } index = i + width; // create sides for (i = 0; i < height; i++){ walls[index + i] = new Wall(city, top + i, left, Direction.WEST); walls[index + i + height] = new Wall(city, top + i, left + width - 1, Direction.EAST); } return walls; } private static Thing[] fillWalls(City city, int width, int height, int top, int left, int objects){ Thing things[] = new Thing[objects]; int avenue = 0, street = 0; for (int i = 0; i < objects; i++){ avenue = (int)(Math.random() * width) + left; street = (int)(Math.random() * height) + top; things[i] = new Thing(city, street, avenue); } return things; } }

Last edited by JavaBean : 07-06-2007 at 08:45 PM. Reason: Codes should be placed inside [code] tag.
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 07-06-2007, 08:50 PM
JavaBean's Avatar
Moderator
 
Join Date: May 2007
Posts: 1,272
JavaBean is on a distinguished road
We need the Robot class. What are the capabilities (methods) of a robot?

Basically, you will need to do four things at each time step. You can do that in a while loop:

1. Check if the robot can pick things. If robot can pick things, pick them.
2. Check if there is a wall in front of the robot. If there is a wall, u-turn.
3. Select a random direction and move a little bit.
4. Return to step 1.
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
How to control robots and other devices francojava Advanced Java 0 01-24-2008 05:03 PM
becker.robots problem. jesse New To Java 1 11-26-2007 11:25 PM


All times are GMT +3. The time now is 06:02 AM.


VBulletin, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2007, Crawlability, Inc.
Copyright ©2006 - 2007, www.java-forums.org