commit 8fe4020ffee165154494f0214a9985ee34c2a297 Author: Jack Halford Date: Wed Apr 16 18:09:22 2025 +0200 first commit, chess square colors diff --git a/chess.apkg b/chess.apkg new file mode 100644 index 0000000..fc6f71d Binary files /dev/null and b/chess.apkg differ diff --git a/generate_deck.py b/generate_deck.py new file mode 100755 index 0000000..ef130b1 --- /dev/null +++ b/generate_deck.py @@ -0,0 +1,79 @@ +#!/usr/bin/env -S uv run --script +# /// script +# requires-python = ">=3.13" +# dependencies = [ +# "genanki", +# "python-chess", +# ] +# /// + +import random +import genanki +import chess +import chess.svg + +deck = genanki.Deck( + 2059400110, + 'Blind Chess' +) + +model= genanki.Model( + 614661503, + 'Simple Model', + fields=[ + {'name': 'Slug'}, + {'name': 'Square'}, + {'name': 'Piece'}, + {'name': 'Question'}, + {'name': 'Answer'}, + {'name': 'Board'}, + ], + templates=[ + { + 'name': 'Card 1', + 'qfmt': '{{Question}} {{Square}}', + 'afmt': '{{FrontSide}}
{{Answer}}
{{Board}}
', + }, + ] +) + +class ChessNote(genanki.Note): + @property + def guid(self): + # slug-square-piece + return genanki.guid_for(self.fields[0], self.fields[1], self.fields[2]) + +board = chess.BaseBoard() +board.clear_board() + +notes = [] +for sq_name in chess.SQUARE_NAMES: + # square colors + sq_id = chess.parse_square(sq_name) + sq_file = chess.square_file(sq_id) + sq_rank = chess.square_rank(sq_id) + sq_color = 'black' if (sq_file+sq_rank) % 2 == 0 else 'white' + board_svg = chess.svg.board( + board, + squares=chess.SquareSet([sq_id]), + ) + note = ChessNote( + model=model, + fields=[ + 'color', + sq_name, + '', + 'What is the color of square', + sq_color, + board_svg, + ], + ) + notes.append(note) + +# randomize the order of the notes +random.shuffle(notes) +for note in notes: + deck.add_note(note) + +genanki.Package(deck).write_to_file('chess.apkg') +print('Deck generated: chess.apkg')