Advertisement
Guest User

Untitled

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