diff --git a/server/hra/db.py b/server/hra/db.py index 626ea6f..8710ec3 100644 --- a/server/hra/db.py +++ b/server/hra/db.py @@ -187,6 +187,12 @@ class Move(Base): team_id = Column(Integer, primary_key=True) move = Column(Integer, ForeignKey('bigdata.id'), nullable=True) + points = Column(Integer, nullable=False, default=0) + reads_count = Column(Integer, nullable=False, default=0) + ok_pushs_count = Column(Integer, nullable=False, default=0) + warnings_pushs_count = Column(Integer, nullable=False, default=0) + err_pushs_count = Column(Integer, nullable=False, default=0) + def get_move(self): if self.move is None: return None diff --git a/server/hra/lib.py b/server/hra/lib.py index 2115644..0ee53c0 100644 --- a/server/hra/lib.py +++ b/server/hra/lib.py @@ -26,16 +26,24 @@ def game_step(game_id: int): old_state = ses.query(db.State).filter_by(game_id=game.game_id, round=old_round_id).one_or_none().get_state() moves = [None for _ in range(game.teams_count)] + points = [0 for _ in range(game.teams_count)] for i in ses.query(db.Move).filter_by(game_id=game.game_id, round=old_round_id).all(): moves[i.team_id] = i.get_move() + points[i.team_id] = i.points ses.commit() - x, points = game.get_logic().step(old_state, moves, old_round_id) + x, add_points = game.get_logic().step(old_state, moves, old_round_id) + + points = [a+b for a,b in zip(points, add_points)] new_state = db.State(game_id=game.game_id, round=new_round_id, state=db.new_big_data(x), create_time=time) ses.add(new_state) + for i in range(game.teams_count): + db_move = db.Move(team_id=i, game_id=game_id, round=new_round_id, points=points[i]) + ses.add(db_move) + ses.expire_all() game = ses.query(db.Game).filter_by(game_id=game_id).with_for_update().one_or_none() assert game is not None @@ -65,7 +73,6 @@ def create_game(mode, teams_count, configuration={}, test_for=None, name=None, s s = db.State(game_id=g.game_id, round=0, state=db.new_big_data(g.get_logic().zero_state()), create_time=datetime.now()) ses.add(s) - if test_for is not None: for i in range(teams_count): t = db.Team(team_id=i, game_id=g.game_id, name=f"test_{i}", user_id=test_for.id) @@ -75,6 +82,10 @@ def create_game(mode, teams_count, configuration={}, test_for=None, name=None, s t = db.Team(team_id=i, game_id=g.game_id, name="") ses.add(t) + for i in range(teams_count): + db_move = db.Move(team_id=i, game_id=g.game_id, round=0) + ses.add(db_move) + g.current_round = 0 g.working_on_next_state = False diff --git a/server/hra/web/pages.py b/server/hra/web/pages.py index df86115..ea01171 100644 --- a/server/hra/web/pages.py +++ b/server/hra/web/pages.py @@ -230,6 +230,9 @@ def web_game(game_id): ses = db.get_session() game = ses.query(db.Game).filter_by(game_id=game_id).one_or_none() teams = ses.query(db.Team).filter_by(game_id=game_id).order_by(db.Team.team_id).all() + moves = ses.query(db.Move).filter_by(game_id=game_id, round=game.current_round).order_by(db.Move.team_id).all() + assert len(teams) == len(moves) + if game is None: raise werkzeug.exceptions.NotFound() if not right_for_game(game): @@ -246,11 +249,13 @@ def web_game(game_id): with b.thead(): b.line().th()("Id") b.line().th()("User") + b.line().th()("Bodů") b.line().th()("Akce") - for team in teams: + for team, move in zip(teams, moves): with b.tr(): b.line().td()(team.team_id) b.line().td()(user_link(team.user),": ", team.name) + b.line().td()(move.points) with b.td(): with b.div(_class="btn-group", role="group"): if right_for_team(team):