Advertisement
Guest User

Working

a guest
May 27th, 2015
361
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.15 KB | None | 0 0
  1. package customBots;
  2.  
  3. import shared.Planet;
  4. import shared.PlanetWars;
  5.  
  6. public class Check {
  7.  
  8. public static Planet closest(PlanetWars game, Planet source){
  9. Planet target = game.neutralPlanets().get(0) ;
  10. for(int i = 0 ; i < game.myPlanets().size() ; i++){
  11. int bestDistance = 999999;
  12. for (Planet p : game.neutralPlanets()) {
  13. int dist = game.distance(source, p);
  14. if (dist < bestDistance) {
  15. bestDistance = dist;
  16. target = p;
  17. }
  18. }
  19. }
  20. return target;
  21. }
  22.  
  23. public static void play(PlanetWars game) {
  24.  
  25. if(game.numShips(1) + (game.production(1)) > game.numShips(2) + (game.production(2))){
  26.  
  27. } else{
  28. /*
  29. * If they are producing more ships than us:
  30. *
  31. * send a fleet from our biggest planet
  32. * to their high production planet
  33. * to capture it
  34. */
  35.  
  36. if (game.numShips(1) < 1000){
  37. for(int i = 0; i < game.myPlanets().size(); i++){
  38. Planet target = closest(game, game.myPlanets().get(i)) ;
  39. game.issueOrder(game.myPlanets().get(i), target, game.myPlanets().get(i).numShips()/2);
  40. }
  41. } else {
  42. for(int i = 0 ; i < game.myPlanets().size() ; i++){
  43. Planet src = game.myPlanets().get(i) ;
  44. Planet target = game.neutralPlanets().get(0);
  45.  
  46. if(game.neutralPlanets().size() < 5){
  47. target = game.enemyPlanets().get(0);
  48.  
  49. }else{
  50. target = game.neutralPlanets().get(0) ;
  51. }
  52.  
  53. int numShips = src.numShips()/2 ;
  54. if(target.numShips() < numShips){
  55. numShips = target.numShips() + 3;
  56. }
  57.  
  58. game.issueOrder(src, target, numShips);
  59. }
  60. }
  61. game.finishTurn();
  62. }
  63. }
  64.  
  65.  
  66.  
  67. public static void main(String[] args) {
  68. String line = "";
  69. String message = "";
  70. int c;
  71. try {
  72. while ((c = System.in.read()) >= 0) {
  73. switch (c) {
  74. case '\n':
  75. if (line.equals("go")) {
  76. PlanetWars game = new PlanetWars(message);
  77. play(game);
  78. game.finishTurn();
  79. message = "";
  80. } else {
  81. message += line + "\n";
  82. }
  83. line = "";
  84. break;
  85. default:
  86. line += (char) c;
  87. break;
  88. }
  89. }
  90. } catch (Exception e) {
  91. // Owned.
  92. }
  93. }
  94. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement