rendered paste body#!/usr/bin/env python
#
import pw
import planet
import fleet
from sys import stdout
def ParseGameState( s ):
lines = s.split("\n")
list_planets = []
list_fleets = []
planet_id = 0
for line in lines:
line = line.split("#")[0] # remove comments
tokens = line.split(" ")
if len(tokens) == 1:
continue
if tokens[0] == "P":
if len(tokens) != 6:
return 0
list_planets.append(
planet.Planet( planet_id , # The ID of this planet
int(tokens[3]) , # Owner
int(tokens[4]) , # Num ships
int(tokens[5]) , # Growth rate
float(tokens[1]), # X
float(tokens[2])) # Y
)
planet_id += 1
elif tokens[0] == "F":
if len(tokens) != 7:
return 0
f = fleet.Fleet(int(tokens[1]), # Owner
int(tokens[2]), # Num ships
int(tokens[3]), # Source
int(tokens[4]), # Destination
int(tokens[5]), # Total trip length
int(tokens[6])) # Turns remaining
list_fleets.append(f)
else:
return False
return pw.PlanetWars(list_planets, list_fleets)
def ToString(PlanetWarObject):
s = ''
for p in PlanetWarObject.Planets() :
s += "P %f %f %d %d %d\n" % \
(p.X(), p.Y(), p.Owner(), p.NumShips(), p.GrowthRate())
for f in PlanetWarObject.Fleets() :
s += "F %d %d %d %d %d %d\n" % \
(f.Owner(), f.NumShips(), f.SourcePlanet(), f.DestinationPlanet(), \
f.TotalTripLength(), f.TurnsRemaining())
return s
def FinishTurn():
stdout.write("go\n")
stdout.flush()
def IssueOrder( source_planet, destination_planet, num_ships):
stdout.write("%d %d %d\n" % \
(source_planet, destination_planet, num_ships))
stdout.flush()