Skip to content

Commit

Permalink
refactor(single-mode): extract Context.expected_score
Browse files Browse the repository at this point in the history
  • Loading branch information
NateScarlet committed Jun 20, 2021
1 parent 9de4297 commit 543fcf2
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 19 deletions.
24 changes: 5 additions & 19 deletions auto_derby/jobs/nurturing.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,40 +68,26 @@ def _handle_training(ctx: Context) -> None:
action.wait_image(_TRAINING_CONFIRM)
t = Training.from_training_scene(template.screenshot())
trainings.append(t)
expected_score = 15 + ctx.turn_count() * 10 / 24

races_with_score = sorted(
((i, i.score(ctx)) for i in race.find(ctx)),
key=lambda x: x[1],
reverse=True,
)

is_summer_camp = ctx.date[1:] in ((7, 1), (7, 2), (8, 1))
can_heal_condition = not is_summer_camp
if ctx.vitality > 0.5:
expected_score *= 0.5
if ctx.turn_count() >= ctx.total_turn_count() - 2:
expected_score *= 0.1
if ctx.date[1:] in ((6, 1),) and ctx.vitality < 0.8:
expected_score += 10
if ctx.date[1:] in ((6, 2),) and ctx.vitality < 0.9:
expected_score += 20
if is_summer_camp and ctx.vitality < 0.8:
expected_score += 10
if ctx.date in ((4, 0, 0)):
expected_score -= 20
if can_heal_condition and ctx.CONDITION_HEADACHE in ctx.conditions:
expected_score += 20

LOGGER.info("expected score:\t%2.2f", expected_score)
trainings_with_score = [(i, i.score(ctx)) for i in trainings]
trainings_with_score = sorted(
trainings_with_score, key=lambda x: x[1], reverse=True
)

expected_score = ctx.expected_score()
LOGGER.info("expected score:\t%2.2f", expected_score)
for r, s in races_with_score:
LOGGER.info("score:\trace:\t%2.2f:\t%s", s, r)
for t, s in trainings_with_score:
LOGGER.info("score:\ttraining:\t%2.2f:\t%s", s, t)
training, score = trainings_with_score[0]

if races_with_score:
r, s = races_with_score[0]
if s > expected_score and s > score:
Expand Down
22 changes: 22 additions & 0 deletions auto_derby/single_mode/context.py
Original file line number Diff line number Diff line change
Expand Up @@ -355,6 +355,28 @@ def continuous_race_count(self) -> int:
turn -= 1
return ret

def expected_score(self) -> float:
expected_score = 15 + self.turn_count() * 10 / 24

is_summer_camp = self.date[1:] in ((7, 1), (7, 2), (8, 1))
can_heal_condition = not is_summer_camp
if self.vitality > 0.5:
expected_score *= 0.5
if self.turn_count() >= self.total_turn_count() - 2:
expected_score *= 0.1
if self.date[1:] in ((6, 1),) and self.vitality < 0.8:
expected_score += 10
if self.date[1:] in ((6, 2),) and self.vitality < 0.9:
expected_score += 20
if is_summer_camp and self.vitality < 0.8:
expected_score += 10
if self.date in ((4, 0, 0)):
expected_score -= 20
if can_heal_condition and self.CONDITION_HEADACHE in self.conditions:
expected_score += 20

return expected_score


g.context_class = Context

Expand Down

0 comments on commit 543fcf2

Please sign in to comment.