Skip to content

Commit 555adf1

Browse files
committed
Small refactor
1 parent b75da70 commit 555adf1

File tree

1 file changed

+18
-18
lines changed

1 file changed

+18
-18
lines changed

src/board.rs

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -114,18 +114,18 @@ impl Board {
114114

115115
pub fn set_fen(&mut self, fen: &str) {
116116
let parts: Vec<&str> = fen.split_whitespace().collect();
117-
let mut rank = 7;
118-
let mut file = 0;
117+
let mut row = 7;
118+
let mut col = 0;
119119

120120
for c in parts[0].chars() {
121121
match c {
122122
'/' => {
123-
rank -= 1;
124-
file = 0;
123+
row -= 1;
124+
col = 0;
125125
}
126126
'1'..='8' => {
127127
let offset = c.to_digit(10).unwrap() as usize;
128-
file += offset;
128+
col += offset;
129129
}
130130
_ => {
131131
let color = if c.is_uppercase() {
@@ -144,8 +144,8 @@ impl Board {
144144
_ => panic!("Invalid FEN"),
145145
};
146146

147-
self.add_piece(color, piece, rank * BOARD_WIDTH + file);
148-
file += 1;
147+
self.add_piece(color, piece, row * BOARD_WIDTH + col);
148+
col += 1;
149149
}
150150
}
151151
}
@@ -235,15 +235,15 @@ impl Board {
235235
}
236236

237237
fn square_to_index(square: &str) -> usize {
238-
let file = square.chars().nth(0).unwrap() as usize - 'a' as usize;
239-
let rank = square.chars().nth(1).unwrap() as usize - '1' as usize;
240-
rank * BOARD_WIDTH + file
238+
let col = square.chars().nth(0).unwrap() as usize - 'a' as usize;
239+
let row = square.chars().nth(1).unwrap() as usize - '1' as usize;
240+
row * BOARD_WIDTH + col
241241
}
242242

243243
fn index_to_square(index: usize) -> String {
244-
let file = (index % BOARD_WIDTH) as u8 + b'a';
245-
let rank = (index / BOARD_WIDTH) as u8 + b'1';
246-
format!("{}{}", file as char, rank as char)
244+
let col = (index % BOARD_WIDTH) as u8 + b'a';
245+
let row = (index / BOARD_WIDTH) as u8 + b'1';
246+
format!("{}{}", col as char, row as char)
247247
}
248248

249249
fn is_square_empty(&self, index: usize) -> bool {
@@ -255,9 +255,9 @@ impl Board {
255255
}
256256

257257
pub fn print(&self) {
258-
for rank in (0..BOARD_WIDTH).rev() {
259-
for file in 0..BOARD_WIDTH {
260-
let index = rank * BOARD_WIDTH + file;
258+
for row in (0..BOARD_WIDTH).rev() {
259+
for col in 0..BOARD_WIDTH {
260+
let index = row * BOARD_WIDTH + col;
261261
let piece = if self.white_pieces.pawns.is_set(index) {
262262
'P'
263263
} else if self.white_pieces.knights.is_set(index) {
@@ -438,8 +438,8 @@ impl Board {
438438

439439
// EN PASSANT
440440
if let Some(ep) = self.en_passant_square {
441-
let left = ep - 1;
442-
let right = ep + 1;
441+
let left = (to as i32 + MOVE_LEFT) as usize;
442+
let right = (to as i32 + MOVE_RIGHT) as usize;
443443
if left == ep {
444444
moves.push(Move {
445445
from,

0 commit comments

Comments
 (0)