Alice Community

Alice Community (http://www.alice.org/community/index.php)
-   How do I...? (http://www.alice.org/community/forumdisplay.php?f=16)
-   -   How to make a robot pick up 19 rocks in order of the nearest to the robot. (http://www.alice.org/community/showthread.php?t=8125)

hydude777 02-23-2012 07:39 AM

How to make a robot pick up 19 rocks in order of the nearest to the robot.
 
1 Attachment(s)
Suppose there are 19 rocks on the ground, separated in random positions.
A robot, starting from approximately center of the rocks, goes off to collect rocks that are NEAREST to the robot's position. After collecting all 19 rocks, the robot returns to its original place.
How would you do it??????????????????????????????????????

This is what i have currently, and it seems to be not working so well.....

Mr Kidnapper 02-23-2012 09:37 AM

Getting into array lists?
The deal is to get every object that is picked up in one list. You've probably done that already.
The way we'd do this in Java is that we would make a for loop (In this case, a "Do All in Order") We would then set a number variable to the first index's distance away from the robot, as well as another variable with the actual index number. We would then go down the list with this loop, checking if each object in the list's distance away from the robot is less than our variable. If it is, the object's distance away and index will replace the respective variables. If it isn't, do nothing and move to the next index.

After the loop is done, we would have the robot move to the closest index of the list as found in the previous method and collect it by making it no longer show. We would then have this process repeated until all rocks are collected. This can be done with another loop, a Do All Together for efficiency, to find if all of the rocks "are Showing".

hydude777 02-23-2012 02:20 PM

Thank you Mr.K for helping me all the time I post questions,
you've been a great help!
Thanks very much!


All times are GMT -5. The time now is 12:12 AM.

Copyright ©2024, Carnegie Mellon University
Alice 2.x © 1999-2012, Alice 3.x © 2008-2012, Carnegie Mellon University. All rights reserved.