@clawtopia/werewolf-evolution 0.1.11 → 0.1.12
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.js +151 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -760,7 +760,38 @@ var FIXED_RULE_LANGUAGE = /(?:JSON\s*schema|JSON格式|非法动作|角色动作
|
|
|
760
760
|
var COUNTER_EFFECT_LANGUAGE = /(?:未能|没有|无法|无效|反而|恶化|失败|矛盾|误导|暴露|did not|failed|ineffective|worse|contradict)/i;
|
|
761
761
|
var NO_TARGET_ALTERNATIVE_LANGUAGE = /(?:保留投票权|等待更多信息|暂不(?:投票|选择|行动)|弃票|不选(?:择)?(?:任何)?(?:目标|座位)|不指定目标|不设目标|继续观望|\b(?:wait for more information|abstain|hold (?:the )?vote|choose no target)\b)/i;
|
|
762
762
|
var EXPLICIT_TARGET_LANGUAGE = /(?:(?:改投|改票(?:到|给)?|归票|票投|投票(?:给|到)?|投(?:给|到)?|查验|验|刀|毒|救|开枪带走|目标(?:改为|是)?)\s*|target(?:\s+seat)?[^0-9]{0,6})([1-9][0-9]*)\s*(?:号|座|\b)/gi;
|
|
763
|
-
var FINAL_RESULT_LANGUAGE = /(?:最终|终局|全场|对局结果|比赛结果)[^。;,,!!]{0,16}(?:获胜|胜利|胜出|取胜|赢了|输了|落败|失败)|(?:好人(?:阵营)?|村民|平民|狼人(?:阵营)?|狼队)[^。;,,!!]{0,10}(?:获胜|胜利|胜出|取胜|赢了|输了|落败)|赢下(?:本局|这局|对局|比赛)|(?:GOOD|WOLF)(?:_TEAM)?_WIN|(?:the\s+)?(?:(?:good|village|wolf)\s+team|villagers?|village|wolves|wolf|werewolves?)\s+(?:wins?|won|loses?|lost)|(?:won|lost) the game|final (?:victory|defeat)/i;
|
|
763
|
+
var FINAL_RESULT_LANGUAGE = /(?:最终|终局|全场|对局结果|比赛结果)[^。;,,!!]{0,16}(?:获胜|胜利|胜出|取胜|赢了|输了|落败|失败)|(?:好人(?:阵营)?|村民|平民|狼人(?:阵营)?|狼队)[^。;,,!!]{0,10}(?:获胜|胜利|胜出|取胜|赢了|输了|落败)|(?:险胜|惨胜|翻盘获胜|为(?:最终)?胜利铺路)|赢下(?:本局|这局|对局|比赛)|(?:GOOD|WOLF)(?:_TEAM)?_WIN|(?:the\s+)?(?:(?:good|village|wolf)\s+team|villagers?|village|wolves|wolf|werewolves?)\s+(?:wins?|won|loses?|lost)|(?:won|lost) the game|final (?:victory|defeat)/i;
|
|
764
|
+
var SEAT_REFERENCE_LANGUAGE = /([1-9][0-9]*)\s*号(?:玩家)?/g;
|
|
765
|
+
var BEHAVIOR_TERMS = "\u53D1\u8A00|\u8868\u73B0|\u884C\u4E3A|\u8BF4\u6CD5|\u5185\u5BB9|\u7AD9\u8FB9|\u7968\u578B|\u6295\u7968|\u5F52\u7968|\u7529\u9505|\u8D28\u7591|\u5BF9\u8DF3|\u8D77\u8DF3|\u608D\u8DF3|\u5012\u94A9|\u67E5\u6740|\u4FDD\u4EBA|\u8E29\u4EBA|\u653B\u51FB|\u8FA9\u89E3|\u8DDF\u7968|\u51B2\u7968|\u8868\u6C34";
|
|
766
|
+
var FIRST_NIGHT_DAYTIME_INFORMATION = new RegExp(
|
|
767
|
+
`(?:\u73A9\u5BB6)?\u53D1\u8A00\u98CE\u683C|(?:\u767D\u5929|\u767D\u663C|\u65E5\u95F4|\u9996\u65E5|\u7B2C\u4E00\u5929|\u5929\u4EAE\u540E|\u6B21\u65E5|\u7B2C\u4E8C\u5929|\u968F\u540E|\u540E\u7EED)[^\u3002\uFF1B\uFF0C,!\uFF01]{0,16}(?:${BEHAVIOR_TERMS})|(?:${BEHAVIOR_TERMS})[^\u3002\uFF1B\uFF0C,!\uFF01]{0,16}(?:\u767D\u5929|\u767D\u663C|\u65E5\u95F4|\u9996\u65E5|\u7B2C\u4E00\u5929|\u5929\u4EAE\u540E|\u6B21\u65E5|\u7B2C\u4E8C\u5929|\u968F\u540E|\u540E\u7EED)`,
|
|
768
|
+
"i"
|
|
769
|
+
);
|
|
770
|
+
var DIRECTLY_NEGATED_DAYTIME_INFORMATION = /(?:尚无|暂无|没有|尚未(?:出现|发生)?)(?:任何)?(?:白天|白昼|日间|首日|第一天)?(?:发言|站边|票型|归票|信息)|不(?:得|可|能|应)?(?:参考|使用|依赖)(?:(?:任何)?(?:白天|白昼|日间|首日|第一天)(?:发言|站边|票型|归票|信息)|(?:玩家)?发言风格)|(?:白天|白昼|日间|首日|第一天)(?:发言|站边|票型|归票|信息)(?:尚无|暂无|尚未(?:出现|发生)|不可用|不能使用)/gi;
|
|
771
|
+
var RELATIVE_FUTURE_BEHAVIOR_LANGUAGE = new RegExp(
|
|
772
|
+
`(?:(?:\u540E\u7F6E\u4F4D|\u5176\u4ED6\u73A9\u5BB6)[^\u3002\uFF1B\uFF0C,!\uFF01]{0,10}(?:\u968F\u540E|\u4E4B\u540E|\u5C06\u4F1A?|\u7A0D\u540E)|\u5929\u4EAE(?:\u540E|\u4E4B\u540E)|\u6B21\u65E5|\u4E0B\u4E00(?:\u5929|\u8F6E|\u4E2A\u767D\u5929))[^\u3002\uFF1B\uFF0C,!\uFF01]{0,20}(?:${BEHAVIOR_TERMS})`,
|
|
773
|
+
"i"
|
|
774
|
+
);
|
|
775
|
+
var ABSOLUTE_DAY_BEHAVIOR_LANGUAGE = new RegExp(`\u7B2C([0-9\u4E00\u4E8C\u4E09\u56DB\u4E94\u516D\u4E03\u516B\u4E5D\u5341]+)\u5929[^\u3002\uFF1B\uFF0C,!\uFF01]{0,24}(?:${BEHAVIOR_TERMS})`, "gi");
|
|
776
|
+
var BEHAVIOR_OCCURRENCE_LANGUAGE = new RegExp(`(?:${BEHAVIOR_TERMS})`, "i");
|
|
777
|
+
var PAST_BEHAVIOR_LANGUAGE = new RegExp(`(?:\u6B64\u524D|\u4E4B\u524D|\u66FE\u7ECF|\u8FC7\u53BB|\u4E0A\u4E00\u8F6E|\u4E0A\u4E00\u591C|\u6628\u591C)|\u5DF2\u7ECF(?!\u51B3\u5B9A)[^\u3002\uFF1B\uFF0C,!\uFF01]{0,4}(?:${BEHAVIOR_TERMS})`, "i");
|
|
778
|
+
var CURRENT_ACTOR_ACTION_LANGUAGE = /(?:当前|本次|此时|轮到|发言时|投票时|行动时|查验时|已经决定|正在|正要|准备|计划|将要)/i;
|
|
779
|
+
var NEGATED_BEHAVIOR_LANGUAGE = new RegExp(`(?:\u6CA1\u6709|\u5E76\u672A|\u672A\u66FE|\u4E0D\u66FE|\u4ECE\u672A|\u5C1A\u672A|\u4E0D)[^\u3002\uFF1B\uFF0C,!\uFF01]{0,6}(?:${BEHAVIOR_TERMS})|(?:did not|never|no)\\b`, "i");
|
|
780
|
+
var BEHAVIOR_TARGET_LANGUAGE = /(?:归票|投票(?:给|到)?|票投(?:给|到)?|投(?:给|到)|跟票(?:给|到)?|冲票(?:给|到)?|查杀|保人|踩|攻击|质疑)(?:给|到|向)?\s*([1-9][0-9]*)\s*号/i;
|
|
781
|
+
var TARGET_REFERENCE_PREFIX = /(?:归票|投票|票投|投给|投到|跟票|冲票|查杀|保人|踩|攻击|质疑)(?:给|到|向)?\s*$/i;
|
|
782
|
+
var SPEECH_FACT_TYPES = /* @__PURE__ */ new Set(["DAY_SPEAK", "LAST_WORD", "WOLF_SPEECH"]);
|
|
783
|
+
var VOTE_FACT_TYPES = /* @__PURE__ */ new Set(["DAY_VOTE_SUBMIT", "DAY_REVOTE_SUBMIT"]);
|
|
784
|
+
var BEHAVIOR_GROUPS = [
|
|
785
|
+
/(?:投票|归票|跟票|冲票|票投|出票)/i,
|
|
786
|
+
/(?:甩锅|推责|责任推|把责任)/i,
|
|
787
|
+
/(?:站边|支持|认好|认狼|side with|support)/i,
|
|
788
|
+
/(?:质疑|怀疑|攻击|踩人|question|suspect|attack)/i,
|
|
789
|
+
/(?:对跳|起跳|悍跳|拍身份|公开身份|role claim|claim(?:ed)? (?:seer|witch|hunter))/i,
|
|
790
|
+
/(?:倒钩)/i,
|
|
791
|
+
/(?:查杀)/i,
|
|
792
|
+
/(?:保人|金水)/i,
|
|
793
|
+
/(?:辩解|表水)/i
|
|
794
|
+
];
|
|
764
795
|
var LOCAL_OUTCOME_FACT_TYPES = /* @__PURE__ */ new Set([
|
|
765
796
|
"WOLF_CHOOSE",
|
|
766
797
|
"WOLF_SPEECH",
|
|
@@ -848,6 +879,88 @@ function similarity(left, right) {
|
|
|
848
879
|
function sameSemanticText(left, right) {
|
|
849
880
|
return typeof left === "string" && semanticText(left) === semanticText(right);
|
|
850
881
|
}
|
|
882
|
+
function stripUnavailableDaytimeInformation(value) {
|
|
883
|
+
return value.replace(DIRECTLY_NEGATED_DAYTIME_INFORMATION, "");
|
|
884
|
+
}
|
|
885
|
+
function behaviorTarget(value) {
|
|
886
|
+
const direct = BEHAVIOR_TARGET_LANGUAGE.exec(value);
|
|
887
|
+
if (direct) return Number(direct[1]);
|
|
888
|
+
for (const match of value.matchAll(SEAT_REFERENCE_LANGUAGE)) {
|
|
889
|
+
const prefix = value.slice(Math.max(0, match.index - 12), match.index);
|
|
890
|
+
if (TARGET_REFERENCE_PREFIX.test(prefix)) return Number(match[1]);
|
|
891
|
+
}
|
|
892
|
+
return void 0;
|
|
893
|
+
}
|
|
894
|
+
function factSupportsBehaviorClaim(fact, claim) {
|
|
895
|
+
if (fact.actorSeat == null) return false;
|
|
896
|
+
const summary = fact.summary;
|
|
897
|
+
const claimedTarget = behaviorTarget(claim);
|
|
898
|
+
if (claimedTarget !== void 0) {
|
|
899
|
+
const observedTarget = fact.targetSeat ?? behaviorTarget(summary);
|
|
900
|
+
if (observedTarget !== claimedTarget) return false;
|
|
901
|
+
}
|
|
902
|
+
if (NEGATED_BEHAVIOR_LANGUAGE.test(claim) !== NEGATED_BEHAVIOR_LANGUAGE.test(summary)) {
|
|
903
|
+
return false;
|
|
904
|
+
}
|
|
905
|
+
const groups = BEHAVIOR_GROUPS.filter((pattern) => pattern.test(claim));
|
|
906
|
+
if (groups.length > 0) {
|
|
907
|
+
if (groups.some((pattern) => pattern.test(summary))) return true;
|
|
908
|
+
return groups.some((pattern) => pattern === BEHAVIOR_GROUPS[0] && VOTE_FACT_TYPES.has(fact.type));
|
|
909
|
+
}
|
|
910
|
+
if (/(?:发言|说法|内容)/i.test(claim) && SPEECH_FACT_TYPES.has(fact.type)) {
|
|
911
|
+
const shortGenericClaim = semanticText(claim).length <= 6;
|
|
912
|
+
return shortGenericClaim || similarity(claim, summary) >= 0.28;
|
|
913
|
+
}
|
|
914
|
+
return similarity(claim, summary) >= 0.35;
|
|
915
|
+
}
|
|
916
|
+
function seatBehaviorClaims(value) {
|
|
917
|
+
const claims = [];
|
|
918
|
+
for (const clause of value.split(/[。;,,!!]/)) {
|
|
919
|
+
const seats = [...clause.matchAll(SEAT_REFERENCE_LANGUAGE)];
|
|
920
|
+
for (let index = 0; index < seats.length; index++) {
|
|
921
|
+
const match = seats[index];
|
|
922
|
+
const start = match.index;
|
|
923
|
+
const nextSeat = seats[index + 1];
|
|
924
|
+
const beforeNextSeat = nextSeat ? clause.slice(start + match[0].length, nextSeat.index) : "";
|
|
925
|
+
const end = nextSeat && TARGET_REFERENCE_PREFIX.test(beforeNextSeat) ? nextSeat.index + nextSeat[0].length : nextSeat?.index ?? clause.length;
|
|
926
|
+
const claim = clause.slice(start, end).trim();
|
|
927
|
+
if (BEHAVIOR_OCCURRENCE_LANGUAGE.test(claim)) claims.push({ seat: Number(match[1]), claim });
|
|
928
|
+
}
|
|
929
|
+
}
|
|
930
|
+
return claims;
|
|
931
|
+
}
|
|
932
|
+
function isCurrentDecisionActorClaim(claim) {
|
|
933
|
+
return !PAST_BEHAVIOR_LANGUAGE.test(claim) && CURRENT_ACTOR_ACTION_LANGUAGE.test(claim);
|
|
934
|
+
}
|
|
935
|
+
function chineseNumber(value) {
|
|
936
|
+
if (/^[0-9]+$/.test(value)) return Number(value);
|
|
937
|
+
const digits = {
|
|
938
|
+
\u4E00: 1,
|
|
939
|
+
\u4E8C: 2,
|
|
940
|
+
\u4E09: 3,
|
|
941
|
+
\u56DB: 4,
|
|
942
|
+
\u4E94: 5,
|
|
943
|
+
\u516D: 6,
|
|
944
|
+
\u4E03: 7,
|
|
945
|
+
\u516B: 8,
|
|
946
|
+
\u4E5D: 9
|
|
947
|
+
};
|
|
948
|
+
if (value === "\u5341") return 10;
|
|
949
|
+
if (value.startsWith("\u5341")) return 10 + (digits[value[1]] ?? 0);
|
|
950
|
+
if (value.endsWith("\u5341")) return (digits[value[0]] ?? 0) * 10;
|
|
951
|
+
const [tens, ones] = value.split("\u5341");
|
|
952
|
+
if (ones !== void 0) return (digits[tens] ?? 0) * 10 + (digits[ones] ?? 0);
|
|
953
|
+
return digits[value];
|
|
954
|
+
}
|
|
955
|
+
function dependsOnFutureBehavior(value, currentRound) {
|
|
956
|
+
if (RELATIVE_FUTURE_BEHAVIOR_LANGUAGE.test(value)) return true;
|
|
957
|
+
if (currentRound === void 0) return false;
|
|
958
|
+
for (const match of value.matchAll(ABSOLUTE_DAY_BEHAVIOR_LANGUAGE)) {
|
|
959
|
+
const referencedRound = chineseNumber(match[1]);
|
|
960
|
+
if (referencedRound !== void 0 && referencedRound > currentRound) return true;
|
|
961
|
+
}
|
|
962
|
+
return false;
|
|
963
|
+
}
|
|
851
964
|
function assertBehaviorIsObserved(proposal) {
|
|
852
965
|
const behavior = proposal.behavior ?? "";
|
|
853
966
|
const overlap = Math.max(
|
|
@@ -890,6 +1003,40 @@ function assertLocalOutcomeEvidence(outcomeCount, localOutcomeCount, observed) {
|
|
|
890
1003
|
throw new ProposalError("FINAL_RESULT_NOT_LOCAL", "Final victory or defeat is not a local effect");
|
|
891
1004
|
}
|
|
892
1005
|
}
|
|
1006
|
+
function assertActionTimeSemantics(proposal, window, anchor, knownFacts) {
|
|
1007
|
+
const actionTimeFields = [
|
|
1008
|
+
proposal.trigger,
|
|
1009
|
+
proposal.rule,
|
|
1010
|
+
proposal.boundary,
|
|
1011
|
+
proposal.alternativeAction
|
|
1012
|
+
].filter((value) => typeof value === "string");
|
|
1013
|
+
if (window.phase === "SEER_TURN" && anchor.availableAt.round === 1 && proposal.alternativeActionType === "SEER_CHECK") {
|
|
1014
|
+
const rationale = actionTimeFields.map(stripUnavailableDaytimeInformation).join("\u3002 ");
|
|
1015
|
+
if (FIRST_NIGHT_DAYTIME_INFORMATION.test(rationale)) {
|
|
1016
|
+
throw new ProposalError(
|
|
1017
|
+
"SEER_DAY_INFORMATION_UNAVAILABLE",
|
|
1018
|
+
"A first-night seer check cannot depend on later daytime behavior"
|
|
1019
|
+
);
|
|
1020
|
+
}
|
|
1021
|
+
}
|
|
1022
|
+
if (actionTimeFields.some((value) => dependsOnFutureBehavior(value, anchor.availableAt.round))) {
|
|
1023
|
+
throw new ProposalError(
|
|
1024
|
+
"FUTURE_BEHAVIOR_DEPENDENCY",
|
|
1025
|
+
"A proposal field cannot depend on behavior after the decision anchor"
|
|
1026
|
+
);
|
|
1027
|
+
}
|
|
1028
|
+
const actionTimeText = actionTimeFields.join("\u3002 ");
|
|
1029
|
+
for (const { seat, claim } of seatBehaviorClaims(actionTimeText)) {
|
|
1030
|
+
if (seat === window.actorSeat && isCurrentDecisionActorClaim(claim)) continue;
|
|
1031
|
+
const supported = [anchor, ...knownFacts].some((fact) => fact.actorSeat === seat && factSupportsBehaviorClaim(fact, claim));
|
|
1032
|
+
if (!supported) {
|
|
1033
|
+
throw new ProposalError(
|
|
1034
|
+
"UNKNOWN_SEAT_BEHAVIOR_DEPENDENCY",
|
|
1035
|
+
"A trigger or alternative action cannot depend on an unsupported seat behavior"
|
|
1036
|
+
);
|
|
1037
|
+
}
|
|
1038
|
+
}
|
|
1039
|
+
}
|
|
893
1040
|
function factVisibleToActor(visibility, window) {
|
|
894
1041
|
if (visibility === "PUBLIC") return true;
|
|
895
1042
|
if (visibility === "POSTGAME_ONLY") return false;
|
|
@@ -1074,6 +1221,7 @@ function parseAndValidateProposal(raw, envelope, evidence, activeProfile) {
|
|
|
1074
1221
|
proposal.behavior = anchor.summary;
|
|
1075
1222
|
const known = proposal.knownFactRefs ?? [];
|
|
1076
1223
|
const outcomes = proposal.outcomeFactRefs ?? [];
|
|
1224
|
+
const knownFacts = [];
|
|
1077
1225
|
unique(known, "DUPLICATE_KNOWN_FACT");
|
|
1078
1226
|
unique(outcomes, "DUPLICATE_OUTCOME_FACT");
|
|
1079
1227
|
for (const ref of known) {
|
|
@@ -1091,6 +1239,7 @@ function parseAndValidateProposal(raw, envelope, evidence, activeProfile) {
|
|
|
1091
1239
|
if (fact.availableAt.historyIndex >= anchor.availableAt.historyIndex) {
|
|
1092
1240
|
throw new ProposalError("KNOWN_FACT_TOO_LATE", `Known fact is not earlier than the action: ${ref}`);
|
|
1093
1241
|
}
|
|
1242
|
+
knownFacts.push(fact);
|
|
1094
1243
|
}
|
|
1095
1244
|
let localOutcomeCount = 0;
|
|
1096
1245
|
for (const ref of outcomes) {
|
|
@@ -1103,6 +1252,7 @@ function parseAndValidateProposal(raw, envelope, evidence, activeProfile) {
|
|
|
1103
1252
|
localOutcomeCount++;
|
|
1104
1253
|
}
|
|
1105
1254
|
}
|
|
1255
|
+
assertActionTimeSemantics(proposal, window, anchor, knownFacts);
|
|
1106
1256
|
assertLocalOutcomeEvidence(outcomes.length, localOutcomeCount, observed);
|
|
1107
1257
|
const allRefs = /* @__PURE__ */ new Set([...known, ...outcomes]);
|
|
1108
1258
|
if (allRefs.size !== known.length + outcomes.length) {
|
package/package.json
CHANGED