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

Clean up examples, make it more "Rusty" #1649

Merged
merged 1 commit into from
Oct 1, 2024
Merged
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
57 changes: 15 additions & 42 deletions examples/connect5.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ const SCORE_NONE: i32 = -EVAL_INF - 1;
/// DIRECTION 2: top left to bottom right\
/// DIRECTION 3: top right to bottom left
#[rustfmt::skip]
#[allow(clippy::identity_op)]
const DIRECTION: [[i32; 5]; 4] = [ [1, 2, 3, 4, 5],
[1 * (FILE_SIZE + 1), 2 * (FILE_SIZE + 1), 3 * (FILE_SIZE + 1), 4 * (FILE_SIZE + 1), 5 * (FILE_SIZE + 1)],
[1 * (FILE_SIZE + 2), 2 * (FILE_SIZE + 2), 3 * (FILE_SIZE + 2), 4 * (FILE_SIZE + 2), 5 * (FILE_SIZE + 2)],
Expand Down Expand Up @@ -311,7 +312,7 @@ impl Pos {

match self.p_turn {
Color::Black => {
self.state[mv as usize] = Color::Black;
self.state[mv] = Color::Black;
// update black move and remove empty move in bitboard
self.bitboard[black][0][MAPMOVEIDX[0][mv] as usize] |= MAPMOVEVALUE[0][mv];
self.bitboard[empty][0][MAPMOVEIDX[0][mv] as usize] ^= MAPMOVEVALUE[0][mv];
Expand All @@ -323,7 +324,7 @@ impl Pos {
self.bitboard[empty][1][MAPMOVEIDX[3][mv] as usize] ^= MAPMOVEVALUE[3][mv];
}
Color::White => {
self.state[mv as usize] = Color::White;
self.state[mv] = Color::White;
// update white move and remove empty move in bitboard
self.bitboard[white][0][MAPMOVEIDX[0][mv] as usize] |= MAPMOVEVALUE[0][mv];
self.bitboard[empty][0][MAPMOVEIDX[0][mv] as usize] ^= MAPMOVEVALUE[0][mv];
Expand All @@ -345,11 +346,7 @@ impl Pos {
}

pub fn can_play(&self, from: Square) -> bool {
if self.state[from as usize] == Color::Empty {
true
} else {
false
}
self.state[from as usize] == Color::Empty
}
}

Expand Down Expand Up @@ -421,14 +418,14 @@ fn pos_is_draw(pos: &Pos) -> bool {
break;
}

if found == false {
if !found {
break;
}
}
}

let mut out: bool = false;
if found == true && !pos_is_winner(pos) {
let mut out = false;
if found && !pos_is_winner(pos) {
out = true;
}

Expand All @@ -447,19 +444,11 @@ unsafe fn pos_is_draw_avx512(pos: &Pos) -> bool {
// if all empty is 0, all board is filled.
let temp_mask = _mm512_mask_cmpneq_epi32_mask(0b11111111_11111111, answer, board0org);

if _popcnt32(temp_mask as i32) == 0 && !pos_is_winner_avx512(pos) {
return true;
} else {
return false;
}
_popcnt32(temp_mask as i32) == 0 && !pos_is_winner_avx512(pos)
}

fn pos_is_end(pos: &Pos) -> bool {
if pos_is_winner(pos) || pos_is_draw(pos) {
true
} else {
false
}
pos_is_winner(pos) || pos_is_draw(pos)
}

fn pos_disp(pos: &Pos) {
Expand All @@ -475,7 +464,7 @@ fn pos_disp(pos: &Pos) {
}
}

println!("");
println!();
}

match pos.turn() {
Expand Down Expand Up @@ -581,7 +570,7 @@ fn search(pos: &Pos, alpha: i32, beta: i32, depth: i32, _ply: i32) -> i32 {
}
}

assert!(bm != MOVE_NONE);
assert_ne!(bm, MOVE_NONE);
assert!(bs >= -EVAL_INF && bs <= EVAL_INF);

if _ply == 0 {
Expand Down Expand Up @@ -773,11 +762,7 @@ fn check_pattern5(pos: &Pos, sd: Side) -> bool {
}
}

if n > 0 {
true
} else {
false
}
n > 0
}

/// Check <b>-OOOO-</b>
Expand Down Expand Up @@ -809,11 +794,7 @@ fn check_patternlive4(pos: &Pos, sd: Side) -> bool {
}
}

if n > 0 {
true
} else {
false
}
n > 0
}

/// Check <b>OOOO-, OOO-O, OO-OO, O-OOO, -OOOO</b>
Expand Down Expand Up @@ -961,11 +942,7 @@ unsafe fn pos_is_winner_avx512(pos: &Pos) -> bool {
}
}

if count_match > 0 {
return true;
} else {
return false;
}
count_match > 0
}

#[target_feature(enable = "avx512f,avx512bw")]
Expand Down Expand Up @@ -1027,11 +1004,7 @@ unsafe fn check_patternlive4_avx512(pos: &Pos, sd: Side) -> bool {
}
}

if count_match > 0 {
return true;
} else {
return false;
}
count_match > 0
}

#[target_feature(enable = "avx512f,avx512bw")]
Expand Down