Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env python
- #
- """
- // The DoTurn function is where your code goes. The PlanetWars object contains
- // the state of the game, including information about all planets and fleets
- // that currently exist. Inside this function, you issue orders using the
- // pw.IssueOrder() function. For example, to send 10 ships from planet 3 to
- // planet 8, you would say pw.IssueOrder(3, 8, 10).
- //
- // There is already a basic strategy in place here. You can use it as a
- // starting point, or you can throw it out entirely and replace it with your
- // own. Check out the tutorials and articles on the contest website at
- // http://www.ai-contest.com/resources.
- """
- from PlanetWars import PlanetWars
- def DoTurn(pw):
- if not len( pw.MyPlanets() ):
- return
- for planet in pw.Planets():
- planet.NumShipz( planet.NumShips() )
- planet.Ownerz( planet.Owner() )
- for fleet in pw.Fleets():
- target= pw.GetPlanet( fleet.DestinationPlanet() )
- if fleet.Owner() == target.Ownerz():
- target.AddShipz( fleet.NumShips() )
- else:
- target.RemoveShipz( fleet.NumShips() )
- if target.NumShipz() < 0:
- target.NumShipz( -target.NumShipz() )
- target.Ownerz( fleet.Owner() )
- source= None
- for planet in pw.MyPlanets():
- if( planer.Owner() == 1 )and( planet.Ownerz() == 1 ):
- if ( not source )or( planet.NumShipz() > source.NumShipz() ):
- source= planet
- target= None
- for planet in sorted( pw.Planets(), key= lambda planet: pw.Distance( source, planet ) ):
- if planet.NumShipz() * 3 < source.NumShipz():
- if ( not target )or( planet.GrowthRate() > target.GrowthRate() ):
- target= planet
- if source and target and ( source != target ):
- num_ships = min( source.NumShips() , source.NumShipz() ) / 3
- # if target.Owner() != 1:
- # num_ships*= 2
- if num_ships > 0:
- pw.IssueOrder( source.PlanetID(), target.PlanetID(), num_ships )
- def main():
- map_data = ''
- while(True):
- current_line = raw_input()
- if len(current_line) >= 2 and current_line.startswith("go"):
- pw = PlanetWars(map_data)
- DoTurn(pw)
- pw.FinishTurn()
- map_data = ''
- else:
- map_data += current_line + '\n'
- if __name__ == '__main__':
- try:
- import psyco
- psyco.full()
- except ImportError:
- pass
- try:
- main()
- except KeyboardInterrupt:
- print 'ctrl-c, leaving ...'
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement