Advertisement
Guest User

Untitled

a guest
Oct 15th, 2019
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.42 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. }
  34.  
  35. //Methods for basic robot-functions //Basic functions for easier testing and programming
  36. public static void move(int x, int y) => Console.WriteLine("MOVE {0} {1}",x,y);
  37. public static void dig(int x, int y) => Console.WriteLine("DIG {0} {1}",x,y);
  38. public static void request(string x) => Console.WriteLine("REQUEST {0}",x);
  39. public static void wait() => Console.WriteLine("WAIT");
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement