Skip to content

Commit bff8f85

Browse files
committed
stdarch_examples: Modernization of the coding style
It modernizes the coding style of the crate stdarch_examples (an example "connect5") by fixing Clippy warnings (except clippy::manual_range_contains in which "fixing" the warning will complicate the code). Clippy: rust version 1.89.0-nightly (6f6971078 2025-05-28) Number of Fixed Warnings: 6/6
1 parent d862fb0 commit bff8f85

File tree

1 file changed

+24
-24
lines changed

1 file changed

+24
-24
lines changed

examples/connect5.rs

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -229,8 +229,7 @@ const MAPMOVEIDX: [[i32; 239]; 4] = [ [// Direction 0
229229
/// The first dimension is color: Black, White and Empty.\
230230
/// The second and third one are 2 x 512-bit. Direction 0 and 2 use the first 512-bit. Direction 1 and
231231
/// 3 use the second 512-bit.\
232-
/// Each 512-bit is a 32-bit x 16 array. Direction 0 and 1 store at bit 31-16 and Direction 2 and 3 store at bit 15-0.
233-
232+
/// Each 512-bit is a 32-bit x 16 array. Direction 0 and 1 store at bit 31-16 and Direction 2 and 3 store at bit 15-0.
234233
pub struct Pos {
235234
// position
236235
state: [Color; SQUARE_SIZE as usize],
@@ -473,6 +472,7 @@ fn gen_moves(list: &mut List, pos: &Pos) {
473472
}
474473

475474
/// AI: use Minimax search with alpha-beta pruning
475+
#[allow(clippy::manual_range_contains)]
476476
fn search(pos: &Pos, alpha: i32, beta: i32, depth: i32, _ply: i32) -> i32 {
477477
assert!(-EVAL_INF <= alpha && alpha < beta && beta <= EVAL_INF);
478478
// leaf?
@@ -724,12 +724,12 @@ fn check_pattern5(pos: &Pos, sd: Side) -> bool {
724724
for fl in 0..FILE_SIZE {
725725
let sq: Square = square_make(fl, rk);
726726

727-
for pat in 0..4 {
727+
for direction in &DIRECTION {
728728
let idx0 = sq;
729-
let idx1 = sq + DIRECTION[pat][0];
730-
let idx2 = sq + DIRECTION[pat][1];
731-
let idx3 = sq + DIRECTION[pat][2];
732-
let idx4 = sq + DIRECTION[pat][3];
729+
let idx1 = sq + direction[0];
730+
let idx2 = sq + direction[1];
731+
let idx3 = sq + direction[2];
732+
let idx4 = sq + direction[3];
733733

734734
let val0 = pos.state[idx0 as usize];
735735
let val1 = pos.state[idx1 as usize];
@@ -754,13 +754,13 @@ fn check_patternlive4(pos: &Pos, sd: Side) -> bool {
754754
for fl in 0..FILE_SIZE {
755755
let sq: Square = square_make(fl, rk);
756756

757-
for pat in 0..4 {
757+
for direction in &DIRECTION {
758758
let idx0 = sq;
759-
let idx1 = sq + DIRECTION[pat][0];
760-
let idx2 = sq + DIRECTION[pat][1];
761-
let idx3 = sq + DIRECTION[pat][2];
762-
let idx4 = sq + DIRECTION[pat][3];
763-
let idx5 = sq + DIRECTION[pat][4];
759+
let idx1 = sq + direction[0];
760+
let idx2 = sq + direction[1];
761+
let idx3 = sq + direction[2];
762+
let idx4 = sq + direction[3];
763+
let idx5 = sq + direction[4];
764764

765765
let val0 = pos.state[idx0 as usize];
766766
let val1 = pos.state[idx1 as usize];
@@ -786,12 +786,12 @@ fn check_patterndead4(pos: &Pos, sd: Side) -> i32 {
786786
for fl in 0..FILE_SIZE {
787787
let sq: Square = square_make(fl, rk);
788788

789-
for dir in 0..4 {
789+
for direction in &DIRECTION {
790790
let idx0 = sq;
791-
let idx1 = sq + DIRECTION[dir][0];
792-
let idx2 = sq + DIRECTION[dir][1];
793-
let idx3 = sq + DIRECTION[dir][2];
794-
let idx4 = sq + DIRECTION[dir][3];
791+
let idx1 = sq + direction[0];
792+
let idx2 = sq + direction[1];
793+
let idx3 = sq + direction[2];
794+
let idx4 = sq + direction[3];
795795

796796
let val0 = pos.state[idx0 as usize];
797797
let val1 = pos.state[idx1 as usize];
@@ -824,13 +824,13 @@ fn check_patternlive3(pos: &Pos, sd: Side) -> i32 {
824824
for fl in 0..FILE_SIZE {
825825
let sq: Square = square_make(fl, rk);
826826

827-
for dir in 0..4 {
827+
for direction in &DIRECTION {
828828
let idx0 = sq;
829-
let idx1 = sq + DIRECTION[dir][0];
830-
let idx2 = sq + DIRECTION[dir][1];
831-
let idx3 = sq + DIRECTION[dir][2];
832-
let idx4 = sq + DIRECTION[dir][3];
833-
let idx5 = sq + DIRECTION[dir][4];
829+
let idx1 = sq + direction[0];
830+
let idx2 = sq + direction[1];
831+
let idx3 = sq + direction[2];
832+
let idx4 = sq + direction[3];
833+
let idx5 = sq + direction[4];
834834

835835
let val0 = pos.state[idx0 as usize];
836836
let val1 = pos.state[idx1 as usize];

0 commit comments

Comments
 (0)