Expand description
Pattern4 mini — 11-cell line window를 lossless ID로 압축하는 테이블.
Rapfi식 Pattern4 인프라의 mini 버전. 한 cell의 한 방향에서 ±5 = 11칸의 시퀀스를 정규화해 unique pattern ID를 부여하고, 보드 안에 (cell, dir) 별 pattern_id 상태를 유지하면 매 수마다 영향받는 라인의 ID만 lookup으로 갱신할 수 있어 region recompute가 사라진다.
이 모듈은 그 인프라의 첫 단계: 패턴 표현, canonicalize, packed encoding, 그리고 모든 가능 패턴의 enumeration. NNUE 통합과 보드 상태 유지는 후속 단계에서 추가된다.
Enums§
- Cell
- Cell 값 enum (가독성용). u8와 1:1.
- Window
Threat - Threat tier produced when
mine(hypothetically) plays at the anchor cell of a single direction’s window. Mirrorsvct.rs::LineThreatbut is kept separate here to avoid a cross-module type dependency; callers translate between the two enums.
Constants§
- PATTERN_
NUM_ IDS - PATTERN_
RARE_ ID - PATTERN_
TOP_ K - 우리 NNUE에서 실제로 추적하는 mapped pattern ID 수. Top 16384 = 학습 데이터에서 99.24% 커버 + rare bucket 1개 = 16385.
Functions§
- canonicalize
- 좌우 reflection 정규화. canonical = min(w, reverse(w)) packed.
- empty_
pattern_ mapped_ id - 모든 빈 셀의 LineWindow
[0; 11]의 mapped ID. 보드 안쪽 빈 cell의 초기값 — 우리 freq 측정에서 11.94% 빈도 1위라 mapped id 0으로 매핑됨. Board::new() 의 default fill 에 사용. - enumerate_
patterns - 모든 가능한 11-cell pattern을 enumerate해 canonical packed → ID로 매핑.
is_realizable통과 + canonical form만 unique ID. - is_
realizable - 패턴이 보드에서 실제 등장 가능한가? 규칙: boundary는 양 끝에서만 연속으로 나타날 수 있다. 보드 안쪽에서는 boundary가 등장하지 않는다.
- lookup_
mapped_ id - raw packed 11-cell window → mapped pattern ID (0..16384, 16384=rare). Caller가 read_window로 만든 packed를 그대로 넘기면 O(1) lookup.
- pack_
window - 11-cell window를 22-bit u32로 packed. 각 cell 2 bit. 인덱스 0이 high bits, 인덱스 10이 low bits.
- pattern_
threat_ after_ my_ play - O(1) lookup of the
LineThreatproduced whenmineplays at an empty anchor cell, given the currentmapped pattern IDfor the surrounding 11-cell window. Top-K canonical IDs are precomputed; theRAREbucket returnsWindowThreat::Noneand callers must fall back toread_window+classify_window_anchor_minefor those. - read_
window - 보드 상태(stones bitboard 두 개)에서 (row, col, dir) 의 11-cell window를 읽어내는 helper. mine/opp 관점에 따라 cell 값 결정.
- swap_
mapped_ id - mine/opp swap된 perspective의 mapped pattern ID.
- unpack_
window - packed u32에서 LineWindow 복원. 인덱스 0이 high bits, 인덱스 10이 low bits — pack_window의 역.
Type Aliases§
- Line
Window - 11-cell line window. cell 값:
- Pattern
Id - Pattern ID type. canonical pattern 수가 65k 초과 (실측 ~수십만)이라 u16으로는 부족. u32 사용.