Strategická: Fix nedefinovaných funkcí
This commit is contained in:
parent
642f4389af
commit
a0a4fc2735
1 changed files with 10 additions and 11 deletions
|
@ -84,11 +84,6 @@ def run_subprocess(
|
||||||
def get_state(min_round: int, args) -> dict:
|
def get_state(min_round: int, args) -> dict:
|
||||||
"""Iteratively try to get game data from the server."""
|
"""Iteratively try to get game data from the server."""
|
||||||
|
|
||||||
state, wait_time = get_state_once()
|
|
||||||
while state is None:
|
|
||||||
time.sleep(wait_time)
|
|
||||||
state, wait_time = get_state_once()
|
|
||||||
|
|
||||||
def get_state_once() -> Tuple[Optional[dict], float]:
|
def get_state_once() -> Tuple[Optional[dict], float]:
|
||||||
try:
|
try:
|
||||||
res = requests.get(f"{args.server}/api/state", params={
|
res = requests.get(f"{args.server}/api/state", params={
|
||||||
|
@ -107,6 +102,7 @@ def get_state(min_round: int, args) -> dict:
|
||||||
|
|
||||||
state = res.json()
|
state = res.json()
|
||||||
if state["status"] == "ok":
|
if state["status"] == "ok":
|
||||||
|
logger.info("Received new state.")
|
||||||
return state, 0
|
return state, 0
|
||||||
|
|
||||||
# retry after some time
|
# retry after some time
|
||||||
|
@ -116,16 +112,16 @@ def get_state(min_round: int, args) -> dict:
|
||||||
logger.info("Round didn't start yet.")
|
logger.info("Round didn't start yet.")
|
||||||
return None, state["wait"]
|
return None, state["wait"]
|
||||||
|
|
||||||
logger.info("Received new state.")
|
state, wait_time = get_state_once()
|
||||||
return state, 0
|
while state is None:
|
||||||
|
time.sleep(wait_time)
|
||||||
|
state, wait_time = get_state_once()
|
||||||
|
return state
|
||||||
|
|
||||||
|
|
||||||
def send_turn(turn: dict, round: int, args) -> None:
|
def send_turn(turn: dict, round: int, args) -> None:
|
||||||
"""Iteratively try to send turn to the server."""
|
"""Iteratively try to send turn to the server."""
|
||||||
|
|
||||||
while not send_turn_once():
|
|
||||||
time.sleep(TIME_BEFORE_RETRY)
|
|
||||||
|
|
||||||
def send_turn_once() -> bool:
|
def send_turn_once() -> bool:
|
||||||
"""Returns True if server answered."""
|
"""Returns True if server answered."""
|
||||||
|
|
||||||
|
@ -162,13 +158,16 @@ def send_turn(turn: dict, round: int, args) -> None:
|
||||||
f" {member['id']}: {member['description']}"
|
f" {member['id']}: {member['description']}"
|
||||||
for member in response["members"]
|
for member in response["members"]
|
||||||
]
|
]
|
||||||
|
logger.info("Turn accepted with warnings.")
|
||||||
logger.warning(
|
logger.warning(
|
||||||
"Member warnings:\n"
|
"Member warnings:\n"
|
||||||
"\n".join(member_warns)
|
"\n".join(member_warns)
|
||||||
)
|
)
|
||||||
|
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
while not send_turn_once():
|
||||||
|
time.sleep(TIME_BEFORE_RETRY)
|
||||||
|
|
||||||
|
|
||||||
def log_server_error(res: requests.Response) -> None:
|
def log_server_error(res: requests.Response) -> None:
|
||||||
logger.error(
|
logger.error(
|
||||||
|
|
Loading…
Reference in a new issue