summaryrefslogtreecommitdiff
path: root/src/LivingVillage.Kernel
diff options
context:
space:
mode:
authorSomhairle H. Marisol <[email protected]>2026-09-22 16:16:40 +0800
committerSomhairle H. Marisol <[email protected]>2026-09-22 16:16:40 +0800
commit6c2f180cc7c8315e32d88cbe5d44928d495fe473 (patch)
treeb882d707e1ac1b31c885b19e1f2ce31534448c52 /src/LivingVillage.Kernel
parent2f915a48837039dc772d7fa25b83b34a707922fd (diff)
downloadliving-village-6c2f180cc7c8315e32d88cbe5d44928d495fe473.tar.gz
feat(kernel): P31 step1 occupation dialogue response bias
- Occupation.biasResponse: deterministic pure remap over Sim.responseFor; no occupation = byte-identical pass-through (all intents x personalities). farmer AskHelp Refused->Helpful; fisher SmallTalk Reserved->Friendly; peddler SmallTalk Reserved->Bargaining; scholar Joke fully overridden to Reserved (documented total-override semantics, opposite of personality). - Sim.responseFor made public (same pure function, reused as the base path). - Sim.chooseDialogueWith: extracted body of chooseDialogue with an injectable respond function; chooseDialogue keeps identity semantics unchanged. - Sim.appendAnnal made public for the upcoming story annal writes. - 9 new kernel tests (92 -> 101); performance digest unchanged.
Diffstat (limited to 'src/LivingVillage.Kernel')
-rw-r--r--src/LivingVillage.Kernel/Occupation.fs31
-rw-r--r--src/LivingVillage.Kernel/Sim.fs19
2 files changed, 46 insertions, 4 deletions
diff --git a/src/LivingVillage.Kernel/Occupation.fs b/src/LivingVillage.Kernel/Occupation.fs
index 2168c4e..8ce5060 100644
--- a/src/LivingVillage.Kernel/Occupation.fs
+++ b/src/LivingVillage.Kernel/Occupation.fs
@@ -241,3 +241,34 @@ module Occupation =
/// Sim.quotePrice 的输出经职业偏置映射;None(无报价)原样穿透。
let biasedQuote (kind: Kind option) (playerIsBuyer: bool) (baseQuote: float32 option) : float32 option =
baseQuote |> Option.map (fun price -> price * quoteBiasOf kind playerIsBuyer)
+
+ // ---- 对话分支倾向(design §5 / P-d):村民对玩家职业的确定性回应偏差 ----
+ // 全部为纯函数重映射:基底仍走 Sim.responseFor 的人格口径,偏差不引入随机。
+ // 无职业(None)= 原回应逐字节不变。
+ // 规则(各自只作用于签名意图,其余意图原样穿透):
+ // 农夫 AskHelp:Refused → Helpful(老实人家,求助不落空);
+ // 渔夫 SmallTalk:Reserved → Friendly(聊的是天气鱼汛,冷场变热络);
+ // 货郎 SmallTalk:Reserved → Bargaining(三句不离买卖,更易进讨价还价);
+ // 书生 Joke:完全覆盖为 Reserved(读过书的人讲笑话,众人反而拘谨)——
+ // 与 personality 相反时采用完全覆盖语义而非概率偏向,确定性可测(design §5 反差感)。
+ let private remapResponse
+ (kind: Kind)
+ (intent: Sim.DialogueIntent)
+ (baseResponse: Sim.DialogueResponse)
+ : Sim.DialogueResponse =
+ match kind, intent, baseResponse with
+ | Farmer, Sim.AskHelp, Sim.Refused -> Sim.Helpful
+ | Fisher, Sim.SmallTalk, Sim.Reserved -> Sim.Friendly
+ | Peddler, Sim.SmallTalk, Sim.Reserved -> Sim.Bargaining
+ | Scholar, Sim.Joke, _ -> Sim.Reserved
+ | _ -> baseResponse
+
+ let biasResponse
+ (kind: Kind option)
+ (intent: Sim.DialogueIntent)
+ (personality: Sim.Personality)
+ : Sim.DialogueResponse =
+ let baseResponse = Sim.responseFor intent personality
+ match kind with
+ | None -> baseResponse
+ | Some kind -> remapResponse kind intent baseResponse
diff --git a/src/LivingVillage.Kernel/Sim.fs b/src/LivingVillage.Kernel/Sim.fs
index 5c4e107..348a60e 100644
--- a/src/LivingVillage.Kernel/Sim.fs
+++ b/src/LivingVillage.Kernel/Sim.fs
@@ -299,7 +299,8 @@ module Sim =
let clamp (v: float32) (lo: float32) (hi: float32) : float32 = if v < lo then lo elif v > hi then hi else v
- let private appendAnnal (entry: AnnalEntry) (world: World) : World =
+ /// P-d 起对调用方公开(剧情线年鉴写入复用同一裁剪口径,语义不变)。
+ let appendAnnal (entry: AnnalEntry) (world: World) : World =
{ world with Annals = (entry :: world.Annals) |> List.truncate maxAnnalEntries }
let hungerDecayPerTick = 0.0012f
@@ -765,7 +766,8 @@ module Sim =
{ Target = target
Options = dialogueOptions })
- let private responseFor (intent: DialogueIntent) (personality: Personality) : DialogueResponse =
+ /// 纯人格回应函数;P-d 起对调用方公开,供 Occupation.biasResponse 复用原口径。
+ let responseFor (intent: DialogueIntent) (personality: Personality) : DialogueResponse =
match intent with
| SmallTalk -> if personality.Extraversion >= 0.5f then Friendly else Reserved
| AskHelp -> if personality.Honesty >= 0.4f then Helpful else Refused
@@ -782,7 +784,12 @@ module Sim =
sprintf "rumor tick=%d source=%A narrator=%A receiver=%A depth=%d"
rumor.Tick rumor.Source rumor.Narrator rumor.Receiver rumor.Depth
- let chooseDialogue (target: NpcId) (intent: DialogueIntent) (world: World) : DialogueResult =
+ let chooseDialogueWith
+ (respond: DialogueIntent -> Personality -> DialogueResponse)
+ (target: NpcId)
+ (intent: DialogueIntent)
+ (world: World)
+ : DialogueResult =
match findNpcIndex target world.Npcs with
| None -> DialogueRejected(DialogueTargetNotFound, world)
| Some targetIndex ->
@@ -794,7 +801,7 @@ module Sim =
elif not (dialogueAvailable targetNpc) then
DialogueRejected(DialogueTargetUnavailable, world)
else
- let response = responseFor intent targetNpc.Mind.Personality
+ let response = respond intent targetNpc.Mind.Personality
let outcome =
{ Tick = world.Tick
Actor = playerId
@@ -842,6 +849,10 @@ module Sim =
withRumorAnnal
DialogueSucceeded(outcome, withDialogueAnnal)
+ /// 既有入口:无职业偏差的人格回应路径(identity,与历史行为逐字节一致)。
+ let chooseDialogue (target: NpcId) (intent: DialogueIntent) (world: World) : DialogueResult =
+ chooseDialogueWith responseFor target intent world
+
let annalText (world: World) : string =
let rows =
world.Annals