Skip to content

Commit

Permalink
analyze first position as well
Browse files Browse the repository at this point in the history
  • Loading branch information
franciscoBSalgueiro committed Nov 7, 2023
1 parent 642281b commit 8bcb604
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 14 deletions.
24 changes: 12 additions & 12 deletions src-tauri/src/chess.rs
Original file line number Diff line number Diff line change
Expand Up @@ -439,30 +439,30 @@ pub async fn analyze_game(
let mut analysis: Vec<MoveAnalysis> = Vec::new();

let (mut process, mut reader) = EngineProcess::new(path)?;

let fen = Fen::from_ascii(options.fen.as_bytes())?;

let mut chess: Chess = fen.into_position(CastlingMode::Standard)?;
let mut chess: Chess = fen.clone().into_position(CastlingMode::Standard)?;
let mut fens: Vec<Fen> = vec![fen];

let len_moves = moves.len();
moves.iter().for_each(|m| {
let san = San::from_ascii(m.as_bytes()).unwrap();
let m = san.to_move(&chess).unwrap();
chess.play_unchecked(&m);
fens.push(Fen::from_position(chess.clone(), EnPassantMode::Legal));
});

let mut novelty_found = false;

for (i, m) in moves.iter().enumerate() {
for (i, fen) in fens.iter().enumerate() {
app.emit_all(
"report_progress",
ProgressPayload {
progress: (i as f64 / len_moves as f64) * 100.0,
progress: (i as f64 / fens.len() as f64) * 100.0,
id: 0,
finished: false,
},
)?;
let san = San::from_ascii(m.as_bytes())?;
let m = san.to_move(&chess)?;
chess.play_unchecked(&m);
if chess.is_game_over() {
break;
}
let fen = Fen::from_position(chess.clone(), EnPassantMode::Legal);
let query = PositionQuery::exact_from_fen(&fen.to_string())?;

process
Expand All @@ -480,7 +480,7 @@ pub async fn analyze_game(
while let Ok(Some(line)) = reader.next_line().await {
match parse_one(&line) {
UciMessage::Info(attrs) => {
if let Ok(best_moves) = parse_uci_attrs(attrs, &fen) {
if let Ok(best_moves) = parse_uci_attrs(attrs, fen) {
current_analysis.best = best_moves;
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/utils/treeReducer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -381,7 +381,7 @@ export const getNodeAtPath = (node: TreeNode, path: number[]): TreeNode => {
};

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

0 comments on commit 8bcb604

Please sign in to comment.