Browse Source

Strategická: Vyřešit mypy chyby

master
David Klement 2 years ago
parent
commit
b9ebbbcc30
  1. 5
      klient/client.py
  2. 27
      klient/play.py

5
klient/client.py

@ -31,9 +31,8 @@ logger = logging.getLogger("client")
def main(args: argparse.Namespace) -> None: def main(args: argparse.Namespace) -> None:
logger.setLevel(args.log_level.upper()) logger.setLevel(args.log_level.upper())
min_round = 0 min_round = 0
program = None
if args.save_state is None: if args.save_state is None:
program = get_command(args) command = get_command(args)
while True: while True:
state = get_state(min_round, args) state = get_state(min_round, args)
@ -49,7 +48,7 @@ def main(args: argparse.Namespace) -> None:
return return
turn_json = run_subprocess( turn_json = run_subprocess(
program, json.dumps(state), state["time_to_response"] command, json.dumps(state), state["time_to_response"]
) )
if turn_json is None: if turn_json is None:
continue continue

27
klient/play.py

@ -36,13 +36,15 @@ class Team:
home: Field home: Field
def __init__(self, id: int, is_me: bool) -> None: def __init__(self, id: int, is_me: bool) -> None:
self.id: int = id self.id = id
self.is_me = is_me self.is_me = is_me
self.protected_fields: List[Field] = [] self.protected_fields: List[Field] = []
self.occupied: List[Field] = [] self.occupied: List[Field] = []
self.members: List[Member] = [] self.members: List[Member] = []
def __eq__(self, other: Field) -> bool: def __eq__(self, other: object) -> bool:
if not isinstance(other, Team):
return NotImplemented
return (self.id) == (other.id) return (self.id) == (other.id)
def __hash__(self) -> int: def __hash__(self) -> int:
@ -50,7 +52,7 @@ class Team:
class Member: class Member:
def __init__(self, field: Field, team: int, id: int) -> None: def __init__(self, field: Field, team: Team, id: int) -> None:
self.field = field self.field = field
self.team = team self.team = team
self.id = id self.id = id
@ -64,14 +66,16 @@ class Field:
home_for_team: Optional[Team], home_for_team: Optional[Team],
occupied_by_team: Optional[Team], occupied_by_team: Optional[Team],
protected_for_team: Optional[Team],) -> None: protected_for_team: Optional[Team],) -> None:
self.i: int = i self.i = i
self.j: int = j self.j = j
self.hill: bool = hill self.hill = hill
self.home_for_team: Optional[Team] = home_for_team self.home_for_team: Optional[Team] = home_for_team
self.occupied_by_team: Optional[Team] = occupied_by_team self.occupied_by_team: Optional[Team] = occupied_by_team
self.protected_for_team: Optional[Team] = protected_for_team self.protected_for_team: Optional[Team] = protected_for_team
def __eq__(self, other: Field) -> bool: def __eq__(self, other: object) -> bool:
if not isinstance(other, Field):
return NotImplemented
return (self.i, self.j) == (other.i, other.j) return (self.i, self.j) == (other.i, other.j)
def __hash__(self) -> int: def __hash__(self) -> int:
@ -126,7 +130,7 @@ class State:
self.time_to_response: Optional[int] = state["time_to_response"] self.time_to_response: Optional[int] = state["time_to_response"]
def _parse_world(self, world: dict) -> List[List[Field]]: def _parse_world(self, world: dict) -> List[List[Field]]:
def get_team(team_id): def get_team(team_id: int) -> Optional[Team]:
return None if team_id is None else self.teams[team_id] return None if team_id is None else self.teams[team_id]
fields = [] fields = []
@ -148,13 +152,14 @@ class State:
parsed_field.protected_for_team.protected_fields.append(parsed_field) parsed_field.protected_for_team.protected_fields.append(parsed_field)
members = [] members = []
for member in field["members"]: for member in field["members"]:
member_team = self.teams[member["team_id"]]
m = Member( m = Member(
parsed_field, parsed_field,
self.teams[member["team"]], member_team,
member["id"], member["id"],
) )
members.append(m) members.append(m)
m.team.members.append(m) member_team.members.append(m)
parsed_field.members = members parsed_field.members = members
fields_row.append(parsed_field) fields_row.append(parsed_field)
@ -227,7 +232,7 @@ def main() -> None:
# TODO: zde doplňte svou herní strategii # TODO: zde doplňte svou herní strategii
# příklad: všechny vojáky posílám nahoru # příklad: všechny vojáky posílám nahoru
for member in state.teams[state.my_team].members: for member in state.my_team.members:
member.action = Direction.UP member.action = Direction.UP
print(json.dumps(state.build_turn())) print(json.dumps(state.build_turn()))

Loading…
Cancel
Save