Skip to main content

Module pattern_table

Module pattern_table 

Source
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.
WindowThreat
Threat tier produced when mine (hypothetically) plays at the anchor cell of a single direction’s window. Mirrors vct.rs::LineThreat but 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 LineThreat produced when mine plays at an empty anchor cell, given the current mapped pattern ID for the surrounding 11-cell window. Top-K canonical IDs are precomputed; the RARE bucket returns WindowThreat::None and callers must fall back to read_window + classify_window_anchor_mine for 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§

LineWindow
11-cell line window. cell 값:
PatternId
Pattern ID type. canonical pattern 수가 65k 초과 (실측 ~수십만)이라 u16으로는 부족. u32 사용.