Advertisement
Guest User

Untitled

a guest
Jul 24th, 2017
54
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.49 KB | None | 0 0
  1. import sys
  2. import os
  3. import importlib
  4.  
  5. from PlanetWars import PlanetWars
  6.  
  7. """
  8. /*
  9. TODO BOOM:
  10. 1. isValid
  11. 2. udateList
  12. 3. makeMove
  13. 4. make enemy list
  14. */
  15. """
  16. class Move:
  17. def __init__(self, moveSource, moveDest, distance, score):
  18. self._source = moveSource
  19. self._dest = moveDest
  20. self._distance = distance
  21. self._score = score
  22.  
  23. def __lt__(self, other):
  24. return self._score < other._score
  25.  
  26. def getScore(self):
  27. numOfTurns= 0
  28. if(self._distance > 0 and self._distance < 50):
  29. numOfTurns = 70
  30. elif (self._distance >= 50 and self._distance < 100):
  31. return
  32. self._score = (numOfTurns-self._distance)*self._dest.growth_rate()
  33.  
  34. def isValid(currMove):
  35. numberOfShips = currMove._source.num_ships()/2
  36. numberOfDestShips = currMove._dest.num_ships()/1
  37. if (numberOfShips > numberOfDestShips):
  38. return True
  39. else:
  40. return False
  41.  
  42. def updateList(movesList, currMove):
  43. newList = []
  44. for move in movesList:
  45. if (move._dest != currMove._dest):
  46. newList.append(move)
  47. return newList
  48.  
  49.  
  50. def getMoves(pw):
  51. moves = []
  52. myPlanets = pw.my_planets()
  53. for planet in myPlanets:
  54. neutralPlanets = pw.neutral_planets()
  55. for neutral in neutralPlanets:
  56. m = Move(planet, neutral, pw.distance(planet, neutral), 0)
  57. m.getScore()
  58. moves.append(m)
  59. return moves
  60.  
  61. def makeMove(moveList, pw):
  62. while(len(moveList) > 0):
  63. currMove=moveList[0]
  64. if(isValid(currMove)):
  65. pw.debug(currMove._source.x())
  66. pw.issue_order(currMove._source, currMove._dest, currMove._source.num_ships() / 2)
  67. moveList = updateList(moveList, currMove)
  68. else:
  69. currMove._dest = 0
  70. currMove._source = 0
  71. updateList(moveList, currMove)
  72.  
  73.  
  74. def sort(MList):
  75. MList.sort()
  76.  
  77. def do_turn(pw):
  78. if len(pw.my_planets()) == 0:
  79. return
  80.  
  81. if len(pw.neutral_planets()) >= 1:
  82. dest = pw.neutral_planets()[0]
  83.  
  84. else:
  85. if len(pw.enemy_planets()) >= 1:
  86. dest = pw.enemy_planets()[0]
  87.  
  88. source = pw.my_planets()[0]
  89. movesList = getMoves(pw)
  90. movesList.sort()
  91. pw.debug(movesList[0]._score)
  92.  
  93. num_ships = source.num_ships() / 2
  94.  
  95. makeMove(movesList,pw)
  96.  
  97.  
  98. def main():
  99. pw = PlanetWars('')
  100. do_turn(pw)
  101.  
  102. if __name__ == '__main__':
  103. assert len(sys.argv) == 2
  104.  
  105. bot_path = sys.argv[1]
  106. bot_dir = os.path.dirname(bot_path)
  107. bot_filename = os.path.basename(bot_path)
  108. bot_modulename = os.path.splitext(bot_filename)[0]
  109.  
  110. sys.path.append(bot_dir)
  111.  
  112. bot_module = importlib.import_module(bot_modulename)
  113.  
  114. do_turn = bot_module.do_turn
  115.  
  116. main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement