|
|
@ -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 |
|
|
|
|
|
|
|