Ejemplo n.º 1
0
    def run_game(self):
        logging.info("game loop started")
        while not self._shutdown:
            # increment internal turn counter
            self.turn_number += 1

            # FIXME: iterating over ALL the players time and time again must be slow

            # send all alive players a new turn command
            for player in self._in_game:
                player.energy = min(config.player.max_energy + config.player.turn_charge, 1.0)
                player.send(protocol.begin(self.turn_number, player.energy).values())

                # decrement wait counters for dead players
            for player in filter(lambda p: p.state is PlayerState.DEAD, self._players.values()):
                player.dead_turns -= 1

                # wait the configured amount of time for players to submit commands
            time.sleep(config.game.turn_duration / 1000)

            # execute all requested move actions
            self.execute_moves(filter(lambda p: p.move is not None, self._in_game))

            # execute all requested fire actions
            self.execute_fires(filter(lambda p: p.fire is not None, self._in_game), self._in_game)

            # execute all requested scan actions
            self.execute_scans(filter(lambda p: p.scan is not None, self._in_game), self._in_game)

            # send all players the end turn command
            for player in self._in_game:
                player.send(protocol.end().values())
Ejemplo n.º 2
0
    def run_game(self):
        logging.info('game loop started')
        while not self._shutdown:
            # increment internal turn counter
            self.turn_number += 1

            # FIXME: iterating over ALL the players time and time again must be slow

            # send all alive players a new turn command
            for player in self._in_game:
                player.energy = min(
                    config.player.max_energy + config.player.turn_charge, 1.0)
                player.send(
                    protocol.begin(self.turn_number, player.energy).values())

            # decrement wait counters for dead players
            for player in filter(lambda p: p.state is PlayerState.DEAD,
                                 self._players.values()):
                player.dead_turns -= 1

            # wait the configured amount of time for players to submit commands
            time.sleep(config.game.turn_duration / 1000)

            # execute all requested move actions
            self.execute_moves(
                filter(lambda p: p.move is not None, self._in_game))

            # execute all requested fire actions
            self.execute_fires(
                filter(lambda p: p.fire is not None, self._in_game),
                self._in_game)

            # execute all requested scan actions
            self.execute_scans(
                filter(lambda p: p.scan is not None, self._in_game),
                self._in_game)

            # send all players the end turn command
            for player in self._in_game:
                player.send(protocol.end().values())
Ejemplo n.º 3
0
	def signal_end(self):
		if self.state is not PlayerState.DEAD:
			self.state = PlayerState.WAITING
		self.send(protocol.end().values())
Ejemplo n.º 4
0
 def signal_end(self):
     self.state = PlayerState.WAITING
     self.send(protocol.end().values())
Ejemplo n.º 5
0
 def signal_end(self):
     if self.state is not PlayerState.DEAD:
         self.state = PlayerState.WAITING
     self.send(protocol.end().values())
Ejemplo n.º 6
0
 def signal_end(self):
     self.state = PlayerState.WAITING
     self.send(protocol.end().values())