Skip to content

Commit 6f48adc

Browse files
nyurikAmanieu
authored andcommitted
Clean up examples, make it more "Rusty"
1 parent 49d647b commit 6f48adc

File tree

1 file changed

+15
-42
lines changed

1 file changed

+15
-42
lines changed

examples/connect5.rs

Lines changed: 15 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ const SCORE_NONE: i32 = -EVAL_INF - 1;
7474
/// DIRECTION 2: top left to bottom right\
7575
/// DIRECTION 3: top right to bottom left
7676
#[rustfmt::skip]
77+
#[allow(clippy::identity_op)]
7778
const DIRECTION: [[i32; 5]; 4] = [ [1, 2, 3, 4, 5],
7879
[1 * (FILE_SIZE + 1), 2 * (FILE_SIZE + 1), 3 * (FILE_SIZE + 1), 4 * (FILE_SIZE + 1), 5 * (FILE_SIZE + 1)],
7980
[1 * (FILE_SIZE + 2), 2 * (FILE_SIZE + 2), 3 * (FILE_SIZE + 2), 4 * (FILE_SIZE + 2), 5 * (FILE_SIZE + 2)],
@@ -311,7 +312,7 @@ impl Pos {
311312

312313
match self.p_turn {
313314
Color::Black => {
314-
self.state[mv as usize] = Color::Black;
315+
self.state[mv] = Color::Black;
315316
// update black move and remove empty move in bitboard
316317
self.bitboard[black][0][MAPMOVEIDX[0][mv] as usize] |= MAPMOVEVALUE[0][mv];
317318
self.bitboard[empty][0][MAPMOVEIDX[0][mv] as usize] ^= MAPMOVEVALUE[0][mv];
@@ -323,7 +324,7 @@ impl Pos {
323324
self.bitboard[empty][1][MAPMOVEIDX[3][mv] as usize] ^= MAPMOVEVALUE[3][mv];
324325
}
325326
Color::White => {
326-
self.state[mv as usize] = Color::White;
327+
self.state[mv] = Color::White;
327328
// update white move and remove empty move in bitboard
328329
self.bitboard[white][0][MAPMOVEIDX[0][mv] as usize] |= MAPMOVEVALUE[0][mv];
329330
self.bitboard[empty][0][MAPMOVEIDX[0][mv] as usize] ^= MAPMOVEVALUE[0][mv];
@@ -345,11 +346,7 @@ impl Pos {
345346
}
346347

347348
pub fn can_play(&self, from: Square) -> bool {
348-
if self.state[from as usize] == Color::Empty {
349-
true
350-
} else {
351-
false
352-
}
349+
self.state[from as usize] == Color::Empty
353350
}
354351
}
355352

@@ -421,14 +418,14 @@ fn pos_is_draw(pos: &Pos) -> bool {
421418
break;
422419
}
423420

424-
if found == false {
421+
if !found {
425422
break;
426423
}
427424
}
428425
}
429426

430-
let mut out: bool = false;
431-
if found == true && !pos_is_winner(pos) {
427+
let mut out = false;
428+
if found && !pos_is_winner(pos) {
432429
out = true;
433430
}
434431

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

450-
if _popcnt32(temp_mask as i32) == 0 && !pos_is_winner_avx512(pos) {
451-
return true;
452-
} else {
453-
return false;
454-
}
447+
_popcnt32(temp_mask as i32) == 0 && !pos_is_winner_avx512(pos)
455448
}
456449

457450
fn pos_is_end(pos: &Pos) -> bool {
458-
if pos_is_winner(pos) || pos_is_draw(pos) {
459-
true
460-
} else {
461-
false
462-
}
451+
pos_is_winner(pos) || pos_is_draw(pos)
463452
}
464453

465454
fn pos_disp(pos: &Pos) {
@@ -475,7 +464,7 @@ fn pos_disp(pos: &Pos) {
475464
}
476465
}
477466

478-
println!("");
467+
println!();
479468
}
480469

481470
match pos.turn() {
@@ -581,7 +570,7 @@ fn search(pos: &Pos, alpha: i32, beta: i32, depth: i32, _ply: i32) -> i32 {
581570
}
582571
}
583572

584-
assert!(bm != MOVE_NONE);
573+
assert_ne!(bm, MOVE_NONE);
585574
assert!(bs >= -EVAL_INF && bs <= EVAL_INF);
586575

587576
if _ply == 0 {
@@ -773,11 +762,7 @@ fn check_pattern5(pos: &Pos, sd: Side) -> bool {
773762
}
774763
}
775764

776-
if n > 0 {
777-
true
778-
} else {
779-
false
780-
}
765+
n > 0
781766
}
782767

783768
/// Check <b>-OOOO-</b>
@@ -809,11 +794,7 @@ fn check_patternlive4(pos: &Pos, sd: Side) -> bool {
809794
}
810795
}
811796

812-
if n > 0 {
813-
true
814-
} else {
815-
false
816-
}
797+
n > 0
817798
}
818799

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

964-
if count_match > 0 {
965-
return true;
966-
} else {
967-
return false;
968-
}
945+
count_match > 0
969946
}
970947

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

1030-
if count_match > 0 {
1031-
return true;
1032-
} else {
1033-
return false;
1034-
}
1007+
count_match > 0
10351008
}
10361009

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

0 commit comments

Comments
 (0)