Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🐛 Skip wrong color blunder variant #7

Merged
merged 1 commit into from
Feb 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions app/src/app/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,12 @@ interface BlunderContext {
white_player: string
black_player: string
fen_before_blunder: string
game_id: string
wrong_move: string
}

interface MissedTactic {
type: 'fork' | 'checkmate' | 'stalemate'
game_id: string
context: BlunderContext
fen: string
move_number: number
Expand Down Expand Up @@ -93,7 +93,7 @@ export default function Home() {
const moveCount = Math.ceil(tactic.variant.length / 2)
const customArrows = tactic.attacked?.map((attacked) => [tactic.attacker, attacked, 'orange']) as (Arrow[] | undefined)
return (<li key={tactic.fen} className='mb-5'>
<a href={`https://lichess.org/${tactic.game_id}`} target="_blank" rel="noreferrer noopener" className="text-blue-600 underline">
<a href={`https://lichess.org/${tactic.context.game_id}`} target="_blank" rel="noreferrer noopener" className="text-blue-600 underline">
{tactic.context.white_player} vs {tactic.context.black_player}
</a>
{` -> ${tactic.type}`}
Expand Down
7 changes: 4 additions & 3 deletions chess-analysis-api/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,10 @@ def get_analysis(username: str) -> list[Union[MissedTactic, MissedFork]]:
logger.error(f"Error loading board from pgn: {game.pgn}")
continue

is_white = game.white_player.name.lower() == username.lower()

for index, move in enumerate(game_details.analysis):
if (index % 2 == 0) and game.white_player.name != username or \
(index % 2 == 1) and game.black_player.name != username:
if (index % 2 == (1 if is_white else 0)):
continue

if move.judgment is not None and move.variation is not None:
Expand All @@ -74,7 +75,7 @@ def get_analysis(username: str) -> list[Union[MissedTactic, MissedFork]]:
black_player=game.black_player.name,
fen_before_blunder=game_before_blunder.fen(),
wrong_move=game.moves.split()[index],
is_white=(game.white_player.name == username),
is_white=is_white,
game_id=game.gid
)

Expand Down
Loading