# Piece-Square Tables

Piece-Square Tables(PST, PSQT)は、
「どの駒がどの升にいると良いか」を表形式で持つ評価手法である。
実装が簡単で高速なため、手作り評価の入門として非常に重要である。

## 概要

駒種ごとに、
盤上の各マスへ点数を割り当てる。

たとえば、

- 桂馬は前へ進んだ方が良い
- 飛車は開けた筋で強い
- 王は中盤では囲いの中、終盤では中央寄りがよい

といった知識をテーブル化する。

## 実装例

```cpp
int PST[PIECE_TYPE_NB][SQ_NB];

int evaluatePieceSquareTables(const Position& pos, Color us) {
    int score = 0;

    for (Piece pc : pos.pieces(us)) {
        score += PST[pc.type()][pc.square()];
    }

    for (Piece pc : pos.pieces(~us)) {
        score -= PST[pc.type()][mirror(pc.square())];
    }

    return score;
}
```

探索中に make/unmake で差分更新しやすいのも大きな利点である。

## 将棋AIでの位置づけ

将棋では駒の向きや成り、持ち駒があるので、
チェスより単純ではない。

それでも、

- 駒種ごとの好位置
- 玉形ごとの配置傾向
- 終盤の王の中央化

などを素早く入れられる。

また、
[NNUE](/shogi/shogiwiki/search/nnue/) の入力として知られる
king-piece-square table も、
広い意味では PST の発展形と見なせる。

## 複数テーブル

実戦的には、

- 中盤用テーブル
- 終盤用テーブル

を用意して混ぜる tapered evaluation がよく使われる。

将棋でも、
玉の位置や飛車角の働きは局面の段階で意味が大きく変わるため、
複数テーブルの方が自然である。

## 注意点

- テーブルだけでは駒同士の関係を十分に表せない
- 打ち駒や成駒の価値変化は別項目と組み合わせる必要がある
- うまく設計しないと [Mobility](/shogi/shogiwiki/search/mobility/) や [King Safety](/shogi/shogiwiki/search/king-safety/) と二重計上しやすい

## 関連項目

- [評価関数](/shogi/shogiwiki/search/evaluation-function/)
- [Mobility](/shogi/shogiwiki/search/mobility/)
- [King Safety](/shogi/shogiwiki/search/king-safety/)
- [NNUE](/shogi/shogiwiki/search/nnue/)

## 参考にしたホームページ

- [Chessprogramming Wiki: Piece Square Tables](https://www.chessprogramming.org/Piece-Square_Tables)
- [home.hccnet.nl: Pcsqr.Html](https://home.hccnet.nl/h.g.muller/pcsqr.html)
- [rustic-chess.org: Psqt.Html](https://rustic-chess.org/evaluation/psqt.html)
- [int0x80.ca: 2 HCE](https://int0x80.ca/posts/chess-engines-nnue/2-hce)