Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import sys
- import os
- import importlib
- from PlanetWars import PlanetWars
- """
- /*
- TODO BOOM:
- 1. isValid
- 2. udateList
- 3. makeMove
- 4. make enemy list
- */
- """
- class Move:
- def __init__(self, moveSource, moveDest, distance, score):
- self._source = moveSource
- self._dest = moveDest
- self._distance = distance
- self._score = score
- def __lt__(self, other):
- return self._score < other._score
- def getScore(self):
- numOfTurns= 0
- if(self._distance > 0 and self._distance < 50):
- numOfTurns = 70
- elif (self._distance >= 50 and self._distance < 100):
- return
- self._score = (numOfTurns-self._distance)*self._dest.growth_rate()
- def isValid(currMove):
- numberOfShips = currMove._source.num_ships()/2
- numberOfDestShips = currMove._dest.num_ships()/1
- if (numberOfShips > numberOfDestShips):
- return True
- else:
- return False
- def updateList(movesList, currMove):
- newList = []
- for move in movesList:
- if (move._dest != currMove._dest):
- newList.append(move)
- return newList
- def getMoves(pw):
- moves = []
- myPlanets = pw.my_planets()
- for planet in myPlanets:
- neutralPlanets = pw.neutral_planets()
- for neutral in neutralPlanets:
- m = Move(planet, neutral, pw.distance(planet, neutral), 0)
- m.getScore()
- moves.append(m)
- return moves
- def makeMove(moveList, pw):
- while(len(moveList) > 0):
- currMove=moveList[0]
- if(isValid(currMove)):
- pw.debug(currMove._source.x())
- pw.issue_order(currMove._source, currMove._dest, currMove._source.num_ships() / 2)
- moveList = updateList(moveList, currMove)
- else:
- currMove._dest = 0
- currMove._source = 0
- updateList(moveList, currMove)
- def sort(MList):
- MList.sort()
- def do_turn(pw):
- if len(pw.my_planets()) == 0:
- return
- if len(pw.neutral_planets()) >= 1:
- dest = pw.neutral_planets()[0]
- else:
- if len(pw.enemy_planets()) >= 1:
- dest = pw.enemy_planets()[0]
- source = pw.my_planets()[0]
- movesList = getMoves(pw)
- movesList.sort()
- pw.debug(movesList[0]._score)
- num_ships = source.num_ships() / 2
- makeMove(movesList,pw)
- def main():
- pw = PlanetWars('')
- do_turn(pw)
- if __name__ == '__main__':
- assert len(sys.argv) == 2
- bot_path = sys.argv[1]
- bot_dir = os.path.dirname(bot_path)
- bot_filename = os.path.basename(bot_path)
- bot_modulename = os.path.splitext(bot_filename)[0]
- sys.path.append(bot_dir)
- bot_module = importlib.import_module(bot_modulename)
- do_turn = bot_module.do_turn
- main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement