Skip to content

Instantly share code, notes, and snippets.

View niklasf's full-sized avatar

Niklas Fiekas niklasf

View GitHub Profile
@niklasf
niklasf / huffman-pgn.py
Created January 3, 2016 15:58
Compress and decompress chess games using huffman encoding
import bitarray
import chess
import chess.pgn
import sys
import pickle
import textwrap
def base_counts():
counts = {}
--- a/masters.pgn 2016-02-08 16:00:16.000000000 +0100
+++ b/masters.pgn 2016-02-16 16:34:55.645514341 +0100
@@ -39522220,21 +39522220,21 @@
[WhiteElo "2591"]
[BlackElo "2327"]
[PlyCount "93"]
[EventDate "2010.11.13"]
[EventType "swiss"]
[EventRounds "9"]
[EventCountry "CHN"]
#!/usr/bin/python3
# -*- coding: utf-8 -*-
import json
import collections
import chess
import chess.pgn
db = {}
This file has been truncated, but you can view the full file.
{"n": "King's Indian: S\u00e4misch, Orthodox, 7.Nge2 c6", "f": "rnbq1rk1/pp3pbp/2pp1np1/4p3/2PPP3/2N1BP2/PP2N1PP/R2QKB1R w KQ", "c": "E86a", "m": "d2d4 g8f6 c2c4 g7g6 b1c3 f8g7 e2e4 d7d6 f2f3 e8g8 c1e3 e7e5 g1e2 c7c6"}
{"n": "Sicilian: Najdorf, Polugaevsky, 10.Qe2 Nfd7 11.O-O-O Bb7", "f": "rn2kb1r/1bqn1ppp/p3p3/1p2P1B1/3N4/2N5/PPP1Q1PP/2KR1B1R w kq", "c": "B96v", "m": "e2e4 c7c5 g1f3 d7d6 d2d4 c5d4 f3d4 g8f6 b1c3 a7a6 c1g5 e7e6 f2f4 b7b5 e4e5 d6e5 f4e5 d8c7 d1e2 f6d7 e1c1 c8b7"}
{"n": "Queen's Indian: Pomar, Polugaevsky Variation", "f": "rn1q1rk1/pbppbppp/1p3n2/3p4/2P4N/6P1/PP2PPBP/RNBQ1RK1 b -", "c": "E17w", "m": "d2d4 g8f6 c2c4 e7e6 g1f3 b7b6 g2g3 c8b7 f1g2 f8e7 e1g1 e8g8 d4d5 e6d5 f3h4"}
{"n": "Sicilian: Taimanov, Szen, Hedgehog Variation", "f": "r1bq1rk1/4bppp/ppnppn2/8/2P1P3/N1N5/PP2BPPP/R1BQ1RK1 w -", "c": "B44w", "m": "e2e4 c7c5 g1f3 e7e6 d2d4 c5d4 f3d4 b8c6 d4b5 d7d6 c2c4 g8f6 b1c3 a7a6 b5a3 f8e7 f1e2 e8g8 e1g1 b7b6"}
{"n": "QGD: Semi-Tarrasch, 7.Bd3 Main Line, 10.Re1 Bf6 11.Be4 Nce7", "f": "r1bq1rk1/
@niklasf
niklasf / cpuid.py
Last active June 22, 2022 09:53
Detect support for popcnt and pext instructions on amd64, x86-64, x86 and i686 CPUs
import ctypes
import contextlib
import os
import platform
def detect_cpu_capabilities():
# Detects support for popcnt and pext instructions
modern, bmi2 = False, False
@niklasf
niklasf / encode-movetimes.py
Last active November 21, 2016 16:51
Benchmarking various methods to encode 100 000 movetimes from FICS
from __future__ import division
from __future__ import print_function
import heapq
import math
import itertools
from collections import defaultdict
#from scipy.special import erf, erfinv
@niklasf
niklasf / atomic.md5sums
Last active November 16, 2016 15:29
MD5SUMS of 5 piece atomic syzygy tables
5f09f78f986d440d5fda3cd28b335eb3 KBBBvK.atbw
30405c5366213d43f4acf68b10c5ca58 KBBBvK.atbz
8314a33d3042c8ab76ca365d492c7fd2 KBBNvK.atbw
996aa9ef24cadf6342e15212b8ca91a1 KBBNvK.atbz
2087b9823af4ca34e0f1692b917650e5 KBBPvK.atbw
19b934721c02787d50b471ef44e99bd7 KBBPvK.atbz
0b12a60dcd347e5db4dcb3a19a351b1f KBBvK.atbw
2cdbcd87dbd5a2e069b121d08eb68138 KBBvK.atbz
6d57f8073f620c5a4c0e33ecda89e79a KBBvKB.atbw
a382621f6953995d3948b5f45d5cf7bb KBBvKB.atbz
@niklasf
niklasf / 3-4-5.atbw.md5
Created November 21, 2016 17:01
Atomic syzygy tablebase stats
5f09f78f986d440d5fda3cd28b335eb3 KBBBvK.atbw
8314a33d3042c8ab76ca365d492c7fd2 KBBNvK.atbw
2087b9823af4ca34e0f1692b917650e5 KBBPvK.atbw
0b12a60dcd347e5db4dcb3a19a351b1f KBBvK.atbw
6d57f8073f620c5a4c0e33ecda89e79a KBBvKB.atbw
03dfac996c8ad3bb0243b6cab20d22db KBBvKN.atbw
fea01a36c7246c01ff7dee676478f69f KBBvKP.atbw
df59dd79ecd5e81667a8d0df9279ad5d KBBvKQ.atbw
69e712795f8131d814fe9c5207d01423 KBBvKR.atbw
3ec95fde73d9142b220c7b599a7bc569 KBNNvK.atbw
@niklasf
niklasf / pgn-codebook.py
Last active March 28, 2023 14:26
Experiment with PGN compression. Usage: python pgn-codebook.py corpus.pgn
import chess.pgn
import huffman
import sys
# https://github.com/flok99/feeks/blob/master/psq.py
PSQT = {
chess.PAWN: [
0, 0, 0, 0, 0, 0, 0, 0,
50, 50, 50, 50, 50, 50, 50, 50,
@niklasf
niklasf / tbdep.py
Created January 26, 2018 15:30
Create a Makefile for Syzygy tabebase generation
import sys
import chess.syzygy
import itertools
PCHR = chess.syzygy.PCHR
NORMAL = set(chess.syzygy.filenames())
def swap(egname):
w, b = egname.split("v")