Example #1
0
 def do_POST(self):
     pathParts = self.path.split("/")
     print pathParts
     if pathParts[1].lower() == 'actions':
         timestep = int(pathParts[2])
         if timestep != universe.t:
             self.send_error(404, "incorrect timestep")
         else:
             team = pathParts[3].lower()
             if universe.AccountedFor(team):
                 self.send_error(404, "team already acted this timestep")
             else:
                 length = int(self.headers.getheader('content-length'))
                 actionJson = self.rfile.read(length)
                 actions = Actions.FromJson(actionJson, universe)
                 if universe.ActTryTimestep(actions, team):
                     universeStates[universe.t] = universe.ToJson()                
                 self.respondJson(o={'actionsSet':timestep})
     else:
         self.send_error(404)