Skip to content

Instantly share code, notes, and snippets.

"""
Determine if a given chess position is "checkmate" or not.
Input is a FEN string, a commonly used way to 'serialize' the state of a chess game at a certain move,
it looks like this:
rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w KQkq - 0 1
Explanation of algorithm:
functions {
// For sum to 0. From here: https://discourse.mc-stan.org/t/test-soft-vs-hard-sum-to-zero-constrain-choosing-the-right-prior-for-soft-constrain/3884/31
vector Q_sum_to_zero_QR(int N) {
vector [2*N] Q_r;
for(i in 1:N) {
Q_r[i] = -sqrt((N-i)/(N-i+1.0));
Q_r[i+N] = inv_sqrt((N-i) * (N-i+1));
}