Skip to content

Commit

Permalink
🐛 Fix blunder color (#7)
Browse files Browse the repository at this point in the history
  • Loading branch information
zatonix authored Feb 5, 2024
1 parent cf4b148 commit 1fc3a15
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 5 deletions.
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

0 comments on commit 1fc3a15

Please sign in to comment.