def parse_pregame(self):
		'''
		Parse all the pre-game messages. These include begin, hit and detect.
		See the protocol description for more details
		'''
		while True:
			try:
				parsed = protocol.parse_msg(self.recv_msg())
				command = parsed['command']

				if command == 'hit':
					logging.info('We were hit by {0} (angle: {1}, charge: {2})'.format(
						parsed['name'], parsed['angle'], parsed['charge']))
				elif command == 'detect':
					logging.info('We detected {0}({1} energy) at (angle: {2}, distance: {3})'.format(
						parsed['name'], parsed['energy'], parsed['angle'], parsed['distance']))
				elif command == 'begin':
					self.turn_number = parsed['turn_number']
					self.energy = parsed['energy']
					self.playing = self.energy > 0.0
					return
				elif command == 'death':
					logging.info('We died! Dead for {} turns'.format(parsed['turns']))
					self.playing = False
				else:
					continue
			except KeyError:
			# garbage received
				logging.exception('Pregame message parsing error:')
				continue
Exemple #2
0
 def parse_command(self, command):
     try:
         cmd = protocol.parse_msg(command)
         self.commands.append(cmd)
         print("Will send command " + str(list(str(k) + " : " + str(v) for (k, v) in cmd.items())))
     except ValueError as e:
         print("Error while parsing command:")
         print(e)
Exemple #3
0
	def parse_command(self, command):
		try:
			cmd = protocol.parse_msg(command)
			signal_function = getattr(self.player, 'signal_' + cmd['command'])
			self.commands.append((signal_function,) + tuple(cmd.values())[1:])
			print('Will send command ' + str(list(str(k) + ' : ' + str(v) for (k,v) in cmd.items())))
		except ValueError as e:
			print('Error while parsing command:')
			print(e)
Exemple #4
0
 def parse_command(self, command):
     try:
         cmd = protocol.parse_msg(command)
         signal_function = getattr(self.player, 'signal_' + cmd['command'])
         self.commands.append((signal_function, ) + tuple(cmd.values())[1:])
         print('Will send command ' +
               str(list(str(k) + ' : ' + str(v) for (k, v) in cmd.items())))
     except ValueError as e:
         print('Error while parsing command:')
         print(e)
	def parse_welcome(self):
		'''
		Receive the welcome message, parse all info in it and start playing
		'''
		welcome_msg = self.recv_msg()
		parsed = protocol.parse_msg(welcome_msg)
		self.energy = parsed['energy']
		self.max_energy = parsed['energy']
		self.heal = parsed['heal']
		self.turn_duration = parsed['turn_duration']
		self.turns_left = parsed['turns_left']
		self.in_game = True
	def parse_end(self):
		'''
		Parse the end-turn message
		'''
		protocol.parse_msg(self.recv_msg())