Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class Ground {
- Item myBoard[][];
- ArrayList<Robot> myList=null;
- LinkedList<GeometricElement> mySapesList=null;
- protected Dot size;
- public Ground(int row,int col)
- {
- myBoard=new Item[size.getRow()][size.getCol()];
- for (int i=0;i< size.getRow();i++)
- for (int j=0;j< size.getRow();j++)
- {
- myBoard[i][j]=new Item();
- }
- size=new Dot(row, col);
- myList=new ArrayList<Robot>();
- mySapesList=new LinkedList<GeometricElement>();
- }
- public Dot getSize() {
- return size;
- }
- public void eatAllTheShapes()
- {
- //pass on all the shapse and ate them
- for (int i=0;i<mySapesList.size();i++)
- {
- eatShape(mySapesList.get(i));
- }
- }
- public void eatShape(GeometricElement elem)
- {
- //first calcluate the nierst shape(we asume anormal size of the ground)
- float distance=1000000000;
- //find the minmum distance
- for(int i=0;i<myList.size();i++)
- {
- if( distance<(myList.get(i).calculateRealDistanceFromDot(elem.getD()))&&
- myList.get(i).getSize()-elem.getArea()>=0)
- {
- distance=myList.get(i).calculateRealDistanceFromDot(elem.getD());
- }
- }
- //naw after we now the closest distance we find the closest robot
- for(int i=0;i<myList.size();i++)
- {
- if( distance==(myList.get(i).calculateRealDistanceFromDot(elem.getD())))
- {
- //update the distance the robot went
- myList.get(i).setSumDist(myList.get(i).calculateDistanceFromDot((elem.getD())));
- //update the realdistance the robot went
- myList.get(i).setSumRealDist(myList.get(i).calculateRealDistanceFromDot(elem.getD()));
- //set the postion of the robot to the place of the shape
- myList.get(i).setPosion(elem.getD());
- elem.setEaten(true);
- }
- }
- //Collections.max(myList, comp)
- }
- public void printFinalRestlt()
- {
- //print the resukt of the robots
- for(int i=0;i<myList.size();i++)
- {
- System.out.println("ROBOT NUM"+i);
- System.out.println(myList.get(i));
- }
- for(int i=0;i<mySapesList.size();i++)
- {
- if(!mySapesList.get(i).isEaten())
- System.out.println("shape"+i+"didnt eaten");
- }
- }
- }
Add Comment
Please, Sign In to add comment