News for hackers. Stuff that matters.
Re:How to Store a Chess Game in 26 Bytes Using Bit-Level Mag... by TylerE on Friday September 15, 2023 @12:59PM (#37526049)
I suspect it would be hard to beat pgn run through a good compression algorithmn.

Or similarly essentially a binary version of pgn. Probably the optimalist of optimal is a binary specifying the starting square (6 bits), and then a minimal-width for the specified piece number that indexes against a standard set of move offsets.

So, for instance, a knight has (ignoring potential exposed checks, board boundaries, etc, 8 possible moves, so to fully encode a knight move you need 6+3=9 bits. 8 also works for pawns (and annoying due to e.p. 4 doesn't). Bishops, queens, and rooks would need a 4/5 bit field. Encode castling as starting from the rook as they have 'spare' moves in their bit set, and kings don't. Encode the end state at the begining.

This is going to use 2 bits for the end state, and then either 9, 10, or 11 bits per move.

Re:How to Store a Chess Game in 26 Bytes Using Bit-Level Mag... by thechao on Friday September 15, 2023 @01:23PM (#37526368)
You only need 5b to encode the piece to move: you know whose turn it is. Also, as the game progresses, you can reindex to reduce the number of bits to define which piece is moving.
Re:How to Store a Chess Game in 26 Bytes Using Bit-Level Mag... by thaumasiotes on Friday September 15, 2023 @10:47PM (#37531565)
> You only need 5b to encode the piece to move: you know whose turn it is.

If you want to encode the piece (rather than the square), and you're comfortable not counting "whose turn is it?" against the information requirement, you don't need 5 bits. Each player has only 16 pieces, so you can give them all four-bit names.

You won't know what kind of piece they are, though.

Re:How to Store a Chess Game in 26 Bytes Using Bit-Level Mag... by robertlagrant on Friday September 15, 2023 @03:29PM (#37528051)
> I suspect it would be hard to beat pgn run through a good compression algorithmn.

I once[0] tried to spread this message :)

[0] https://stackoverflow.com/a/1831841/61938

Re:How to Store a Chess Game in 26 Bytes Using Bit-Level Mag... by TylerE on Friday September 15, 2023 @04:24PM (#37528678)
A standard archiver like 7zip is probably a loss due to the metadata/format headers etc. When your plain text is only a few hundred bytes to start with...

I suspect the winner would be something like an LZMA derivative with a fixed dictionary. I doubt not using an adaptive encoder would be a big loss as PGN (exlcuding the metadata) is quite far from random bytes.

Re:How to Store a Chess Game in 26 Bytes Using Bit-Level Mag... by thaumasiotes on Friday September 15, 2023 @10:45PM (#37531552)
> Bishops, queens, and rooks would need a 4/5 bit field.

Ignoring board boundaries, a queen has 56 possible moves requiring 6 bits. At any given position on the board, most of those aren't possible because the board is too small, but cramming that into 5 bits will make the encoding much more annoying.

Same thing goes for rooks; ignoring board boundaries there are 28 possible moves, but including the board boundaries there are 14. You can fit that in four bits, but you pick up some context sensitivity.

> 8 also works for pawns (and annoying due to e.p. 4 doesn't)

I don't see the problem? A pawn can move forward two spaces, it can move forward one space, it can capture diagonally to the left, or it can capture diagonally to the right. Those are the only possibilities and they fit into two bits.

En passant enables a pawn to capture a piece that isn't located on the space being captured, and you need to know the state of the board on the previous turn (or, equivalently, what the previous move was) in order to know whether en passant is a legal move... but to encode that it happened, you don't need anything you didn't already have.

Re:How to Store a Chess Game in 26 Bytes Using Bit-Level Mag... by TylerE on Saturday September 16, 2023 @12:15AM (#37531999)
Hours forgetting pawns capturing en passant.
Re:How to Store a Chess Game in 26 Bytes Using Bit-Level Mag... by thaumasiotes on Saturday September 16, 2023 @12:56AM (#37532156)
What?