Spaces:
Sleeping
Sleeping
Thibault Duplessis commited on
Commit ·
b2fa1c4
1
Parent(s): 0102145
improve challenge sorting
Browse files- config.yml.default +1 -1
- main.py +2 -3
- model.py +7 -0
config.yml.default
CHANGED
|
@@ -16,7 +16,7 @@ ucioptions: # arbitrary UCI options passed to the engine
|
|
| 16 |
|
| 17 |
|
| 18 |
max_concurrent_games: 1 # number of games to play simultaneously
|
| 19 |
-
sort_challenges_by: "
|
| 20 |
|
| 21 |
supported_variants: # chess variants to accept (http://lichess.org/variant)
|
| 22 |
- standard
|
|
|
|
| 16 |
|
| 17 |
|
| 18 |
max_concurrent_games: 1 # number of games to play simultaneously
|
| 19 |
+
sort_challenges_by: "best" # possible values: "best", "first"
|
| 20 |
|
| 21 |
supported_variants: # chess variants to accept (http://lichess.org/variant)
|
| 22 |
- standard
|
main.py
CHANGED
|
@@ -59,9 +59,8 @@ def start(li, user_profile, max_games, engine_factory, config):
|
|
| 59 |
chlng = model.Challenge(event["challenge"])
|
| 60 |
if can_accept_challenge(chlng, config):
|
| 61 |
challenge_queue.append(chlng)
|
| 62 |
-
if (config.get("sort_challenges_by") =
|
| 63 |
-
challenge_queue.sort(key=lambda c: -c.
|
| 64 |
-
challenge_queue.sort(key=lambda c: not c.rated)
|
| 65 |
else:
|
| 66 |
try:
|
| 67 |
li.decline_challenge(chlng.id)
|
|
|
|
| 59 |
chlng = model.Challenge(event["challenge"])
|
| 60 |
if can_accept_challenge(chlng, config):
|
| 61 |
challenge_queue.append(chlng)
|
| 62 |
+
if (config.get("sort_challenges_by") != "first"):
|
| 63 |
+
challenge_queue.sort(key=lambda c: -c.score())
|
|
|
|
| 64 |
else:
|
| 65 |
try:
|
| 66 |
li.decline_challenge(chlng.id)
|
model.py
CHANGED
|
@@ -9,6 +9,8 @@ class Challenge():
|
|
| 9 |
self.perf_name = c_info["perf"]["name"]
|
| 10 |
self.speed = c_info["speed"]
|
| 11 |
self.challenger = c_info.get("challenger")
|
|
|
|
|
|
|
| 12 |
self.challengerName = self.challenger["name"] if self.challenger else "Anonymous"
|
| 13 |
self.challengerRatingInt = self.challenger["rating"] if self.challenger else 0
|
| 14 |
self.challengerRating = self.challengerRatingInt or "?"
|
|
@@ -28,6 +30,11 @@ class Challenge():
|
|
| 28 |
modes = config["supported_modes"]
|
| 29 |
return self.is_supported_speed(tc) and self.is_supported_variant(variants) and self.is_supported_mode(modes)
|
| 30 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 31 |
def __str__(self):
|
| 32 |
return "{} challenge from {}({})".format(self.perf_name, self.challengerName, self.challengerRating)
|
| 33 |
|
|
|
|
| 9 |
self.perf_name = c_info["perf"]["name"]
|
| 10 |
self.speed = c_info["speed"]
|
| 11 |
self.challenger = c_info.get("challenger")
|
| 12 |
+
self.challengerTitle = self.challenger.get("title") if self.challenger else None
|
| 13 |
+
self.challengerMasterTitle = self.challengerTitle if self.challengerTitle != "BOT" else None
|
| 14 |
self.challengerName = self.challenger["name"] if self.challenger else "Anonymous"
|
| 15 |
self.challengerRatingInt = self.challenger["rating"] if self.challenger else 0
|
| 16 |
self.challengerRating = self.challengerRatingInt or "?"
|
|
|
|
| 30 |
modes = config["supported_modes"]
|
| 31 |
return self.is_supported_speed(tc) and self.is_supported_variant(variants) and self.is_supported_mode(modes)
|
| 32 |
|
| 33 |
+
def score(self):
|
| 34 |
+
ratedBonus = 200 if self.rated else 0
|
| 35 |
+
titledBonus = 200 if self.challengerMasterTitle else 0
|
| 36 |
+
return self.challengerRatingInt + ratedBonus + titledBonus
|
| 37 |
+
|
| 38 |
def __str__(self):
|
| 39 |
return "{} challenge from {}({})".format(self.perf_name, self.challengerName, self.challengerRating)
|
| 40 |
|