Use 'writeln' in magic seed generation

This commit is contained in:
Bruno BELANYI 2024-04-03 20:00:57 +01:00
parent a4aa4ae1e4
commit 388c26f4ac

View file

@ -197,6 +197,8 @@ pub(crate) const ROOK_SEED: [u64; 64] = [
#[cfg(test)] #[cfg(test)]
mod test { mod test {
use std::fmt::Write as _;
use super::*; use super::*;
// A simple XOR-shift RNG implementation. // A simple XOR-shift RNG implementation.
@ -238,20 +240,25 @@ mod test {
Some((prefix, mid, suffix)) Some((prefix, mid, suffix))
} }
fn array_string(piece_type: &str, values: &[Magic]) -> String { fn array_string(piece_type: &str, values: &[Magic]) -> Result<String, std::fmt::Error> {
let mut res = format!( let mut res = String::new();
"/// A set of magic numbers for {} move generation.\n",
writeln!(
&mut res,
"/// A set of magic numbers for {} move generation.",
piece_type piece_type
); )?;
res.push_str(&format!( writeln!(
"pub(crate) const {}_SEED: [u64; 64] = [\n", &mut res,
"pub(crate) const {}_SEED: [u64; 64] = [",
piece_type.to_uppercase() piece_type.to_uppercase()
)); )?;
for magic in values { for magic in values {
res.push_str(&format!(" {},\n", magic.magic)); writeln!(&mut res, " {},", magic.magic)?;
} }
res.push_str("];\n"); writeln!(&mut res, "];")?;
res
Ok(res)
} }
#[test] #[test]
@ -264,8 +271,8 @@ mod test {
let original_text = std::fs::read_to_string(file!()).unwrap(); let original_text = std::fs::read_to_string(file!()).unwrap();
let bishop_array = array_string("bishop", &bishop_magics[..]); let bishop_array = array_string("bishop", &bishop_magics[..]).unwrap();
let rook_array = array_string("rook", &rook_magics[..]); let rook_array = array_string("rook", &rook_magics[..]).unwrap();
let new_text = { let new_text = {
let start_marker = "// region:sourcegen\n"; let start_marker = "// region:sourcegen\n";