Datasets:
Create README.yaml
Browse files- README.yaml +87 -0
README.yaml
ADDED
|
@@ -0,0 +1,87 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
---
|
| 2 |
+
viewer_config:
|
| 3 |
+
custom_view_config:
|
| 4 |
+
- name: fen
|
| 5 |
+
type: text
|
| 6 |
+
column: fen
|
| 7 |
+
formatter: |
|
| 8 |
+
def formatter(row):
|
| 9 |
+
import struct
|
| 10 |
+
data = row['fen']
|
| 11 |
+
if not data or len(data) < 8:
|
| 12 |
+
return "Invalid FEN data"
|
| 13 |
+
|
| 14 |
+
# Piece mappings
|
| 15 |
+
nib_to_piece_map = {
|
| 16 |
+
0: 'K', 1: 'Q', 2: 'R', 3: 'B', 4: 'N', 5: 'P',
|
| 17 |
+
6: 'k', 7: 'q', 8: 'r', 9: 'b', 10: 'n', 11: 'p'
|
| 18 |
+
}
|
| 19 |
+
NIB_EMPTY = 12
|
| 20 |
+
|
| 21 |
+
# Read flags
|
| 22 |
+
flags = data[0]
|
| 23 |
+
is_crazyhouse = bool(flags & 4)
|
| 24 |
+
active_player = 'b' if (flags & 1) else 'w'
|
| 25 |
+
|
| 26 |
+
# Calculate metadata size and board end
|
| 27 |
+
meta_size = 6 + (13 if is_crazyhouse else 0)
|
| 28 |
+
board_end = len(data) - meta_size
|
| 29 |
+
|
| 30 |
+
# Unpack board nibbles
|
| 31 |
+
nibs = []
|
| 32 |
+
for i in range(1, board_end):
|
| 33 |
+
nibs.append((data[i] >> 4) & 0xF)
|
| 34 |
+
nibs.append(data[i] & 0xF)
|
| 35 |
+
|
| 36 |
+
# Decode board
|
| 37 |
+
board_chars = []
|
| 38 |
+
sq = 0
|
| 39 |
+
i = 0
|
| 40 |
+
while i < len(nibs) and sq < 64:
|
| 41 |
+
if nibs[i] == NIB_EMPTY and i + 1 < len(nibs):
|
| 42 |
+
cnt = nibs[i + 1] + 1
|
| 43 |
+
board_chars.extend([' '] * cnt)
|
| 44 |
+
sq += cnt
|
| 45 |
+
i += 2
|
| 46 |
+
elif nibs[i] < 12:
|
| 47 |
+
board_chars.append(nib_to_piece_map[nibs[i]])
|
| 48 |
+
sq += 1
|
| 49 |
+
i += 1
|
| 50 |
+
elif nibs[i] == 0xF:
|
| 51 |
+
break
|
| 52 |
+
else:
|
| 53 |
+
i += 1
|
| 54 |
+
|
| 55 |
+
# Convert board to FEN notation (8 ranks)
|
| 56 |
+
fen_ranks = []
|
| 57 |
+
for rank in range(8):
|
| 58 |
+
rank_str = ""
|
| 59 |
+
empty_count = 0
|
| 60 |
+
for file in range(8):
|
| 61 |
+
idx = rank * 8 + file
|
| 62 |
+
if idx < len(board_chars):
|
| 63 |
+
piece = board_chars[idx]
|
| 64 |
+
if piece == ' ':
|
| 65 |
+
empty_count += 1
|
| 66 |
+
else:
|
| 67 |
+
if empty_count > 0:
|
| 68 |
+
rank_str += str(empty_count)
|
| 69 |
+
empty_count = 0
|
| 70 |
+
rank_str += piece
|
| 71 |
+
if empty_count > 0:
|
| 72 |
+
rank_str += str(empty_count)
|
| 73 |
+
fen_ranks.append(rank_str)
|
| 74 |
+
|
| 75 |
+
board_fen = '/'.join(fen_ranks)
|
| 76 |
+
|
| 77 |
+
# Read metadata
|
| 78 |
+
m = board_end
|
| 79 |
+
castlings_bits = (data[m], data[m + 1])
|
| 80 |
+
enpassant = data[m + 2]
|
| 81 |
+
halfmove = data[m + 3]
|
| 82 |
+
fullmove = data[m + 4] | (data[m + 5] << 8)
|
| 83 |
+
|
| 84 |
+
# Build FEN string (simplified, without full castling/enpassant parsing)
|
| 85 |
+
fen_str = f"{board_fen} {active_player} - - {halfmove} {fullmove}"
|
| 86 |
+
|
| 87 |
+
return fen_str
|