Initial
This commit is contained in:
commit
2ca7a264b3
53 files changed
+7113
No files matched your search
@@ -0,0 +1,94 @@
|
||||
"""Stateless worker. Inputs consist exclusively of the acting seat's view."""
|
||||
|
||||
from collections import Counter
|
||||
|
||||
|
||||
def permitted(weather, size, lane):
|
||||
return weather not in ("FG", "ICE", lane) and (weather, size) not in (
|
||||
("CW", 1),
|
||||
("SN", 3),
|
||||
)
|
||||
|
||||
|
||||
def decide(request):
|
||||
v, commands = request["view"], request["actions"]
|
||||
seat = v["seat"]
|
||||
planes = v["planes"]
|
||||
stock = Counter(v["hand"])
|
||||
remaining = Counter(p["owner"] for p in planes.values() if p["pos"] != "F")
|
||||
heads = [
|
||||
(p, p["pos"].split(":")[1])
|
||||
for p in planes.values()
|
||||
if p["pos"].startswith("D:") and p["pos"].endswith(":0")
|
||||
]
|
||||
|
||||
def evaluate(cmd):
|
||||
kind = cmd["kind"]
|
||||
p = planes.get(cmd.get("plane"), {})
|
||||
if kind == "runway":
|
||||
lane, position = cmd["to"].split(":")[1:]
|
||||
return 100 - int(position) * 4 + 3 * permitted(
|
||||
v["weather"], p["size"], lane
|
||||
), "Выбор полосы по очереди и погоде"
|
||||
if kind == "choose":
|
||||
return 100, "Выбор среди равноценных целей обязательной неприятности"
|
||||
if kind == "ice":
|
||||
return 125, "Обработка позволяет вылететь сейчас"
|
||||
if kind == "weather":
|
||||
new, old = cmd["cards"][0], v["weather"]
|
||||
gain = sum(
|
||||
(1 if q["owner"] == seat else -0.28)
|
||||
* (
|
||||
int(permitted(new, q["size"], lane))
|
||||
- int(permitted(old, q["size"], lane))
|
||||
)
|
||||
for q, lane in heads
|
||||
)
|
||||
return (
|
||||
10 + gain * 95,
|
||||
"Изменение доступности вылета на исполнительных стартах",
|
||||
)
|
||||
if kind == "attack":
|
||||
st = p["pos"].split(":")[0]
|
||||
advance = {"D": 50, "V2": 30, "V1": 20, "B": 22, "C": 22, "A": 12}[st]
|
||||
return 10 + advance + 58 / remaining[
|
||||
p["owner"]
|
||||
], "Возврат продвинутого борта соперника в ангар"
|
||||
if kind == "move":
|
||||
target = cmd["to"].split(":")
|
||||
base = {"D": 82, "V1": 77, "B": 64, "C": 64, "A": 48}[target[0]]
|
||||
if target[0] == "D":
|
||||
base -= int(target[-1]) * 4
|
||||
base += 3 * permitted(v["weather"], p["size"], target[1])
|
||||
if target[0] == "V1":
|
||||
base += 3 * p["size"]
|
||||
return base - cmd["cards"].count(
|
||||
"LC"
|
||||
) * 2, "Продвижение к старту с учётом очереди, размера и цены"
|
||||
return 26, "Обмен для пополнения руки картами движения"
|
||||
|
||||
ranking = []
|
||||
for cmd in commands:
|
||||
score, reason = evaluate(cmd)
|
||||
if cmd["kind"] == "exchange":
|
||||
|
||||
def keep(c):
|
||||
return {
|
||||
"LC": 10,
|
||||
"VIP": 11,
|
||||
"D": 7,
|
||||
"A": 7,
|
||||
"B": 5,
|
||||
"C": 5,
|
||||
"FLR": 6,
|
||||
"AI": 3,
|
||||
}.get(c, 2) - stock[c] * 0.7
|
||||
|
||||
cards = sorted(v["hand"], key=lambda c: (keep(c), c))
|
||||
cmd = dict(
|
||||
kind="exchange",
|
||||
cards=cards[: min(4, max(1, sum(keep(c) < 5 for c in cards)))],
|
||||
)
|
||||
ranking.append(dict(command=cmd, score=round(score, 2), reason=reason))
|
||||
ranking.sort(key=lambda item: -item["score"])
|
||||
return dict(command=ranking[0]["command"], alternatives=ranking[:3])
|
||||
Reference in new issue
Block a user