|
@ -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() |
|
|
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)] |
|
|
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(): |
|
|
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() |
|
|
moves[i.team_id] = i.get_move() |
|
|
|
|
|
points[i.team_id] = i.points |
|
|
|
|
|
|
|
|
ses.commit() |
|
|
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) |
|
|
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) |
|
|
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() |
|
|
ses.expire_all() |
|
|
game = ses.query(db.Game).filter_by(game_id=game_id).with_for_update().one_or_none() |
|
|
game = ses.query(db.Game).filter_by(game_id=game_id).with_for_update().one_or_none() |
|
|
assert game is not 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()) |
|
|
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) |
|
|
ses.add(s) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if test_for is not None: |
|
|
if test_for is not None: |
|
|
for i in range(teams_count): |
|
|
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) |
|
|
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="") |
|
|
t = db.Team(team_id=i, game_id=g.game_id, name="") |
|
|
ses.add(t) |
|
|
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.current_round = 0 |
|
|
g.working_on_next_state = False |
|
|
g.working_on_next_state = False |
|
|
|
|
|
|
|
|