Skip to content

Commit 8f6cb0d

Browse files
committed
prefer writeln! when write! ends in newline
1 parent 0672851 commit 8f6cb0d

10 files changed

Lines changed: 91 additions & 91 deletions

File tree

src/gen_tables/between.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -59,14 +59,14 @@ pub fn gen_between() {
5959

6060
// Write the BETWEEN array to the specified file.
6161
pub fn write_between(f: &mut File) {
62-
write!(f, "const BETWEEN: [[BitBoard; 64]; 64] = [[\n").unwrap();
62+
writeln!(f, "const BETWEEN: [[BitBoard; 64]; 64] = [[").unwrap();
6363
for i in 0..64 {
6464
for j in 0..64 {
65-
unsafe { write!(f, " BitBoard({}),\n", BETWEEN[i][j].0).unwrap() };
65+
unsafe { writeln!(f, " BitBoard({}),", BETWEEN[i][j].0).unwrap() };
6666
}
6767
if i != 63 {
68-
write!(f, " ], [\n").unwrap();
68+
writeln!(f, " ], [").unwrap();
6969
}
7070
}
71-
write!(f, "]];\n").unwrap();
71+
writeln!(f, "]];").unwrap();
7272
}

src/gen_tables/bmis.rs

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -74,43 +74,43 @@ pub fn gen_all_bmis() {
7474
}
7575

7676
pub fn write_bmis(f: &mut File) {
77-
write!(f, "#[derive(Copy, Clone)]\n").unwrap();
78-
write!(f, "struct BmiMagic {{\n").unwrap();
79-
write!(f, " blockers_mask: BitBoard,\n").unwrap();
80-
write!(f, " offset: u32,\n").unwrap();
81-
write!(f, "}}\n\n").unwrap();
77+
writeln!(f, "#[derive(Copy, Clone)]").unwrap();
78+
writeln!(f, "struct BmiMagic {{").unwrap();
79+
writeln!(f, " blockers_mask: BitBoard,").unwrap();
80+
writeln!(f, " offset: u32,").unwrap();
81+
writeln!(f, "}}\n").unwrap();
8282

83-
write!(f, "const ROOK_BMI_MASK: [BmiMagic; 64] = [\n").unwrap();
83+
writeln!(f, "const ROOK_BMI_MASK: [BmiMagic; 64] = [").unwrap();
8484
for i in 0..NUM_SQUARES {
8585
let bmi = unsafe { ROOK_BMI_MASK[i] };
86-
write!(
86+
writeln!(
8787
f,
88-
" BmiMagic {{ blockers_mask: BitBoard({}),\n",
88+
" BmiMagic {{ blockers_mask: BitBoard({}),",
8989
bmi.blockers_mask.0
9090
)
9191
.unwrap();
92-
write!(f, " offset: {} }},\n", bmi.offset).unwrap();
92+
writeln!(f, " offset: {} }},", bmi.offset).unwrap();
9393
}
94-
write!(f, "];\n").unwrap();
94+
writeln!(f, "];").unwrap();
9595

96-
write!(f, "const BISHOP_BMI_MASK: [BmiMagic; 64] = [\n").unwrap();
96+
writeln!(f, "const BISHOP_BMI_MASK: [BmiMagic; 64] = [").unwrap();
9797
for i in 0..NUM_SQUARES {
9898
let bmi = unsafe { BISHOP_BMI_MASK[i] };
99-
write!(
99+
writeln!(
100100
f,
101-
" BmiMagic {{ blockers_mask: BitBoard({}),\n",
101+
" BmiMagic {{ blockers_mask: BitBoard({}),",
102102
bmi.blockers_mask.0
103103
)
104104
.unwrap();
105-
write!(f, " offset: {} }},\n", bmi.offset).unwrap();
105+
writeln!(f, " offset: {} }},", bmi.offset).unwrap();
106106
}
107-
write!(f, "];\n").unwrap();
107+
writeln!(f, "];").unwrap();
108108

109109
let moves = unsafe { GENERATED_BMI_MOVES };
110-
write!(f, "const BMI_MOVES: [u16; {}] = [\n", moves).unwrap();
110+
writeln!(f, "const BMI_MOVES: [u16; {}] = [", moves).unwrap();
111111

112112
for i in 0..moves {
113-
write!(f, " {},\n", unsafe { BMI_MOVES[i] }).unwrap();
113+
writeln!(f, " {},", unsafe { BMI_MOVES[i] }).unwrap();
114114
}
115-
write!(f, "];\n\n").unwrap();
115+
writeln!(f, "];\n").unwrap();
116116
}

src/gen_tables/king.rs

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -67,35 +67,35 @@ fn gen_castle_moves() -> BitBoard {
6767

6868
// Write the KING_MOVES array to the specified file.
6969
pub fn write_king_moves(f: &mut File) {
70-
write!(f, "const KING_MOVES: [BitBoard; 64] = [\n").unwrap();
70+
writeln!(f, "const KING_MOVES: [BitBoard; 64] = [").unwrap();
7171
for i in 0..64 {
72-
unsafe { write!(f, " BitBoard({}),\n", KING_MOVES[i].0).unwrap() };
72+
unsafe { writeln!(f, " BitBoard({}),", KING_MOVES[i].0).unwrap() };
7373
}
74-
write!(f, "];\n").unwrap();
74+
writeln!(f, "];").unwrap();
7575

76-
write!(f, "pub const KINGSIDE_CASTLE_SQUARES: [BitBoard; 2] = [\n").unwrap();
76+
writeln!(f, "pub const KINGSIDE_CASTLE_SQUARES: [BitBoard; 2] = [").unwrap();
7777
unsafe {
78-
write!(
78+
writeln!(
7979
f,
80-
" BitBoard({}), BitBoard({})];\n",
80+
" BitBoard({}), BitBoard({})];",
8181
KINGSIDE_CASTLE_SQUARES[0].0, KINGSIDE_CASTLE_SQUARES[1].0
8282
)
8383
.unwrap()
8484
};
8585

86-
write!(f, "pub const QUEENSIDE_CASTLE_SQUARES: [BitBoard; 2] = [\n").unwrap();
86+
writeln!(f, "pub const QUEENSIDE_CASTLE_SQUARES: [BitBoard; 2] = [").unwrap();
8787
unsafe {
88-
write!(
88+
writeln!(
8989
f,
90-
" BitBoard({}), BitBoard({})];\n",
90+
" BitBoard({}), BitBoard({})];",
9191
QUEENSIDE_CASTLE_SQUARES[0].0, QUEENSIDE_CASTLE_SQUARES[1].0
9292
)
9393
.unwrap()
9494
};
9595

96-
write!(
96+
writeln!(
9797
f,
98-
"const CASTLE_MOVES: BitBoard = BitBoard({});\n",
98+
"const CASTLE_MOVES: BitBoard = BitBoard({});",
9999
gen_castle_moves().0
100100
)
101101
.unwrap();

src/gen_tables/knights.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,9 @@ pub fn gen_knight_moves() {
2929

3030
// Write the KNIGHT_MOVES array to the specified file.
3131
pub fn write_knight_moves(f: &mut File) {
32-
write!(f, "const KNIGHT_MOVES: [BitBoard; 64] = [\n").unwrap();
32+
writeln!(f, "const KNIGHT_MOVES: [BitBoard; 64] = [").unwrap();
3333
for i in 0..64 {
34-
unsafe { write!(f, " BitBoard({}),\n", KNIGHT_MOVES[i].0).unwrap() };
34+
unsafe { writeln!(f, " BitBoard({}),", KNIGHT_MOVES[i].0).unwrap() };
3535
}
36-
write!(f, "];\n").unwrap();
36+
writeln!(f, "];").unwrap();
3737
}

src/gen_tables/lines.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -48,14 +48,14 @@ pub fn gen_lines() {
4848

4949
// Write the LINE array to the specified file.
5050
pub fn write_lines(f: &mut File) {
51-
write!(f, "const LINE: [[BitBoard; 64]; 64] = [[\n").unwrap();
51+
writeln!(f, "const LINE: [[BitBoard; 64]; 64] = [[").unwrap();
5252
for i in 0..64 {
5353
for j in 0..64 {
54-
unsafe { write!(f, " BitBoard({}),\n", LINE[i][j].0).unwrap() };
54+
unsafe { writeln!(f, " BitBoard({}),", LINE[i][j].0).unwrap() };
5555
}
5656
if i != 63 {
57-
write!(f, " ], [\n").unwrap();
57+
writeln!(f, " ], [").unwrap();
5858
}
5959
}
60-
write!(f, "]];\n").unwrap();
60+
writeln!(f, "]];").unwrap();
6161
}

src/gen_tables/magic.rs

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -136,36 +136,36 @@ pub fn gen_all_magic() {
136136

137137
// Write the MAGIC_NUMBERS and MOVES arrays to the specified file.
138138
pub fn write_magic(f: &mut File) {
139-
write!(f, "#[derive(Copy, Clone)]\n").unwrap();
140-
write!(f, "struct Magic {{\n").unwrap();
141-
write!(f, " magic_number: BitBoard,\n").unwrap();
142-
write!(f, " mask: BitBoard,\n").unwrap();
143-
write!(f, " offset: u32,\n").unwrap();
144-
write!(f, " rightshift: u8\n").unwrap();
145-
write!(f, "}}\n\n").unwrap();
146-
147-
write!(f, "const MAGIC_NUMBERS: [[Magic; 64]; 2] = [[\n").unwrap();
139+
writeln!(f, "#[derive(Copy, Clone)]").unwrap();
140+
writeln!(f, "struct Magic {{").unwrap();
141+
writeln!(f, " magic_number: BitBoard,").unwrap();
142+
writeln!(f, " mask: BitBoard,").unwrap();
143+
writeln!(f, " offset: u32,").unwrap();
144+
writeln!(f, " rightshift: u8").unwrap();
145+
writeln!(f, "}}\n").unwrap();
146+
147+
writeln!(f, "const MAGIC_NUMBERS: [[Magic; 64]; 2] = [[").unwrap();
148148
for i in 0..2 {
149149
for j in 0..64 {
150150
unsafe {
151-
write!(f, " Magic {{ magic_number: BitBoard({}), mask: BitBoard({}), offset: {}, rightshift: {} }},\n",
151+
writeln!(f, " Magic {{ magic_number: BitBoard({}), mask: BitBoard({}), offset: {}, rightshift: {} }},",
152152
MAGIC_NUMBERS[i][j].magic_number.0,
153153
MAGIC_NUMBERS[i][j].mask.0,
154154
MAGIC_NUMBERS[i][j].offset,
155155
MAGIC_NUMBERS[i][j].rightshift).unwrap();
156156
}
157157
}
158158
if i != 1 {
159-
write!(f, "], [\n").unwrap();
159+
writeln!(f, "], [").unwrap();
160160
}
161161
}
162-
write!(f, "]];\n").unwrap();
162+
writeln!(f, "]];").unwrap();
163163

164164
unsafe {
165-
write!(f, "const MOVES: [BitBoard; {}] = [\n", GENERATED_NUM_MOVES).unwrap();
165+
writeln!(f, "const MOVES: [BitBoard; {}] = [", GENERATED_NUM_MOVES).unwrap();
166166
for i in 0..GENERATED_NUM_MOVES {
167-
write!(f, " BitBoard({}),\n", MOVES[i].0).unwrap();
167+
writeln!(f, " BitBoard({}),", MOVES[i].0).unwrap();
168168
}
169169
}
170-
write!(f, "];\n").unwrap();
170+
writeln!(f, "];").unwrap();
171171
}

src/gen_tables/pawns.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -87,16 +87,16 @@ pub fn gen_dest_double_moves() -> BitBoard {
8787

8888
// Write the PAWN_MOVES array to the specified file.
8989
pub fn write_pawn_moves(f: &mut File) {
90-
write!(f, "const PAWN_MOVES: [[BitBoard; 64]; 2] = [[\n").unwrap();
90+
writeln!(f, "const PAWN_MOVES: [[BitBoard; 64]; 2] = [[").unwrap();
9191
for i in 0..2 {
9292
for j in 0..64 {
93-
unsafe { write!(f, " BitBoard({}),\n", PAWN_MOVES[i][j].0).unwrap() };
93+
unsafe { writeln!(f, " BitBoard({}),", PAWN_MOVES[i][j].0).unwrap() };
9494
}
9595
if i != 1 {
96-
write!(f, " ], [\n").unwrap();
96+
writeln!(f, " ], [").unwrap();
9797
}
9898
}
99-
write!(f, "]];\n").unwrap();
99+
writeln!(f, "]];").unwrap();
100100
}
101101

102102
// Write the PAWN_ATTACKS array to the specified file.

src/gen_tables/ranks_files.rs

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -57,22 +57,22 @@ pub fn gen_bitboard_data() {
5757
// Write the FILES array to the specified file.
5858
pub fn write_bitboard_data(f: &mut File) {
5959
unsafe {
60-
write!(f, "const FILES: [BitBoard; 8] = [\n").unwrap();
60+
writeln!(f, "const FILES: [BitBoard; 8] = [").unwrap();
6161
for i in 0..8 {
62-
write!(f, " BitBoard({}),\n", FILES[i].0).unwrap();
62+
writeln!(f, " BitBoard({}),", FILES[i].0).unwrap();
6363
}
64-
write!(f, "];\n").unwrap();
65-
write!(f, "const ADJACENT_FILES: [BitBoard; 8] = [\n").unwrap();
64+
writeln!(f, "];").unwrap();
65+
writeln!(f, "const ADJACENT_FILES: [BitBoard; 8] = [").unwrap();
6666
for i in 0..8 {
67-
write!(f, " BitBoard({}),\n", ADJACENT_FILES[i].0).unwrap();
67+
writeln!(f, " BitBoard({}),", ADJACENT_FILES[i].0).unwrap();
6868
}
69-
write!(f, "];\n").unwrap();
70-
write!(f, "const RANKS: [BitBoard; 8] = [\n").unwrap();
69+
writeln!(f, "];").unwrap();
70+
writeln!(f, "const RANKS: [BitBoard; 8] = [").unwrap();
7171
for i in 0..8 {
72-
write!(f, " BitBoard({}),\n", RANKS[i].0).unwrap();
72+
writeln!(f, " BitBoard({}),", RANKS[i].0).unwrap();
7373
}
74-
write!(f, "];\n").unwrap();
75-
write!(f, "/// What are all the edge squares on the `BitBoard`?\n").unwrap();
76-
write!(f, "pub const EDGES: BitBoard = BitBoard({});\n", EDGES.0).unwrap();
74+
writeln!(f, "];").unwrap();
75+
writeln!(f, "/// What are all the edge squares on the `BitBoard`?").unwrap();
76+
writeln!(f, "pub const EDGES: BitBoard = BitBoard({});", EDGES.0).unwrap();
7777
}
7878
}

src/gen_tables/rays.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -53,16 +53,16 @@ pub fn get_rays(sq: Square, piece: Piece) -> BitBoard {
5353

5454
// Write the RAYS array to the specified file.
5555
pub fn write_rays(f: &mut File) {
56-
write!(f, "const ROOK: usize = {};\n", 0).unwrap();
57-
write!(f, "const BISHOP: usize = {};\n", 1).unwrap();
58-
write!(f, "const RAYS: [[BitBoard; 64]; 2] = [[\n").unwrap();
56+
writeln!(f, "const ROOK: usize = {};", 0).unwrap();
57+
writeln!(f, "const BISHOP: usize = {};", 1).unwrap();
58+
writeln!(f, "const RAYS: [[BitBoard; 64]; 2] = [[").unwrap();
5959
for i in 0..2 {
6060
for j in 0..64 {
61-
unsafe { write!(f, " BitBoard({}),\n", RAYS[i][j].0).unwrap() };
61+
unsafe { writeln!(f, " BitBoard({}),", RAYS[i][j].0).unwrap() };
6262
}
6363
if i != 1 {
64-
write!(f, " ], [\n").unwrap();
64+
writeln!(f, " ], [").unwrap();
6565
}
6666
}
67-
write!(f, "]];\n").unwrap();
67+
writeln!(f, "]];").unwrap();
6868
}

src/gen_tables/zobrist.rs

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -13,47 +13,47 @@ use rand::{RngCore, SeedableRng};
1313
pub fn write_zobrist(f: &mut File) {
1414
let mut rng = SmallRng::seed_from_u64(0xDEADBEEF12345678);
1515

16-
write!(f, "const SIDE_TO_MOVE: u64 = {};\n\n", rng.next_u64()).unwrap();
16+
writeln!(f, "const SIDE_TO_MOVE: u64 = {};\n", rng.next_u64()).unwrap();
1717

18-
write!(
18+
writeln!(
1919
f,
20-
"const ZOBRIST_PIECES: [[[u64; NUM_SQUARES]; NUM_PIECES]; NUM_COLORS] = [[[\n"
20+
"const ZOBRIST_PIECES: [[[u64; NUM_SQUARES]; NUM_PIECES]; NUM_COLORS] = [[["
2121
)
2222
.unwrap();
2323
for i in 0..NUM_COLORS {
2424
for j in 0..NUM_PIECES {
2525
for _ in 0..NUM_SQUARES {
26-
write!(f, " {},\n", rng.next_u64()).unwrap();
26+
writeln!(f, " {},", rng.next_u64()).unwrap();
2727
}
2828
if j != NUM_PIECES - 1 {
29-
write!(f, " ], [\n").unwrap();
29+
writeln!(f, " ], [").unwrap();
3030
}
3131
}
3232
if i != NUM_COLORS - 1 {
33-
write!(f, " ]], [[\n").unwrap();
33+
writeln!(f, " ]], [[").unwrap();
3434
}
3535
}
36-
write!(f, "]]];\n\n").unwrap();
36+
writeln!(f, "]]];\n").unwrap();
3737

38-
write!(f, "const ZOBRIST_CASTLES: [[u64; 4]; NUM_COLORS] = [[\n").unwrap();
38+
writeln!(f, "const ZOBRIST_CASTLES: [[u64; 4]; NUM_COLORS] = [[").unwrap();
3939
for i in 0..NUM_COLORS {
4040
for _ in 0..4 {
41-
write!(f, " {},\n", rng.next_u64()).unwrap();
41+
writeln!(f, " {},", rng.next_u64()).unwrap();
4242
}
4343
if i != NUM_COLORS - 1 {
44-
write!(f, " ], [\n").unwrap();
44+
writeln!(f, " ], [").unwrap();
4545
}
4646
}
47-
write!(f, "]];\n\n").unwrap();
47+
writeln!(f, "]];\n").unwrap();
4848

49-
write!(f, "const ZOBRIST_EP: [[u64; NUM_FILES]; NUM_COLORS] = [[\n").unwrap();
49+
writeln!(f, "const ZOBRIST_EP: [[u64; NUM_FILES]; NUM_COLORS] = [[").unwrap();
5050
for i in 0..NUM_COLORS {
5151
for _ in 0..NUM_FILES {
52-
write!(f, " {},\n", rng.next_u64()).unwrap();
52+
writeln!(f, " {},", rng.next_u64()).unwrap();
5353
}
5454
if i != NUM_COLORS - 1 {
55-
write!(f, "], [\n").unwrap();
55+
writeln!(f, "], [").unwrap();
5656
}
5757
}
58-
write!(f, "]];\n\n").unwrap();
58+
writeln!(f, "]];\n").unwrap();
5959
}

0 commit comments

Comments
 (0)