StefanSalewski / rust-chess

Port of salewski-chess from Nim to Rust
MIT License
2 stars 1 forks source link

Wrong test for repeating positions in abeta() #7

Open StefanSalewski opened 6 months ago

StefanSalewski commented 6 months ago

The following code for testing repeating positions makes not much sense.

            if cup > 5 || hash_res.pop_cnt > 20 || is_a_pawnelsf || el.df != VOID_ID as i8 {
                // test dense populated board or deeper plys.
                m = abeta(
                    g,
                    opp_color(color),
                    v_depth + v_depth_inc + sdi[el.sf.abs() as usize] + ddi[el.df.abs() as usize],
                    cup + 1,
                    -beta,
                    -alpha,
                    hash_res_kks_len,
                    nep_pos,
                );
            } else {
                // deal with repetive positions
                let new_state = encode_board(&g, color); // this is the new board state after a piece is moved
                if g.history.contains_key(&new_state) && g.history[&new_state] >= 2 {
                    // this will be the third repetition, so draw can be requested
                    m.score = 0; // draw
                } else {
                    g.history.insert(new_state, 1);
                    m = abeta(
                        g,
                        opp_color(color),
                        v_depth
                            + v_depth_inc
                            + sdi[el.sf.abs() as usize]
                            + ddi[el.df.abs() as usize],
                        cup + 1,
                        -beta,
                        -alpha,
                        hash_res_kks_len,
                        nep_pos,
                    );
                    *g.history.get_mut(&new_state).unwrap() -= 1;
                }
            }
StefanSalewski commented 6 months ago

Should be fixed now.