SKSP_2022_strategicka_hra/server/bin/create_game

38 lines
731 B
Text
Raw Normal View History

2022-09-12 17:47:58 +02:00
#!/usr/bin/env python3
from hra.game import logic_by_mode
import hra.db as db
import hra.lib as lib
import sys
from sqlalchemy import exc, update
2022-09-13 12:00:57 +02:00
ses = db.get_session()
2022-09-12 17:47:58 +02:00
mode = "occupy"
teams_count = 6
2022-09-13 12:00:57 +02:00
configuration = {
"teams_width": 2,
"teams_height": 3,
"width_per_team": 10,
"height_per_team": 10,
}
2022-09-12 17:47:58 +02:00
g = db.Game(game_mode=mode, configuration=configuration, teams_count=teams_count)
2022-09-13 12:00:57 +02:00
ses.add(g)
ses.commit()
g.lock()
2022-09-12 17:47:58 +02:00
s = db.State(game_id=g.game_id, round=0, state=g.get_logic().zero_state())
2022-09-13 12:00:57 +02:00
ses.add(s)
for i in range(teams_count):
t = db.Team(team_id=i, game_id=g.game_id, name="")
ses.add(t)
2022-09-12 17:47:58 +02:00
g.current_round = 0
g.working_on_next_state = False
2022-09-13 12:00:57 +02:00
ses.commit()
2022-09-12 17:47:58 +02:00
print(f"Přidána hra {g.game_id}. ")