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

Simplify some code in examples #1673

Merged
merged 1 commit into from
Nov 29, 2024
Merged
Show file tree
Hide file tree
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
30 changes: 8 additions & 22 deletions examples/connect5.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ const DIRECTION: [[i32; 5]; 4] = [ [1, 2, 3, 4, 5],

/// A table to encode each location to a value in bit 31-0 in the bitboard for 4 direction
#[rustfmt::skip]
const MAPMOVEVALUE: [[i32; 239]; 4] = [ [// Direction 0
const MAPMOVEVALUE: [[i32; 239]; 4] = [ [// Direction 0
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,
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,
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,
Expand Down Expand Up @@ -114,7 +114,7 @@ const MAPMOVEVALUE: [[i32; 239]; 4] = [ [// Direction 0
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,
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,
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],
[// Direction 2
[// Direction 2
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,
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,
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,
Expand Down Expand Up @@ -148,9 +148,9 @@ const MAPMOVEVALUE: [[i32; 239]; 4] = [ [// Direction 0
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]
];

/// A table to encode each location to an index in the bitboard for 4 direction
/// A table to encode each location to an index in the bitboard for 4 direction
#[rustfmt::skip]
const MAPMOVEIDX: [[i32; 239]; 4] = [ [// Direction 0
const MAPMOVEIDX: [[i32; 239]; 4] = [ [// Direction 0
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0,
2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 0,
Expand All @@ -166,7 +166,7 @@ const MAPMOVEIDX: [[i32; 239]; 4] = [ [// Direction 0
12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 0,
13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 0,
14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14],
[// Direction 1
[// Direction 1
0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 0,
0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 0,
0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 0,
Expand Down Expand Up @@ -373,18 +373,9 @@ impl List {

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

for x in 0..(num as usize) {
new_move.push(self.p_move[x]);
}

new_move.shuffle(&mut rng);

for x in 0..(self.p_size as usize) {
self.p_move[x] = new_move[x];
}
self.p_move[..num].shuffle(&mut rng);
}
}

Expand Down Expand Up @@ -424,12 +415,7 @@ fn pos_is_draw(pos: &Pos) -> bool {
}
}

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

out
found && !pos_is_winner(pos)
}

#[target_feature(enable = "avx512f,avx512bw")]
Expand Down
12 changes: 2 additions & 10 deletions examples/hex.rs
Original file line number Diff line number Diff line change
Expand Up @@ -220,8 +220,6 @@ fn hex_encode_fallback<'a>(src: &[u8], dst: &'a mut [u8]) -> Result<&'a str, usi
// Run these with `cargo +nightly test --example hex -p stdarch`
#[cfg(test)]
mod tests {
use std::iter;

use super::*;

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

#[test]
fn big() {
test(
&[0; 1024],
&iter::repeat('0').take(2048).collect::<String>(),
);
test(&[0; 1024], &"0".repeat(2048));
}

#[test]
fn odd() {
test(
&[0; 313],
&iter::repeat('0').take(313 * 2).collect::<String>(),
);
test(&[0; 313], &"0".repeat(313 * 2));
}

#[test]
Expand Down