Skip to content

Commit

Permalink
merge
Browse files Browse the repository at this point in the history
  • Loading branch information
JoeDailey committed Sep 26, 2020
2 parents 6f771c4 + e517220 commit 6e98c1e
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 9 deletions.
9 changes: 8 additions & 1 deletion matchmaking/linear_regression_ranker.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,17 @@ async def get_scores(channel: TextChannel) -> Dict[int, float]:

player_scores = {}
for i, player in enumerate(data.get_all_players()):
player_scores[player] = (scores[i] - average) / std_dev
score = (scores[i] - average) / std_dev
player_scores[player] = __normalize(score)
return player_scores


def __normalize(score: float) -> int:
score += 2
score *= 1000
return int(score)


def __get_training_data(data: GameData) -> matrix:
game_rows = []
players = data.get_all_players()
Expand Down
6 changes: 4 additions & 2 deletions models/lobby.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,9 @@ async def add(self, user: Member, author: Optional[Member] = None) -> None:

player = Player(user)
if self.has_joined(player):
raise UsageException.already_joined(self.channel)
raise UsageException.already_joined(
self.channel, author is not None
)

self.players.append(player)
self.reset_orderings()
Expand All @@ -51,7 +53,7 @@ async def add(self, user: Member, author: Optional[Member] = None) -> None:
async def remove(self, user: Member, author: Optional[Member] = None):
player = Player(user)
if player not in self.players:
raise UsageException.not_in_lobby(self.channel, player)
raise UsageException.not_in_lobby(self.channel)

if author is None:
# If a user removes themself, then _others_
Expand Down
14 changes: 8 additions & 6 deletions utils/usage_exception.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,16 +34,18 @@ def game_is_full(channel: TextChannel):
)

@staticmethod
def already_joined(channel: TextChannel):
return UsageException(
channel,
"Sorry the game is full. Please wait for someone to leave.",
)
def already_joined(channel: TextChannel, from_other: bool):
if from_other:
return UsageException(
channel, "This player is already in the lobby."
)

return UsageException(channel, "You are already in the lobby.")

@staticmethod
def not_in_lobby(channel: TextChannel, player: Player):
return UsageException(
channel, f"Player not in lobby: {player.get_name()}"
channel, f"This player is not in the lobby: {player.get_name()}"
)

@staticmethod
Expand Down

0 comments on commit 6e98c1e

Please sign in to comment.