def use_saw(self, player): line = player.get_direction_line() Saw.append_line(line) for p in self.players: if p != player: if any([is_intersect(p.pos(), point) for point in line]): self.losers.append(p) self.append_event('killed by saw', p, player) Saw.log.append({ 'player': player.id, 'loser': p.id, 'killed': True }) player.tick_score += SAW_KILL_SCORE else: removed = p.territory.split(line, player.direction, p) if len(removed) > 0: player.tick_score += SAW_SCORE Saw.append_territory(removed, p.territory.color) Saw.log.append({ 'player': player.id, 'loser': p.id, 'points': removed, 'killed': False })
async def game_loop(self, *args, **kwargs): self.send_game_tick() for player in self.players: if (player.x - round(WIDTH / 2)) % WIDTH == 0 and (player.y - round(WIDTH / 2)) % WIDTH == 0: command = await player.get_command(self.tick) if command: player.change_direction(command) for player in self.players: player.move() for index, player in enumerate(self.players): is_loss = self.check_loss(player, self.players) if is_loss: self.losers.append(self.players[index]) for player in self.players: player.remove_saw_bonus() if (player.x - round(WIDTH / 2)) % WIDTH == 0 and (player.y - round(WIDTH / 2)) % WIDTH == 0: player.update_lines() captured = player.territory.capture(player.lines) if len(captured) > 0: player.lines.clear() player.score += NEUTRAL_TERRITORY_SCORE * len(captured) player.tick_action() for bonus in self.bonuses[:]: if bonus.is_ate(player, captured): bonus.apply(player) self.bonuses.remove(bonus) if isinstance(bonus, Saw): line = player.get_direction_line() Saw.append_line(line) for p in self.players: if p != player: if any([is_intersect((p.x, p.y), point) for point in line]): self.losers.append(p) Saw.log.append({ 'player': player.id, 'loser': p.id, 'killed': True }) player.score += SAW_KILL_SCORE else: removed = p.territory.split(line, player.direction, p) if len(removed) > 0: player.score += SAW_SCORE Saw.append_territory(removed, p.territory.color) Saw.log.append({ 'player': player.id, 'loser': p.id, 'points': removed, 'killed': False }) for p in self.players: if p != player: removed = p.territory.remove_points(captured) player.score += (ENEMY_TERRITORY_SCORE - NEUTRAL_TERRITORY_SCORE) * len(removed) for player in self.losers: if player in self.players: self.players.remove(player) self.generate_bonus() self.tick += 1 return len(self.players) == 0
async def game_loop(self, *args, **kwargs): self.send_game_tick() futures = [] for player in self.players: if (player.x - round(WIDTH / 2)) % WIDTH == 0 and ( player.y - round(WIDTH / 2)) % WIDTH == 0: futures.append( asyncio.ensure_future(self.get_command_wrapper(player))) if futures: await asyncio.wait(futures) for player in self.players: player.move() players_to_captured = {} for player in self.players: player.remove_saw_bonus() if (player.x - round(WIDTH / 2)) % WIDTH == 0 and ( player.y - round(WIDTH / 2)) % WIDTH == 0: player.update_lines() captured = player.territory.capture(player.lines) players_to_captured[player] = captured if len(captured) > 0: player.lines.clear() player.tick_score += NEUTRAL_TERRITORY_SCORE * len( captured) for player in self.players: is_loss = self.check_loss(player, self.players) if is_loss: self.losers.append(player) players_to_captured = self.collision_resolution(players_to_captured) for player in self.players: is_loss, p = player.is_ate(players_to_captured) if is_loss: self.append_event('eaten by other player', player, p) self.losers.append(player) for player in self.players: if (player.x - round(WIDTH / 2)) % WIDTH == 0 and ( player.y - round(WIDTH / 2)) % WIDTH == 0: captured = players_to_captured.get(player, set()) player.tick_action() for bonus in self.bonuses[:]: if bonus.is_ate(player, captured): bonus.apply(player) self.bonuses.remove(bonus) if isinstance(bonus, Saw): line = player.get_direction_line() Saw.append_line(line) for p in self.players: if p != player: if any([ is_intersect((p.x, p.y), point) for point in line ]): self.losers.append(p) self.append_event( 'killed by saw', p, player) Saw.log.append({ 'player': player.id, 'loser': p.id, 'killed': True }) player.tick_score += SAW_KILL_SCORE else: removed = p.territory.split( line, player.direction, p) if len(removed) > 0: player.tick_score += SAW_SCORE Saw.append_territory( removed, p.territory.color) Saw.log.append({ 'player': player.id, 'loser': p.id, 'points': removed, 'killed': False }) if captured: player.territory.points.update(captured) for p in self.players: if p != player: removed = p.territory.remove_points(captured) player.tick_score += ( ENEMY_TERRITORY_SCORE - NEUTRAL_TERRITORY_SCORE) * len(removed) for player in self.losers: if player in self.players: self.players.remove(player) for player in self.players: player.score += player.tick_score player.tick_score = 0 self.generate_bonus() self.tick += 1 return len(self.players) == 0