File size: 1,299 Bytes
631a7d3
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
import { TIANJI_DICTIONARY } from './tianji-dictionary';
import { BONUS_RULES, PENALTY_RULES, CONFLICT_RESOLUTION, ScoreRule } from './scoring-tables';

export interface AdviceItem {
  rule: string;
  content: string;
}

export interface ConflictRuleDef {
  priority: number;
  name: string;
  condition: (hasLu: boolean, hasJi: boolean, hasGoodPattern?: boolean, hasBadInteraction?: boolean) => boolean;
  action: string;
}

export interface IKnowledgeSource {
  getPatternAdvices(): Record<string, AdviceItem>;
  getSihuaAdvices(): Record<string, AdviceItem>;
  getStarsAdvices(): Record<string, AdviceItem>;
  getGeneralAdvices(): Record<string, AdviceItem>;
  getBonusRules(): Record<string, ScoreRule>;
  getPenaltyRules(): Record<string, ScoreRule>;
  getConflictRules(): ConflictRuleDef[];
}

export class LocalKnowledgeSource implements IKnowledgeSource {
  getPatternAdvices() { return TIANJI_DICTIONARY.patterns; }
  getSihuaAdvices() { return TIANJI_DICTIONARY.sihua; }
  getStarsAdvices() { return TIANJI_DICTIONARY.stars; }
  getGeneralAdvices() { return TIANJI_DICTIONARY.general; }
  getBonusRules() { return BONUS_RULES; }
  getPenaltyRules() { return PENALTY_RULES; }
  getConflictRules() { return CONFLICT_RESOLUTION; }
}

export const knowledgeSource = new LocalKnowledgeSource();