ADD: Split players into two teams internally

This commit is contained in:
2025-03-16 10:32:55 +01:00
parent e13aa33dd6
commit 2022ee504d
4 changed files with 49 additions and 18 deletions

View File

@@ -1,8 +1,11 @@
from models.player import Player
from models.team import Team
class Match:
def __init__(self, map_name, game_info, tick_rate=64):
self.players = []
def __init__(self, map_name, game_info, team_1: Team, team_2: Team, tick_rate=64):
self.team_1 = team_1
self.team_2 = team_2
self.map_name = map_name
self.tick = 1
@@ -14,15 +17,6 @@ class Match:
self.game_info = game_info # pd dataframe sorted by tick
self.tick_rate = tick_rate
def add_player(self, player: Player) -> None:
self.players.append(player)
def next_tick(self) -> None:
self.tick += 1
self.current_tick = self.game_info[self.game_info["tick"] == self.tick]
self._update_player_positions()
self._update_round()
def _update_player_positions(self) -> None:
# inefficient, might need to change
@@ -30,7 +24,7 @@ class Match:
if self.current_tick.empty:
return
for player in self.players:
for player in self.get_players():
player.x = self.current_tick[self.current_tick["player_steamid"] == player.steam_id]["Y"].values[0]
player.y = self.current_tick[self.current_tick["player_steamid"] == player.steam_id]["X"].values[0]
player.z = self.current_tick[self.current_tick["player_steamid"] == player.steam_id]["Z"].values[0]
@@ -41,4 +35,13 @@ class Match:
def _update_round(self) -> None:
if self.current_tick.empty:
return
self.round = self.current_tick["team_rounds_total"].values[0]
self.round = self.current_tick["team_rounds_total"].values[0]
def next_tick(self) -> None:
self.tick += 1
self.current_tick = self.game_info[self.game_info["tick"] == self.tick]
self._update_player_positions()
self._update_round()
def get_players(self) -> list[Player]:
return self.team_1.players + self.team_2.players