Advertisement
Guest User

C# Code example

a guest
Oct 15th, 2019
151
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.70 KB | None | 0 0
  1. //GRID CLASS
  2. public class Grid
  3. {
  4. public int x { get; set; }
  5. public int y { get; set; }
  6. public string status { get; set; }
  7. public int hole { get; set; }
  8. public Grid ()
  9. {
  10. status = "?";
  11. }
  12.  
  13. }
  14. //ROBOT CLASS
  15. public class robot
  16. {
  17. public int x { get; set; }
  18. public int y { get; set; }
  19. public int item {get; set;}
  20. public int id {get; set;}
  21. public robot (int _x, int _y, int _item)
  22. {
  23. x = _x;
  24. y = _y;
  25. item = _item;
  26. }
  27. }
  28.  
  29. public static int findOre (List<Grid> G, robot myRobot)
  30. {
  31. int index = -404; //stands for 404 - has not found any ore
  32. double distance = 30*30 + 15*15+1; //just a number, so my program thinks it's the biggest distance ever
  33. for(int i = 0; i < G.Count(); i++)
  34. {
  35. if (G[i].status != "?" && G[i].status != "0")
  36. {
  37. double newDistance = Math.Pow(myRobot.x - G[i].x,2) + Math.Pow(myRobot.y - G[i].y,2);
  38. if( newDistance < distance)
  39. {
  40. distance = newDistance;
  41. index = i;
  42. }
  43. }
  44. }
  45. return index;
  46. }
  47.  
  48. //Methods for basic robot-functions //Basic functions for easier testing and programming
  49. public static void move(int x, int y) => Console.WriteLine("MOVE {0} {1}",x,y);
  50. public static void dig(int x, int y) => Console.WriteLine("DIG {0} {1}",x,y);
  51. public static void request(string x) => Console.WriteLine("REQUEST {0}",x);
  52. public static void wait() => Console.WriteLine("WAIT");
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement