Skip to content

Commit

Permalink
Make sure that a new matchmaking type is picked after removing one
Browse files Browse the repository at this point in the history
  • Loading branch information
Torom committed Jul 19, 2024
1 parent 4670e71 commit c132bbc
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions matchmaking.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ def __init__(self, api: API, config: Config) -> None:
self.next_update = datetime.now()
self.timeout = max(config.matchmaking.timeout, 1)
self.types = self._get_types()
self.suspended_types: list[Matchmaking_Type] = []
self.opponents = Opponents(config.matchmaking.delay, config.username)
self.challenger = Challenger(api)

Expand All @@ -37,9 +38,10 @@ def create_challenge(self, pending_challenge: Pending_Challenge) -> None:
try:
next_opponent = self.opponents.get_opponent(self.online_bots, self.current_type)
except NoOpponentException:
print(f'Removing matchmaking type {self.current_type.name} because '
'no opponent is online in the configured rating range.')
print(f'Suspending matchmaking type {self.current_type.name} because no suitable opponent is available.')
self.suspended_types.append(self.current_type)
self.types.remove(self.current_type)
self.current_type = None
if not self.types:
print('No usable matchmaking type configured.')
pending_challenge.set_final_state(Challenge_Response(is_misconfigured=True))
Expand Down Expand Up @@ -129,6 +131,8 @@ def _get_types(self) -> list[Matchmaking_Type]:
def _call_update(self) -> bool:
if self.next_update <= datetime.now():
print('Updating online bots and rankings ...')
self.types.extend(self.suspended_types)
self.suspended_types.clear()
self.online_bots = self._get_online_bots()
return True

Expand Down

0 comments on commit c132bbc

Please sign in to comment.