移除行动点系统,倒计时本地走秒,字体优化
为什么:游戏的时间(40 分钟一天、只能自然流动)本身就是唯一的行动节奏 阀门,再叠一层"每天 10 点行动点"纯属重复惩罚——浇水还要体力既不拟真 也不好玩。删掉之后,稀缺的只剩时间本身,放置玩法的定位反而更纯粹。 改动范围(引擎到界面连根拔): - config 删 START_AP/AP_COST;models 删 ap 字段与 max_ap,存档 payload 里的旧 ap 键被 from_dict 自然忽略; - engine 删 _spend_ap 与全部 8 个调用点、每日恢复逻辑与日志; available_actions 不再按行动点筛,cost 只剩金币; - storage 建表去掉 ap 列,老库在 connect() 里 ALTER TABLE DROP COLUMN 无痛迁移(实测 saves/farm.db 已自动迁完); - bot 删 AP 分支(无 AP 后 available_actions 恒可用);client/TUI/CLI/ README/帮助文本同步清理。 网页端顺带两件事: - "下一天"倒计时改为客户端本地走秒——SSE 只在有变化时推送,以前倒计时 只在推送瞬间跳变,现在每秒都在动(记基点 + 1s 定时器补齐); - 字体优化:页面字体栈补齐 MiSans/HarmonyOS Sans/PingFang,正文字号 14→15,统计数字 tabular-nums;canvas 小字统一字体栈并加粗提对比度。 测试适配:删 2 个 AP 专属用例(无 AP 可测)、改名/收敛 5 个, 532 项全绿(skip 39),ruff/pyright 干净。真机验证:老库迁移、 统计条无行动点、倒计时逐秒递减(39:04→39:02)、动作不再报 no_ap。
This commit is contained in:
1 parent
92b1a628b1
commit
15d290a60a
18 files changed
+82
-179
No files matched your search
@@ -304,7 +304,6 @@ class HarvestAllTestCase(unittest.TestCase):
|
||||
run_action(self.engine, "plant", {"plot": number, "crop": "wheat"})
|
||||
for index in (0, 1):
|
||||
self.engine.state.plots[index].growth = 2
|
||||
self.engine.state.ap = 10
|
||||
|
||||
# 把第一块地做成"看起来熟了、实际收不了"(作物键被改坏)
|
||||
self.engine.state.plots[0].crop = "wheat"
|
||||
|
||||
+11
-16
@@ -64,7 +64,6 @@ BASE_STATE = {
|
||||
"day": 1,
|
||||
"gold": 1000,
|
||||
"feed": 20,
|
||||
"ap": 10,
|
||||
"next_plot_price": 200,
|
||||
"paused": False,
|
||||
"seconds_to_tick": 120.0,
|
||||
@@ -123,11 +122,10 @@ class ScoreTestCase(unittest.TestCase):
|
||||
self.assertEqual(self.score(action, gold=599, next_plot_price=200), 4.0)
|
||||
self.assertEqual(self.score(action, gold=9999, next_plot_price=-1), 4.0, "没地可买")
|
||||
|
||||
def test_animals_need_a_cash_buffer_and_a_free_action_point(self):
|
||||
def test_animals_need_a_cash_buffer(self):
|
||||
action = {"action": "buy_animal", "params": {"kind": "chicken"}}
|
||||
self.assertEqual(self.score(action, gold=270, ap=1), 39.0)
|
||||
self.assertEqual(self.score(action, gold=269, ap=1), 3.0)
|
||||
self.assertEqual(self.score(action, gold=1000, ap=0), 3.0, "没行动点就别想")
|
||||
self.assertEqual(self.score(action, gold=270), 39.0)
|
||||
self.assertEqual(self.score(action, gold=269), 3.0)
|
||||
|
||||
def test_unknown_actions_have_the_lowest_score(self):
|
||||
self.assertEqual(self.score({"action": "fly_to_moon"}), 1.0)
|
||||
@@ -196,7 +194,7 @@ class StepTestCase(unittest.TestCase):
|
||||
state=BASE_STATE,
|
||||
catalog=CATALOG,
|
||||
)
|
||||
client.fail_with = GameError("no_ap", "行动点不足")
|
||||
client.fail_with = GameError("not_enough_gold", "金币不足")
|
||||
bot = make_bot(client)
|
||||
self.assertIsNone(bot.step())
|
||||
self.assertEqual(bot.failures, 1)
|
||||
@@ -208,7 +206,7 @@ class StepTestCase(unittest.TestCase):
|
||||
state=BASE_STATE,
|
||||
catalog=CATALOG,
|
||||
)
|
||||
client.fail_with = GameError("no_ap", "行动点不足")
|
||||
client.fail_with = GameError("not_enough_gold", "金币不足")
|
||||
bot = make_bot(client)
|
||||
bot.step()
|
||||
client.fail_with = None
|
||||
@@ -290,13 +288,11 @@ class RunTestCase(unittest.TestCase):
|
||||
summary = make_bot(client).run(rounds=1)
|
||||
self.assertEqual(set(summary) >= {"name", "days", "actions", "failures", "net_worth"}, True)
|
||||
|
||||
def test_no_action_points_means_clocking_out(self):
|
||||
# AP 用完时,服务端的 available_actions 只会剩下 0 消耗的动作
|
||||
# (卖货/建造/收获/收取),这里模拟"连这些都没有"的极端情况:
|
||||
# 机器人应当直接收工,而不是空转或乱发请求。
|
||||
def test_no_actions_means_clocking_out(self):
|
||||
# 没有任何可执行动作时机器人应当直接收工,而不是空转或乱发请求。
|
||||
client = FakeClient(
|
||||
actions=[],
|
||||
state={**BASE_STATE, "ap": 0},
|
||||
state=BASE_STATE,
|
||||
catalog=CATALOG,
|
||||
)
|
||||
bot = make_bot(client)
|
||||
@@ -304,12 +300,11 @@ class RunTestCase(unittest.TestCase):
|
||||
self.assertEqual(summary["actions"], 0)
|
||||
self.assertEqual(client.calls, [], "没得做就不该发动作请求")
|
||||
|
||||
def test_free_actions_still_run_without_action_points(self):
|
||||
# 新设计:收获不再直接给钱,得靠 sell 把谷仓里的货变现;而 sell/build
|
||||
# 是 0 消耗动作,AP=0 时也必须能执行,否则一整天只能干等着。
|
||||
def test_sell_still_runs_when_idle(self):
|
||||
# 收获不再直接给钱,得靠 sell 把谷仓里的货变现;sell 随时可执行。
|
||||
client = FakeClient(
|
||||
actions=[{"action": "sell", "params": {}}],
|
||||
state={**BASE_STATE, "ap": 0},
|
||||
state=BASE_STATE,
|
||||
catalog=CATALOG,
|
||||
)
|
||||
bot = make_bot(client)
|
||||
|
||||
@@ -227,10 +227,9 @@ class StateViewTestCase(unittest.TestCase):
|
||||
view = StateView(
|
||||
{"day": 1, "gold": 100, "plots": [plot_dict(), plot_dict(index=1)], "animals": []}
|
||||
)
|
||||
view.apply({"gold": 60, "ap": 5})
|
||||
view.apply({"gold": 60})
|
||||
|
||||
self.assertEqual(view.gold, 60)
|
||||
self.assertEqual(view.ap, 5)
|
||||
self.assertEqual(view.day, 1, "没提到的字段要保留")
|
||||
self.assertEqual(len(view.plots), 2, "一次播种不该让农田消失")
|
||||
|
||||
@@ -286,13 +285,12 @@ class StateViewTestCase(unittest.TestCase):
|
||||
"gold": 320,
|
||||
"level": 4,
|
||||
"exp": 11,
|
||||
"ap": 2,
|
||||
"feed": 9,
|
||||
"market": {"corn": 12},
|
||||
}
|
||||
)
|
||||
self.assertEqual((view.day, view.gold, view.level), (5, 320, 4))
|
||||
self.assertEqual((view.exp, view.ap, view.feed), (11, 2, 9))
|
||||
self.assertEqual((view.exp, view.feed), (11, 9))
|
||||
self.assertEqual(view.market["corn"], 12)
|
||||
|
||||
def test_get_and_item_access(self):
|
||||
|
||||
+5
-24
@@ -160,7 +160,6 @@ class GameStateTestCase(unittest.TestCase):
|
||||
state = GameState()
|
||||
self.assertEqual(state.day, 1)
|
||||
self.assertEqual(state.gold, config.START_GOLD)
|
||||
self.assertEqual(state.ap, config.START_AP)
|
||||
self.assertEqual(len(state.plots), config.BASE_PLOTS)
|
||||
self.assertEqual(len(state.animals), 0)
|
||||
|
||||
@@ -209,10 +208,9 @@ class GameStateTestCase(unittest.TestCase):
|
||||
self.assertIsNone(state.next_goal)
|
||||
|
||||
def test_from_dict_clamps_hostile_values(self):
|
||||
"""存档是外部输入:负数金币、越界行动点都要被夹回来。"""
|
||||
state = GameState.from_dict({"gold": -500, "ap": 9999, "level": 0, "day": -3})
|
||||
"""存档是外部输入:负数金币、越界等级都要被夹回来。"""
|
||||
state = GameState.from_dict({"gold": -500, "level": 0, "day": -3})
|
||||
self.assertEqual(state.gold, 0)
|
||||
self.assertEqual(state.ap, state.max_ap)
|
||||
self.assertEqual(state.level, 1)
|
||||
self.assertEqual(state.day, 1)
|
||||
|
||||
@@ -472,12 +470,11 @@ class ActionTestCase(unittest.TestCase):
|
||||
self.assertEqual(ctx.exception.status, 400)
|
||||
|
||||
# ------------------------------------------------------------------ 播种
|
||||
def test_plant_costs_gold_and_action_point(self):
|
||||
gold, ap = self.engine.state.gold, self.engine.state.ap
|
||||
def test_plant_costs_gold(self):
|
||||
gold = self.engine.state.gold
|
||||
result = self.engine.plant(1, "wheat")
|
||||
self.assertTrue(result["ok"])
|
||||
self.assertEqual(self.engine.state.gold, gold - config.CROPS["wheat"]["seed_cost"])
|
||||
self.assertEqual(self.engine.state.ap, ap - config.AP_COST["plant"])
|
||||
|
||||
def test_plant_sets_initial_moisture_and_planted_day(self):
|
||||
self.engine.state.day = 4
|
||||
@@ -511,11 +508,6 @@ class ActionTestCase(unittest.TestCase):
|
||||
self.engine.water(1)
|
||||
self.assertEqual(self.engine.state.plots[0].moisture, config.WATER_CAPACITY)
|
||||
|
||||
def test_water_needs_ap(self):
|
||||
self.engine.plant(1, "wheat")
|
||||
self.engine.state.ap = 0
|
||||
self.assert_code("no_ap", self.engine.water, 1)
|
||||
|
||||
def test_water_rejects_full_and_empty_plots(self):
|
||||
self.assert_code("plot_empty", self.engine.water, 1)
|
||||
self.engine.plant(2, "wheat")
|
||||
@@ -650,7 +642,6 @@ class ActionTestCase(unittest.TestCase):
|
||||
self.engine.state.level = 99
|
||||
self.engine.state.gold = 10**9
|
||||
while self.engine.state.next_plot_price > 0:
|
||||
self.engine.state.ap = 10
|
||||
self.engine.buy_plot()
|
||||
self.assertEqual(len(self.engine.state.plots), config.MAX_PLOTS)
|
||||
self.assert_code("plot_limit", self.engine.buy_plot)
|
||||
@@ -861,11 +852,9 @@ class AdvanceDayTestCase(unittest.TestCase):
|
||||
def setUp(self):
|
||||
self.engine = make_engine()
|
||||
|
||||
def test_day_increments_and_action_points_refill(self):
|
||||
self.engine.state.ap = 0
|
||||
def test_day_increments(self):
|
||||
self.engine.advance_day()
|
||||
self.assertEqual(self.engine.state.day, 2)
|
||||
self.assertEqual(self.engine.state.ap, config.START_AP)
|
||||
|
||||
def test_fed_animals_make_progress_and_get_hungry_again(self):
|
||||
self.engine.buy_animal("chicken") # cycle 1
|
||||
@@ -1038,19 +1027,11 @@ class AvailableActionsTestCase(unittest.TestCase):
|
||||
self.assertIn("collect", actions)
|
||||
self.assertNotIn("feed", actions)
|
||||
|
||||
def test_action_point_shortage_hides_action_point_actions(self):
|
||||
self.engine.state.ap = 0
|
||||
names = self.names()
|
||||
self.assertNotIn("plant", names)
|
||||
self.assertNotIn("water", names)
|
||||
self.assertNotIn("feed", names)
|
||||
|
||||
def test_actions_explain_themselves(self):
|
||||
for item in self.engine.available_actions():
|
||||
with self.subTest(action=item["action"]):
|
||||
self.assertTrue(item["reason"])
|
||||
self.assertIn("gold", item["cost"])
|
||||
self.assertIn("ap", item["cost"])
|
||||
|
||||
|
||||
class LogTestCase(unittest.TestCase):
|
||||
|
||||
@@ -881,7 +881,6 @@ class RestApiTestCase(unittest.TestCase):
|
||||
|
||||
catalog = self.client.get("/api/catalog?farm=alice").json()["catalog"]
|
||||
self.assertEqual(len(catalog["crops"]), len(config.CROPS))
|
||||
self.assertIn("ap_cost", catalog)
|
||||
|
||||
def test_action_then_read_it_back(self):
|
||||
response = self.client.post(
|
||||
|
||||
Reference in new issue
Block a user