Skip to content

Commit

Permalink
Merge branch 'cc004:main' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
666dechaoge authored Nov 8, 2024
2 parents bf8e6a5 + dfc5c6b commit 945f73d
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 10 deletions.
2 changes: 1 addition & 1 deletion autopcr/core/pcrclient.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ async def travel_receive(self, travel_id: int, ex_auto_recycle_option: Union[Tra
if ex_auto_recycle_option is None:
ex_auto_recycle_option = TravelExtraEquipAutoRecycleOptionData(rarity=[], frame=[], category=[])
req = TravelReceiveRequest()
req.travel_quest_id = travel_id
req.travel_id = travel_id
req.ex_auto_recycle_option = ex_auto_recycle_option
return await self.request(req)

Expand Down
17 changes: 13 additions & 4 deletions autopcr/module/modules/sweep.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import random
from collections import Counter
import math
from typing import Set


@description('''
Expand All @@ -21,9 +22,10 @@
代币事件为 30%1000代币70%200代币 或 100%400代币 选项
赌狗策略为前者,保守策略为后者
'''.strip())
@multichoice("travel_speed_up_target", "加速地图", ['1-1', '1-4'], db.travel_quest_candidate)
@singlechoice('travel_quest_gold_event_strategy', "代币事件策略", '赌狗', ['保守','赌狗','随机'])
@singlechoice('travel_quest_equip_event_strategy', "装备事件策略", '赌狗', ['保守','赌狗','随机'])
@inttype('travel_quest_speed_up_paper_hold', "加速券保留", 6, list(range(3001)))
@inttype('travel_quest_speed_up_paper_hold', "加速券保留", 12, list(range(3001)))
@name("探险续航")
@default(True)
class travel_quest_sweep(Module):
Expand Down Expand Up @@ -146,8 +148,15 @@ def get_strategy(event_id: int) -> str:
min(top.remain_daily_decrease_count_ticket, client.data.get_inventory(db.travel_speed_up_paper))
- travel_quest_speed_up_paper_hold, 0)
if team_count and total_use: # avoid divide by zero
travel_speed_up_target = self.get_config("travel_speed_up_target")
self._log(f"可使用加速券{total_use}张")
quest_use = [total_use // team_count + (i < total_use % team_count) for i in range(team_count)]
speed_up_quest_id: Set[int] = {db.get_travel_quest_id_from_candidate(i) for i in travel_speed_up_target}
speed_up_team_count = sum(1 for quest in new_quest_list if quest.travel_quest_id in speed_up_quest_id)
quest_use = [total_use // speed_up_team_count if can_use else 0 for can_use in
[quest.travel_quest_id in speed_up_quest_id for quest in new_quest_list]]
if (paper_remain := total_use - sum(quest_use)) and speed_up_team_count:
for i in random.choices([i for i, v in enumerate(quest_use) if v], k=paper_remain):
quest_use[i] += 1
for quest, use in zip(new_quest_list, quest_use):
if use:
self._log(f"{db.get_quest_name(quest.travel_quest_id)}使用加速券x{use}")
Expand Down Expand Up @@ -470,8 +479,8 @@ class starcup1_sweep(starcup_sweep):
def quest_id(self) -> int:
return 19001001

@inttype("travel_speed_up_paper_threshold", "加速阈值", 6, list(range(12)))
@inttype("travel_target_day", "轮转天数", 7, [2, 3, 5, 7, 10])
@inttype("travel_speed_up_paper_threshold", "加速阈值", 12, list(range(13)))
@inttype("travel_target_day", "轮转天数", 7, list(range(1, 31)))
@multichoice("travel_target_quest3", "轮转目标3", ['1-2','1-3','1-5'], db.travel_quest_candidate)
@multichoice("travel_target_quest2", "轮转目标2", ['1-4'], db.travel_quest_candidate)
@multichoice("travel_target_quest1", "轮转目标1", ['1-1'], db.travel_quest_candidate)
Expand Down
11 changes: 7 additions & 4 deletions autopcr/module/modules/tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,10 @@ async def do_task(self, client: pcrclient):
teams_go = 3 - len(top.travel_quest_list)
if not teams_go:
raise AbortError("已经派遣了3支队伍")
if teams_go < len(travel_quest_id):
raise AbortError(f"可派队伍数量{teams_go}<需派图数{travel_quest_id}")
teams_go = len(travel_quest_id)

memory_unit = 3 * teams_go

forbid_unit = []
Expand Down Expand Up @@ -89,9 +93,10 @@ async def do_task(self, client: pcrclient):
candidate_unit_id = sorted([unit_id for unit_id in unit_power if unit_id not in unit_list and unit_id not in forbid_unit], key=lambda x: unit_power[x], reverse=True)[:teams_go * 7]
candidate_unit_power = [unit_power[unit] for unit in candidate_unit_id]

ret, sol = dispatch_solver(start_power, candidate_unit_power, 7)
lb = [db.travel_quest_data[quest].need_power for quest in travel_quest_id]
ret, sol = dispatch_solver(start_power, candidate_unit_power, lb, 7)
if not ret:
raise AbortError("无解!这不可能!")
raise AbortError(f"无法凑出战力满足最低要求的{teams_go}支队伍!")
for pos, unit in zip(sol, candidate_unit_id):
teams[pos].append(unit)

Expand All @@ -104,8 +109,6 @@ async def do_task(self, client: pcrclient):

if travel_team_go:
self._log('----')
if len(travel_quest_id) != teams_go:
raise AbortError(f"队伍数量{teams_go}与派遣图数{travel_quest_id}不匹配")

start_travel_quest_list: List[TravelStartInfo] = []
for id, (team, quest) in enumerate(zip(teams, travel_quest_id), start = 1):
Expand Down
5 changes: 4 additions & 1 deletion autopcr/util/ilp_solver.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,12 @@ def ilp_solver(ub: List[int], target: int, limit: int, effect: List[int]) -> Tup
print(LpStatus[prob.status])
return prob.status == LpStatusOptimal, ret

def dispatch_solver(start: List[int], candidate: List[int], choose: int) -> Tuple[bool, List[int]]:
def dispatch_solver(start: List[int], candidate: List[int], lb: List[int], choose: int) -> Tuple[bool, List[int]]:
'''
数字分配,使得不同组的数字和尽可能平均
:param start: 组的初始数字和
:param candidate: 候选数字
:param lb: 每组数字和的下界
:param choose: 每组选择的数字个数
:return: 是否有解,数字分配结果
'''
Expand All @@ -42,6 +43,7 @@ def vname(i, j):
n = len(start)
m = len(candidate)
assert n * choose == m, "候选数需等于安排数"
assert len(start) == len(lb), "组数需等于组下界数"
prob = LpProblem(name='dispatch', sense=LpMinimize)

x = [[LpVariable(vname(j, i), lowBound=0, upBound=1, cat=LpInteger) for i in range(n)] for j in range(m)]
Expand All @@ -56,6 +58,7 @@ def vname(i, j):

for i in range(n):
prob += lpSum([x[j][i] for j in range(m)]) == choose, f"dispatch_{i}"
prob += psum[i] >= lb[i], f"dispatch_lb_{i}"
prob += max >= psum[i], f"max_{i}"
prob += min <= psum[i], f"min_{i}"

Expand Down

0 comments on commit 945f73d

Please sign in to comment.