当前位置: 首页 > news >正文

皮卡鱼源码导读

运行pikafish后输入d命令:

Screenshot_20251009_190900

rook:车; knight:马; bishop:象; advisor:士; king:将; cannon:炮; pawn:卒。红棋用大写字母。红方叫白方。

棋盘可以看作9x10的交叉点,也可看作方格(square).

对应代码是position.cpp里的std::ostream& operator<<(std::ostream& os, const Position& pos),不是bitboard.cpp里的pretty,后者没人调用。

先看types.h。enum Square : int8_t { SQ_A0 ... SQ_I9, SQUARE_NB   = 90 } NB是number的意思:…的个数。

enum Direction : int8_t { EAST = 1, NORTH = 9, SOUTH = -NORTH } 上北下南,左西右东。

// Initializes the position object with the given FEN string.
Position& Position::set(const string& fenStr, StateInfo* si) {unsigned char      token;size_t             idx;Square             sq = SQ_A9;std::istringstream ss(fenStr);while ((ss >> token) && !isspace(token)) {if (isdigit(token)) sq += (token - '0') * EAST; // Advance the given number of fileselse if (token == '/')  sq += 2 * SOUTH;else if ((idx = PieceToChar.find(token)) != string::npos) put_piece(Piece(idx), sq);}
}

过度花哨了。* 1怎么说?stringstream包string包char*?

Piece是棋子。File是列,rank是行,和row首字母都是r. rank有军衔的意思,可联想兵到底线升变。

constexpr std::string_view PieceToChar(" RACPNBK racpnbk");

string_view是C++17引入的轻量级字符串视图类,定义于<string_view>中‌。它提供对字符串数据的只读访问,仅存储指针和长度信息。

① 这个函数没必要优化。

② 最快的是像ctype.h那样放在T [256]的表里,T是char好还是int好?还是自己操作位?

Position::put_piece(Piece pc, Square s) {
  board[s] = pc;
  byTypeBB[ALL_PIECES] |= byTypeBB[type_of(pc)] |= s;
  byColorBB[color_of(pc)] |= s;
  pieceCount[pc]++;
}

enum Piece std::int8_t {...}
Piece board[SQUARE_NB];

typedef __uint128_t Bitboard;
// 实际为using Bitboard = ...,处理Linux和Windows不同的情况。Linux下啥头文件都不用包含。

enum PieceType std::int8_t { ROOK, ..., PIECE_TYPE_NB = 8 }
Bitboard byTypeBB[PIECE_TYPE_NB];

enum Color : int8_t { WHITE, BLACK, COLOR_NB = 2 };
Bitboard byColorBB[COLOR_NB];

每方有7种、16个棋子。补充type_of和color_of:

constexpr PieceType type_of(Piece pc) { return PieceType(pc & 7); }constexpr Color color_of(Piece pc) {assert(pc != NO_PIECE);return Color(pc >> 3);
}

与GNU chess相比:

① 虽然我都看不懂,但感觉皮卡鱼赏心悦目,可读性强。在misc.cpp里作者提到了"Our fancy logging facility"; 也许极个别别的地方也有点fancy.

② 搜索部分比较简明。NNUE的online部分1000来行。

③ 速度极快的xxHash还有汇编写的Huffman解码可以先不看。Meta有基础研究科学家,腾讯呢?

④ 皮卡鱼(基于Stockfish)棋力强。

⑤ 带数据。43M的pikafish.nnue是压缩后,7z一点都再压缩不动。Top CPU Contributors里有个Contributors for training data generation with >10,000,000 positions generated, as of 2023-02-16.  不是说拿1千万个局面训练的,是1千万是上榜条件(157人上榜),榜首kaka是452524769438/1e8 > 4525。Contributors to Fishtest with >10,000 CPU hours, as of 2023-07-31. 榜首浮生若梦5029923 (574.2年?)。也许43M的是精简版。

晚上睡不着?可拿平板装QuickEdit看源码,也可听无聊的英语,TTSMAKER可以转AAC,比如:

The year 1066 stands as a pivotal moment in British history, marking the Norman Conquest and the Battle of Hastings. Under the leadership of William the Conqueror, the Normans defeated the Anglo-Saxon King Harold II, reshaping England's political, cultural, and linguistic landscape. This event not only established Norman rule but also introduced feudalism to England, leaving a lasting legacy in its legal systems, architecture, and language. The Battle of Hastings thus remains a defining chapter in the nation's medieval history.
((⏱️=2000))

 

http://www.hskmm.com/?act=detail&tid=27553

相关文章:

  • 高斯消元学习笔记
  • newDay07
  • 10月9日
  • 从开放重定向到XSS:漏洞升级实战
  • 余弦日记
  • 【题解】P11459 [USACO24DEC] Its Mooin Time P
  • 创建一个springboot项目,mybatis连接嵌入式数据库H2,实现增删改查功能
  • 基于众包的产品质量比较与推荐算法研究
  • 10/9
  • 2025.10.9
  • 线程池总结
  • 合并两个有序链表
  • 深入解析:一款相机是只有桶形畸变 和 枕形畸变的一种,还是两个都有?
  • 数据结构-链表
  • 重组抗体技术:从原理到应用,解锁高效可控的新一代抗体研发
  • P13690 [CEOI 2025] boardgames
  • CSS
  • 关于jinja2的ssti模版注入的学习+过滤
  • WPF Epplus export 10M+ items in excel with multiple sheets batch by batch
  • [EGOI 2023] Guessing Game
  • CF2152G Query Jungle
  • [ROI 2018] Addition without carry
  • [THUPC 2025 决赛] Im Here
  • 解码Linux基础命令
  • 基于 C++ 的高雷诺数湍流直接数值模拟求解器设计与性能优化 - 实践
  • 由等概率(a,b)生成等概率(c,d)
  • AI/LLM应用安全与合规产品(AI安全网关|AI安全围栏|AI应用防火墙) 2025最新推荐
  • 10.8 CSP-S模拟27 改题记录
  • 《可复制的领导力》
  • 经营分析会 - 智慧园区