|
@ -7,8 +7,10 @@ from sqlalchemy import exc, update |
|
|
|
|
|
|
|
|
class DuplicitMakeStep(Exception): |
|
|
class DuplicitMakeStep(Exception): |
|
|
pass |
|
|
pass |
|
|
|
|
|
class TooEarlyStep(Exception): |
|
|
|
|
|
pass |
|
|
|
|
|
|
|
|
def game_step(game_id: int): |
|
|
def game_step(game_id: int, by_user: bool = False): |
|
|
ses = db.get_session() |
|
|
ses = db.get_session() |
|
|
|
|
|
|
|
|
ses.expire_all() |
|
|
ses.expire_all() |
|
@ -18,12 +20,17 @@ def game_step(game_id: int): |
|
|
if game.working_on_next_state: |
|
|
if game.working_on_next_state: |
|
|
ses.commit() |
|
|
ses.commit() |
|
|
raise DuplicitMakeStep() |
|
|
raise DuplicitMakeStep() |
|
|
game.working_on_next_state = True |
|
|
|
|
|
ses.commit() |
|
|
|
|
|
|
|
|
|
|
|
old_round_id = game.current_round |
|
|
old_round_id = game.current_round |
|
|
new_round_id = old_round_id + 1 |
|
|
new_round_id = old_round_id + 1 |
|
|
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() |
|
|
|
|
|
|
|
|
|
|
|
if by_user: |
|
|
|
|
|
if (datetime.now() - old_state.create_time).total_seconds() < 5: |
|
|
|
|
|
raise TooEarlyStep() |
|
|
|
|
|
game.working_on_next_state = True |
|
|
|
|
|
ses.commit() |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
moves = [None for _ in range(game.teams_count)] |
|
|
moves = [None for _ in range(game.teams_count)] |
|
|
points = [0 for _ in range(game.teams_count)] |
|
|
points = [0 for _ in range(game.teams_count)] |
|
@ -33,7 +40,7 @@ def game_step(game_id: int): |
|
|
|
|
|
|
|
|
ses.commit() |
|
|
ses.commit() |
|
|
|
|
|
|
|
|
x, add_points = game.get_logic().step(old_state, moves, old_round_id) |
|
|
x, add_points = game.get_logic().step(old_state.get_state(), moves, old_round_id) |
|
|
|
|
|
|
|
|
points = [a+b for a,b in zip(points, add_points)] |
|
|
points = [a+b for a,b in zip(points, add_points)] |
|
|
|
|
|
|
|
|