Advertisement
Guest User

Untitled

a guest
Oct 16th, 2019
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.68 KB | None | 0 0
  1.     public static int findOre (List<Grid> G, robot myRobot)
  2.     {
  3.         int index = -404; //stands for 404 - has not found any ore
  4.         double distance = 30*30 + 15*15+1; //just a number, so my program thinks it's the biggest distance ever
  5.         for(int i = 0; i < G.Count(); i++)
  6.         {
  7.             if (G[i].status != "?" && G[i].status != "0")
  8.             {
  9.                 double newDistance = Math.Pow(myRobot.x - G[i].x,2) + Math.Pow(myRobot.y - G[i].y,2);
  10.                 if( newDistance < distance)
  11.                 {
  12.                     distance = newDistance;
  13.                     index = i;
  14.                 }
  15.             }
  16.         }
  17.         return index;
  18.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement