Skip to content

Conversation

olivierphi
Copy link
Owner

@olivierphi olivierphi commented Sep 5, 2024

WIP...

Roadmap:

  • Interact with the Lichess API, using asyncio (because most of our Views for this will be proxies over HTTP calls to that API, which takes a long time compared to a database call)
  • Implement the OAuth2 flow, so that users can link their Lichess account to Zakuchess - without us storing any of their data on our backend
  • Allow users to unlink their Lichess account
  • Display a list of the user's current games
  • Display a game
  • Manage new board orientation, when the user plays the Black side
  • Allow pieces to be selected
  • Replicate the "piece_role_by_square" machinery, so we can handle pieces moves even though we're in a stateless architecture (so a piece that moves to another square is still identified as being the same piece after the move - which is what powers our move animations)
  • Allow my pieces to be moved - WIP
  • Manage end of game after a move - if the move leads to a checkmate or a draw, we should surface it to the player
  • Manage end of game
  • List of games: polling updates
  • Game display: polling updates, if it's the other player's turn
  • "Profile" window, where the user can see information about their Lichess account and unlink it
  • Try to make all this not too ugly (and there is where our productivity will suddenly collapse 😅 )

Probably for later:

  • Challenge players by their username (we'll need this endpoint, as well as that one)
  • Replay an ongoing game's moves - at least the last 2 ones, as it's a very useful feature for correspondence games

Copy link

github-actions bot commented Sep 5, 2024

☂️ Python Coverage

current status: ✅

Overall Coverage

Lines Covered Coverage Threshold Status
3897 2985 77% 60% 🟢

New Files

File Coverage Status
src/apps/chess/business_logic/_do_chess_move_with_piece_role_by_square.py 73% 🟢
src/apps/chess/exceptions.py 100% 🟢
src/apps/daily_challenge/migrations/0016_convert_games_team_members_to_tuples.py 88% 🟢
src/apps/lichess_bridge/init.py 100% 🟢
src/apps/lichess_bridge/authentication.py 53% 🟢
src/apps/lichess_bridge/business_logic/init.py 100% 🟢
src/apps/lichess_bridge/business_logic/_create_teams_and_piece_role_by_square_for_starting_position.py 94% 🟢
src/apps/lichess_bridge/business_logic/_rebuild_game_from_moves.py 86% 🟢
src/apps/lichess_bridge/business_logic/_rebuild_game_from_pgn.py 48% 🟢
src/apps/lichess_bridge/components/init.py 100% 🟢
src/apps/lichess_bridge/components/companion_bars/init.py 100% 🟢
src/apps/lichess_bridge/components/companion_bars/top_companion_bar.py 60% 🟢
src/apps/lichess_bridge/components/game_creation.py 92% 🟢
src/apps/lichess_bridge/components/game_info.py 21% 🟢
src/apps/lichess_bridge/components/misc_ui/init.py 100% 🟢
src/apps/lichess_bridge/components/misc_ui/user_profile_modal.py 65% 🟢
src/apps/lichess_bridge/components/no_linked_account.py 87% 🟢
src/apps/lichess_bridge/components/ongoing_games.py 78% 🟢
src/apps/lichess_bridge/components/pages/init.py 100% 🟢
src/apps/lichess_bridge/components/pages/lichess_pages.py 88% 🟢
src/apps/lichess_bridge/components/svg_icons.py 100% 🟢
src/apps/lichess_bridge/cookie_helpers.py 57% 🟢
src/apps/lichess_bridge/forms.py 100% 🟢
src/apps/lichess_bridge/lichess_api.py 64% 🟢
src/apps/lichess_bridge/models.py 90% 🟢
src/apps/lichess_bridge/presenters.py 77% 🟢
src/apps/lichess_bridge/urls.py 100% 🟢
src/apps/lichess_bridge/views.py 57% 🟢
src/apps/lichess_bridge/views_decorators.py 60% 🟢
src/apps/webui/components/atoms/_init_.py 100% 🟢
src/apps/webui/components/atoms/buttons.py 92% 🟢
src/apps/webui/components/chess_units.py 91% 🟢
src/apps/webui/components/forms_common.py 88% 🟢
src/apps/webui/components/misc_ui/init.py 100% 🟢
src/apps/webui/components/misc_ui/svg_icons.py 100% 🟢
src/apps/webui/components/molecules/_init_.py 100% 🟢
src/apps/webui/components/molecules/chess_arena_companion_bars.py 83% 🟢
src/apps/webui/cookie_helpers.py 68% 🟢
src/apps/webui/urls.py 100% 🟢
src/apps/webui/views.py 52% 🟢
src/lib/http_cookies_helpers.py 75% 🟢
TOTAL 83% 🟢

Modified Files

File Coverage Status
src/apps/chess/business_logic/init.py 100% 🟢
src/apps/chess/business_logic/_calculate_fen_before_move.py 78% 🟢
src/apps/chess/business_logic/_calculate_piece_available_targets.py 92% 🟢
src/apps/chess/business_logic/_do_chess_move.py 84% 🟢
src/apps/chess/components/chess_board.py 87% 🟢
src/apps/chess/components/chess_helpers.py 92% 🟢
src/apps/chess/components/misc_ui.py 88% 🟢
src/apps/chess/consts.py 93% 🟢
src/apps/chess/models.py 91% 🟢
src/apps/chess/presenters.py 91% 🟢
src/apps/chess/types.py 97% 🟢
src/apps/chess/url_converters.py 90% 🟢
src/apps/conftest.py 100% 🟢
src/apps/daily_challenge/admin.py 47% 🟢
src/apps/daily_challenge/business_logic/init.py 100% 🟢
src/apps/daily_challenge/business_logic/_compute_fields_before_bot_first_move.py 93% 🟢
src/apps/daily_challenge/business_logic/_get_current_daily_challenge.py 42% 🟢
src/apps/daily_challenge/business_logic/_get_speech_bubble.py 49% 🟢
src/apps/daily_challenge/business_logic/_has_player_won_today.py 88% 🟢
src/apps/daily_challenge/business_logic/_has_player_won_yesterday.py 88% 🟢
src/apps/daily_challenge/business_logic/_manage_daily_challenge_defeat_logic.py 56% 🟢
src/apps/daily_challenge/business_logic/_manage_daily_challenge_moved_piece_logic.py 88% 🟢
src/apps/daily_challenge/business_logic/_manage_daily_challenge_victory_logic.py 92% 🟢
src/apps/daily_challenge/business_logic/_manage_new_daily_challenge_stats_logic.py 85% 🟢
src/apps/daily_challenge/business_logic/_move_daily_challenge_piece.py 90% 🟢
src/apps/daily_challenge/business_logic/_restart_daily_challenge.py 94% 🟢
src/apps/daily_challenge/business_logic/_see_daily_challenge_solution.py 35% 🟢
src/apps/daily_challenge/business_logic/_set_daily_challenge_teams_and_pieces_roles.py 95% 🟢
src/apps/daily_challenge/business_logic/_undo_last_move.py 35% 🟢
src/apps/daily_challenge/components/misc_ui/help.py 88% 🟢
src/apps/daily_challenge/components/misc_ui/help_modal.py 82% 🟢
src/apps/daily_challenge/components/misc_ui/stats_modal.py 94% 🟢
src/apps/daily_challenge/components/misc_ui/svg_icons.py 100% 🟢
src/apps/daily_challenge/consts.py 88% 🟢
src/apps/daily_challenge/cookie_helpers.py 77% 🟢
src/apps/daily_challenge/management/commands/dailychallenge_create_from_lichess_puzzles_csv.py 35% 🟢
src/apps/daily_challenge/models.py 93% 🟢
src/apps/daily_challenge/presenters.py 91% 🟢
src/apps/daily_challenge/urls.py 100% 🟢
src/apps/daily_challenge/view_helpers.py 85% 🟢
src/apps/daily_challenge/views.py 75% 🟢
src/apps/daily_challenge/views_decorators.py 86% 🟢
src/apps/utils/view_decorators.py 57% 🟢
src/apps/utils/views_helpers.py 50% 🟢
src/apps/webui/components/layout.py 89% 🟢
src/project/asgi.py 0% 🟢
src/project/urls.py 100% 🟢
TOTAL 80% 🟢

updated for commit: 0eadccf by action🐍

It will be a long run 😅, but hey that's the very first stone now laid.

With this 1st commit we add an ugly-but-functional Oauth2 flow that allows a user to get an API token from Lichess.
Still super basic and ugly at the moment, but that's a good start :-)
As Lichess-related Views will mainly be proxies to the Lichess HTTP API, we would likely benefit from being able to not block workers' threads while the I/O between our server and Lichess are taking place.
@olivierphi olivierphi force-pushed the add-lichess-integration branch from 9188878 to 0c746f3 Compare September 6, 2024 16:15
We can now create correspondence games on Lichess, and display the ongoing games.

[bugfix] Our assets are now correctly served straight from the "static/" folder of each app in development mode, even though we stopped using "runserver" - thanks to WhiteNoise.

Misc other bugfixes here and there.
@olivierphi olivierphi force-pushed the add-lichess-integration branch from 0c746f3 to 24769a5 Compare September 6, 2024 16:28
There's still a hell lot of work to do 😅, but hey that's a first milestone reached :-)
Baby steps! Still ugly as hell, but we'll get there :-)
Because we want to cache the result of many of our chess-related functions, we'd better use immutable data structures (such as NamedTuples) to prevent bugs where we would unintentionally mutate a cached result, used by the whole app.
Let's use `pip install -e .` instead
...which comes with unexpected required updates, as we now have to manage that cache using the async API when our Views are async 😅
(which makes complete sense in retrospect, but I didn't see it coming :-)
Better than using our quick-n-dirty manual solution 😅
And while we're here... Let's change the "active/opponent" semantic of the CSS classes we add to selected pieces and targets to "playable/non-playable", which is more accurate and generic.
For some reason, it seems that the "game export" ednpoint returns outdated information about the ongoing games.

It was returning up-to-date data until yesterday, but for a mysterious reason it stopped doing so 🤷
Maybe it returns only the few first moves, when the game is still ongoing?

Anyway... Thankfully, it seems that using the "Stream Board game state" endpoint works correctly. 🤞🤞🤞

Also improve code there and there while I was here :-)
…d there

