Compare commits
1 commit
| Author | SHA1 | Date | |
|---|---|---|---|
| 3f9484a1a7 |
4 changed files with 17 additions and 30 deletions
18
.github/workflows/release.yaml
vendored
18
.github/workflows/release.yaml
vendored
|
|
@ -1,18 +0,0 @@
|
||||||
on:
|
|
||||||
push:
|
|
||||||
branches: [main]
|
|
||||||
|
|
||||||
jobs:
|
|
||||||
release:
|
|
||||||
name: release
|
|
||||||
runs-on: ubuntu-latest
|
|
||||||
steps:
|
|
||||||
- uses: actions/checkout@v3
|
|
||||||
- run: curl -LsSf https://astral.sh/uv/install.sh | sh
|
|
||||||
- run: ./blind_chess.py
|
|
||||||
- env:
|
|
||||||
GITHUB_TOKEN: ${{ secrets.GH_TOKEN }}
|
|
||||||
run: |
|
|
||||||
date=$(date +%y-%m-%d)
|
|
||||||
gh release delete --yes $date || :
|
|
||||||
gh release create --notes "" $date blind_chess.apkg
|
|
||||||
1
.gitignore
vendored
1
.gitignore
vendored
|
|
@ -1 +0,0 @@
|
||||||
*.apkg
|
|
||||||
BIN
chess.apkg
Normal file
BIN
chess.apkg
Normal file
Binary file not shown.
|
|
@ -1,7 +1,4 @@
|
||||||
#!/usr/bin/env -S uv run --script
|
#!/usr/bin/env -S uv run --script
|
||||||
#
|
|
||||||
# Generates the blind_chess.apkg Anki Deck
|
|
||||||
#
|
|
||||||
# /// script
|
# /// script
|
||||||
# requires-python = ">=3.13"
|
# requires-python = ">=3.13"
|
||||||
# dependencies = [
|
# dependencies = [
|
||||||
|
|
@ -15,9 +12,14 @@ import genanki
|
||||||
import chess
|
import chess
|
||||||
import chess.svg
|
import chess.svg
|
||||||
|
|
||||||
deck = genanki.Deck(2059400110, 'Blind Chess')
|
deck = genanki.Deck(
|
||||||
|
2059400110,
|
||||||
|
'Blind Chess'
|
||||||
|
)
|
||||||
|
|
||||||
model = genanki.Model(1120858226, 'Chess Model',
|
model= genanki.Model(
|
||||||
|
1120858226,
|
||||||
|
'Chess Model',
|
||||||
fields=[
|
fields=[
|
||||||
{'name': 'guid'},
|
{'name': 'guid'},
|
||||||
{'name': 'Question'},
|
{'name': 'Question'},
|
||||||
|
|
@ -28,7 +30,7 @@ model = genanki.Model(1120858226, 'Chess Model',
|
||||||
{
|
{
|
||||||
'name': 'Base Card with SVG board in answer',
|
'name': 'Base Card with SVG board in answer',
|
||||||
'qfmt': '{{Question}}',
|
'qfmt': '{{Question}}',
|
||||||
'afmt': '{{FrontSide}}<hr id="answer">{{Answer}} {{Board}}',
|
'afmt': '{{FrontSide}}<hr id="answer">{{Answer} {{Board}}',
|
||||||
},
|
},
|
||||||
]
|
]
|
||||||
)
|
)
|
||||||
|
|
@ -36,6 +38,7 @@ model = genanki.Model(1120858226, 'Chess Model',
|
||||||
class ChessNote(genanki.Note):
|
class ChessNote(genanki.Note):
|
||||||
@property
|
@property
|
||||||
def guid(self):
|
def guid(self):
|
||||||
|
# slug-square-piece
|
||||||
return genanki.guid_for(self.fields[0])
|
return genanki.guid_for(self.fields[0])
|
||||||
|
|
||||||
def square_color(sq_name):
|
def square_color(sq_name):
|
||||||
|
|
@ -55,22 +58,25 @@ def knight_moves(sq_name):
|
||||||
board.set_piece_at(sq_id, chess.Piece(chess.KNIGHT, chess.WHITE))
|
board.set_piece_at(sq_id, chess.Piece(chess.KNIGHT, chess.WHITE))
|
||||||
attacks = board.attacks(sq_id)
|
attacks = board.attacks(sq_id)
|
||||||
|
|
||||||
guid = f'{sq_name}-knight-moves'
|
guid = f'{sq_name}-knight-moves' #guid
|
||||||
question = f'Where can the knight move from square {sq_name}?'
|
question = f'Where can the knight move from square {sq_name}?'
|
||||||
answer = ', '.join(chess.SQUARE_NAMES[sq] for sq in list(attacks))
|
answer = ', '.join(chess.SQUARE_NAMES[sq] for sq in list(attacks))
|
||||||
board_svg = chess.svg.board(board, fill=dict.fromkeys(attacks, "#cc0000cc"))
|
board_svg = chess.svg.board(board, fill=dict.fromkeys(attacks, "#cc0000cc"))
|
||||||
|
# return ChessNote(model, [guid, question, answer, board_svg])
|
||||||
return ChessNote(model, [guid,question,answer,board_svg])
|
return ChessNote(model, [guid,question,answer,board_svg])
|
||||||
|
|
||||||
def notes():
|
def notes():
|
||||||
|
# square colors
|
||||||
for sq_name in chess.SQUARE_NAMES:
|
for sq_name in chess.SQUARE_NAMES:
|
||||||
yield square_color(sq_name)
|
yield square_color(sq_name)
|
||||||
yield knight_moves(sq_name)
|
yield knight_moves(sq_name)
|
||||||
|
|
||||||
notes = list(notes())
|
notes = list(notes())
|
||||||
|
|
||||||
|
# randomize the order of the notes
|
||||||
random.shuffle(notes)
|
random.shuffle(notes)
|
||||||
for note in notes:
|
for note in notes:
|
||||||
deck.add_note(note)
|
deck.add_note(note)
|
||||||
|
|
||||||
out = 'blind_chess.apkg'
|
genanki.Package(deck).write_to_file('chess.apkg')
|
||||||
genanki.Package(deck).write_to_file(out)
|
print(f'Created deck chess.apkg with {len(deck.notes)} notes')
|
||||||
print(f'Created deck {out} with {len(deck.notes)} notes')
|
|
||||||
Loading…
Reference in a new issue