方法说明详见report.pdf。以下是一个自动转换出来的版本,并不是很可靠。报告本身是用typst撰写。
(^1) /*
(^2) * 0000ABCXDEF
(^3) */
(^1) /*
(^2) * 0000ABCXDEF
(^3) * 000ABCXDEF
(^4) * 00ABCXDEF
(^5) * 0ABCXDEF
(^6) */
(^1) bool rowWin(const short row) {
(^2) const short row1 = row & (row << 1 );
(^3) const short row2 = row1 & (row1 << 2 );
(^4) return row2;
(^5) }
²https://github.com/Guangxuan-Xiao/Connect4/blob/master/report.md
(^1) 001X
(^2) 02111X
(^1) int hot(const int row) {
(^2) return row & (row << 1 ) & (row << 2 );
(^3) }
(^1) 00001110
(^2) 00011100
(^3) 00111000
(^4) &------&
(^5) 00001000
(^6) --hot---
(^7) 000X100X
(^1) constexpr int mask = 0 b10001;
(^2) const int off = (p - 1 ) * 16 ;
(^3) return charge_r[x] & (mask << (y + off) >> 1 );
(^1) /*
(^2) *
(^3) *
(^4) *
(^5) *
(^6) *
(^7) */
(^1) int jump(const int row) {
(^2) const int match = row & (row << 3 );
(^3) const int A = match & (row << 2 );
(^4) const int B = match & (row << 1 );
(^5) return (A >> 1 ) | (B >> 2 );
(^6) }
(^1) bool mustWin(const int x, const int y, const char p) const {
(^2) constexpr int mask = 0 b10001;
(^3) const int off = (p - 1 ) * 16 ;
(^4) return charge_r[x] & (mask << (y + off) >> 1 )
(^5) || charge_c[y] & (mask << (x + off) >> 1 )
(^6) || charge_sl[x + y] & (mask << (y + off) >> 1 )
(^7) || charge_sr[x - y + 11 ] & (mask << (y + off) >> 1 )
(^8) || jump_r[x] & ( 1 << (y + off))
(^9) || jump_c[y] & ( 1 << (x + off))
(^10) || jump_sl[x + y] & ( 1 << (y + off))
(^11) || jump_sr[x - y + 11 ] & ( 1 << (y + off));
(^12) }
(^1) void update(const int x, const int y, const char p) {
(^2) set(x, y, p);
(^3) charge_r[x] = hot(rows[x]);
(^4) charge_c[y] = hot(cols[y]);
(^5) charge_sl[x + y] = hot(slanted_left[x + y]);
(^6) charge_sr[x - y + 11 ] = hot(slanted_right[x - y + 11 ]);
(^7) jump_r[x] = jump(rows[x]);
(^8) jump_c[y] = jump(cols[y]);
(^9) jump_sl[x + y] = jump(slanted_left[x + y]);
(^10) jump_sr[x - y + 11 ] = jump(slanted_right[x - y + 11 ]);
(^11) }
𝑅𝐴−𝑅𝐵
400