Skip to content

Commit dba8c80

Browse files
eduardosmAmanieu
authored andcommitted
Simplify some code in examples
1 parent 96c4cc7 commit dba8c80

File tree

2 files changed

+10
-32
lines changed

2 files changed

+10
-32
lines changed

examples/connect5.rs

Lines changed: 8 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ const DIRECTION: [[i32; 5]; 4] = [ [1, 2, 3, 4, 5],
8282

8383
/// A table to encode each location to a value in bit 31-0 in the bitboard for 4 direction
8484
#[rustfmt::skip]
85-
const MAPMOVEVALUE: [[i32; 239]; 4] = [ [// Direction 0
85+
const MAPMOVEVALUE: [[i32; 239]; 4] = [ [// Direction 0
8686
1<<31, 1<<30, 1<<29, 1<<28, 1<<27, 1<<26, 1<<25, 1<<24, 1<<23, 1<<22, 1<<21, 1<<20, 1<<19, 1<<18, 1<<17, 0,
8787
1<<31, 1<<30, 1<<29, 1<<28, 1<<27, 1<<26, 1<<25, 1<<24, 1<<23, 1<<22, 1<<21, 1<<20, 1<<19, 1<<18, 1<<17, 0,
8888
1<<31, 1<<30, 1<<29, 1<<28, 1<<27, 1<<26, 1<<25, 1<<24, 1<<23, 1<<22, 1<<21, 1<<20, 1<<19, 1<<18, 1<<17, 0,
@@ -114,7 +114,7 @@ const MAPMOVEVALUE: [[i32; 239]; 4] = [ [// Direction 0
114114
1<<19, 1<<19, 1<<19, 1<<19, 1<<19, 1<<19, 1<<19, 1<<19, 1<<19, 1<<19, 1<<19, 1<<19, 1<<19, 1<<19, 1<<19, 0,
115115
1<<18, 1<<18, 1<<18, 1<<18, 1<<18, 1<<18, 1<<18, 1<<18, 1<<18, 1<<18, 1<<18, 1<<18, 1<<18, 1<<18, 1<<18, 0,
116116
1<<17, 1<<17, 1<<17, 1<<17, 1<<17, 1<<17, 1<<17, 1<<17, 1<<17, 1<<17, 1<<17, 1<<17, 1<<17, 1<<17, 1<<17],
117-
[// Direction 2
117+
[// Direction 2
118118
1<<15, 1<<15, 1<<15, 1<<15, 1<<15, 1<<15, 1<<15, 1<<15, 1<<15, 1<<15, 1<<15, 0, 0, 0, 0, 0,
119119
1<<15, 1<<14, 1<<14, 1<<14, 1<<14, 1<<14, 1<<14, 1<<14, 1<<14, 1<<14, 1<<14, 1<<14, 0, 0, 0, 0,
120120
1<<15, 1<<14, 1<<13, 1<<13, 1<<13, 1<<13, 1<<13, 1<<13, 1<<13, 1<<13, 1<<13, 1<<13, 1<<13, 0, 0, 0,
@@ -148,9 +148,9 @@ const MAPMOVEVALUE: [[i32; 239]; 4] = [ [// Direction 0
148148
1<<1, 1<<2, 1<<3, 1<<4, 1<<5, 1<<6, 1<<1, 1<<1, 1<<1, 1<<1, 1<<1, 0, 0, 0, 0]
149149
];
150150

151-
/// A table to encode each location to an index in the bitboard for 4 direction
151+
/// A table to encode each location to an index in the bitboard for 4 direction
152152
#[rustfmt::skip]
153-
const MAPMOVEIDX: [[i32; 239]; 4] = [ [// Direction 0
153+
const MAPMOVEIDX: [[i32; 239]; 4] = [ [// Direction 0
154154
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
155155
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0,
156156
2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 0,
@@ -166,7 +166,7 @@ const MAPMOVEIDX: [[i32; 239]; 4] = [ [// Direction 0
166166
12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 0,
167167
13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 0,
168168
14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14],
169-
[// Direction 1
169+
[// Direction 1
170170
0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 0,
171171
0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 0,
172172
0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 0,
@@ -373,18 +373,9 @@ impl List {
373373

374374
pub fn shuffle(&mut self) {
375375
let mut rng = thread_rng();
376-
let num = self.p_size;
377-
let mut new_move: Vec<Move> = vec![];
376+
let num = self.p_size as usize;
378377

379-
for x in 0..(num as usize) {
380-
new_move.push(self.p_move[x]);
381-
}
382-
383-
new_move.shuffle(&mut rng);
384-
385-
for x in 0..(self.p_size as usize) {
386-
self.p_move[x] = new_move[x];
387-
}
378+
self.p_move[..num].shuffle(&mut rng);
388379
}
389380
}
390381

@@ -424,12 +415,7 @@ fn pos_is_draw(pos: &Pos) -> bool {
424415
}
425416
}
426417

427-
let mut out = false;
428-
if found && !pos_is_winner(pos) {
429-
out = true;
430-
}
431-
432-
out
418+
found && !pos_is_winner(pos)
433419
}
434420

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

examples/hex.rs

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -220,8 +220,6 @@ fn hex_encode_fallback<'a>(src: &[u8], dst: &'a mut [u8]) -> Result<&'a str, usi
220220
// Run these with `cargo +nightly test --example hex -p stdarch`
221221
#[cfg(test)]
222222
mod tests {
223-
use std::iter;
224-
225223
use super::*;
226224

227225
fn test(input: &[u8], output: &str) {
@@ -248,18 +246,12 @@ mod tests {
248246

249247
#[test]
250248
fn big() {
251-
test(
252-
&[0; 1024],
253-
&iter::repeat('0').take(2048).collect::<String>(),
254-
);
249+
test(&[0; 1024], &"0".repeat(2048));
255250
}
256251

257252
#[test]
258253
fn odd() {
259-
test(
260-
&[0; 313],
261-
&iter::repeat('0').take(313 * 2).collect::<String>(),
262-
);
254+
test(&[0; 313], &"0".repeat(313 * 2));
263255
}
264256

265257
#[test]

0 commit comments

Comments
 (0)