Skip to content

Commit

Permalink
fix annotation when starting color is black
Browse files Browse the repository at this point in the history
  • Loading branch information
franciscoBSalgueiro committed Nov 10, 2023
1 parent 8bcb604 commit 2f96637
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/components/panels/analysis/ReportModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ function ReportModal({

const form = useForm({
initialValues: {
engine: "",
engine: engines[0]?.path ?? "",
millisecondsPerMove: 500,
novelty: true,
},
Expand Down
11 changes: 10 additions & 1 deletion src/utils/treeReducer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -380,9 +380,18 @@ export const getNodeAtPath = (node: TreeNode, path: number[]): TreeNode => {
return getNodeAtPath(node.children[index], path.slice(1));
};

export function getColorFromFen(fen: string): "w" | "b" {
const parts = fen.split(" ");
if (parts[1] === "w") {
return "w";
}
return "b";
}

function addAnalysis(state: TreeState, analysis: { best: BestMoves, novelty: boolean }[]) {
let cur = state.root;
let i = 0;
const initialColor = getColorFromFen(state.root.fen);
while (cur !== undefined && i < analysis.length) {
cur.score = analysis[i].best.score;
if (analysis[i].novelty) {
Expand All @@ -394,7 +403,7 @@ function addAnalysis(state: TreeState, analysis: { best: BestMoves, novelty: boo
prevScore = analysis[i - 1].best.score;
}
const curScore = analysis[i].best.score;
const color = i % 2 === 1 ? "w" : "b";
const color = i % 2 === (initialColor === "w" ? 1: 0) ? "w" : "b";
cur.annotation = getAnnotation(prevScore, curScore, color);
cur = cur.children[0];
i++;
Expand Down

0 comments on commit 2f96637

Please sign in to comment.