Still pretty ugly overall... but we're working on it 😅
Design is hard - especially when you have no natural talent nor acquired skills for it 😅
@olivierphi olivierphi force-pushed the add-lichess-integration branch from 1b0e713 to 1d60d71 Compare September 28, 2024 11:49
@olivierphi olivierphi force-pushed the add-lichess-integration branch from 19edbcc to a9f8e49 Compare November 25, 2024 21:30
We're not using them anyhow, since our bot ended up being based on a WebAssembly version of Stockfish, running in te player's own browser.
Now that the next major version of Python finally seems to land with PEP 649 implemented, it seems safe to use `from __future__ import annotations` everywhere we use non-builtin type hints :-)

And thanks to the "flake8 type-checking" rules (re-implemented in Ruff), we can make sure we're still using "if TYPE_CHECKING:" for type-only imports 👌
@olivierphi olivierphi force-pushed the add-lichess-integration branch from 4c6e17c to 34a0378 Compare December 7, 2024 12:02
That will give us better semantics, and should make maintenance a bit easier in the long term 🤞
…ponents

This should lead to better code overall, with the extra benefit of preparing the ground for the Lichess UI
…to Lichess

The UI for this is pretty basic for now, but as implementing this and the "atoms" & "molecules" design was my goal for today's session... I'll call it a day! :-)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant