Readit News logoReadit News
antsou commented on Observability's past, present, and future   blog.sherwoodcallaway.com... · Posted by u/shcallaway
antsou · a month ago
Observability and APM are way, way older than depicted in this simplistic post!
antsou commented on Portugal just ran on 100% renewables for six days in a row   canarymedia.com/articles/... · Posted by u/Anon84
antsou · 2 years ago
It really doesn't tell what really happened: -This was only due to hydro production... -The amount of rain that fell was consistent along those days, which is definitely not usual. -The energy produced was mainly exported to Spain, but at ZERO or even NEGATIVE euros.

Does this help? Doesn't seem to me! And besides having to pay full price to the renewables producers (while exporting the same energy at ZERO), which amounts to a significant energy deficit, they are talking about even more H2 or whatever schemes??? This is the reason why Portugal has had one of the biggest rises of electricity prices in Europe over the last 15 years...

antsou commented on How to store a chess position in 26 bytes using bit-level magic (2022)   ezzeriesa.com/index/Writi... · Posted by u/kurinikku
timerol · 2 years ago
I played with this in the past (https://news.ycombinator.com/item?id=34461113#34462521), but am willing to take another stab at it.

Store one 64 bit bitboard - a set bit means that a piece is present at that place. An unset bit means that no piece is after that position. After the bitboard, store a list of 32 4 bit integers, where the order of the pieces in the list corresponds to the order of the bits set. If there are less than 16 bits set in the bitboard, ignore the last items in the list.

  0000 - 0x0 - black pawn 
  0001 - 0x1 - black pawn (can be en-passant'd)
  0010 - 0x2 - black knight
  0011 - 0x3 - black bishop
  0100 - 0x4 - black rook (castling unavailable)
  0101 - 0x5 - black rook (castling available)
  0110 - 0x6 - black king
  0111 - 0x7 - black queen
  1000 - 0x8 - white pawn 
  1001 - 0x9 - white pawn (can be en-passant'd)
  1010 - 0xA - white knight
  1011 - 0xB - white bishop
  1100 - 0xC - white rook (castling unavailable)
  1101 - 0xD - white rook (castling available)
  1110 - 0xE - white king
  1111 - 0xF - white queen
I think that covers all possibilities to store a chess position in 64 + 32 * 4 = 192 bits, or 24 bytes exactly.

The starting position would be represented with a bitboard of 0xFFFF00000000FFFF, with a list of [0xD, 0xA, 0xB, 0xF, 0xE, 0xB, 0xA, 0xD, 0x8, 0x8, 0x8, 0x8, 0x8, 0x8, 0x8, 0x8, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x5, 0x2, 0x3, 0x7, 0x6, 0x3, 0x2, 0x5], using the same position-to-number scheme in the blog post

Edit: 32 pieces, not 16. Thanks to the peanut gallery for catching it quickly

Edit2: To store which player is next: do nothing for white. For black, if there are 32 pieces, flip the bitboard upside down. (To check if it's black's turn, verify that black pawns are "below" white pawns, which is illegal before captures are made.) If there are less than 32 pieces and it's black's turn, invert the bitboard. (To check, count the number of set bits.) This is entirely taken from https://news.ycombinator.com/item?id=37526484

antsou · 2 years ago
I believe you can also do it in a slightly different way. For each square on the board:

0 - encodes no piece in the square; at least 32 of them, so 32 bits (4 bytes)

1xxxx - xxxx being your encoding: encodes remaining pieces; at most 32 of them, so max 32 x 5 bits (20 bytes)

u/antsou

KarmaCake day5September 16, 2023View Original