Browse Source

Strategická: Fix nedefinovaných funkcí

master
David Klement 2 years ago
parent
commit
a0a4fc2735
  1. 21
      klient/client.py

21
klient/client.py

@ -84,11 +84,6 @@ def run_subprocess(
def get_state(min_round: int, args) -> dict:
"""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]:
try:
res = requests.get(f"{args.server}/api/state", params={
@ -107,6 +102,7 @@ def get_state(min_round: int, args) -> dict:
state = res.json()
if state["status"] == "ok":
logger.info("Received new state.")
return state, 0
# retry after some time
@ -116,16 +112,16 @@ def get_state(min_round: int, args) -> dict:
logger.info("Round didn't start yet.")
return None, state["wait"]
logger.info("Received new state.")
return state, 0
state, wait_time = get_state_once()
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:
"""Iteratively try to send turn to the server."""
while not send_turn_once():
time.sleep(TIME_BEFORE_RETRY)
def send_turn_once() -> bool:
"""Returns True if server answered."""
@ -162,13 +158,16 @@ def send_turn(turn: dict, round: int, args) -> None:
f" {member['id']}: {member['description']}"
for member in response["members"]
]
logger.info("Turn accepted with warnings.")
logger.warning(
"Member warnings:\n"
"\n".join(member_warns)
)
return True
while not send_turn_once():
time.sleep(TIME_BEFORE_RETRY)
def log_server_error(res: requests.Response) -> None:
logger.error(

Loading…
Cancel
Save