diff --git a/rs/src/main.rs b/rs/src/main.rs index 39d70a6..413af52 100644 --- a/rs/src/main.rs +++ b/rs/src/main.rs @@ -5,16 +5,16 @@ enum Color { } impl Color { - fn get_home_row(&self) -> Row { + fn get_home_rank(&self) -> Rank { match self { - Color::Black => Row::_8, - Color::White => Row::_1, + Color::Black => Rank::_8, + Color::White => Rank::_1, } } - fn get_pawn_row(&self) -> Row { + fn get_pawn_rank(&self) -> Rank { match self { - Color::Black => Row::_7, - Color::White => Row::_2, + Color::Black => Rank::_7, + Color::White => Rank::_2, } } fn get_direction(&self) -> i8 { @@ -27,22 +27,22 @@ impl Color { #[derive(Clone)] struct Position { - row: Row, - column: Column, + rank: Rank, + file: File, } impl Position { - fn delta(&self, delta_row_column: (i8, i8)) -> Result { - let (delta_row, delta_column) = delta_row_column; + fn delta(&self, delta_rank_file: (i8, i8)) -> Result { + let (delta_rank, delta_file) = delta_rank_file; Ok(Position { - row: self.row.delta(delta_row)?, - column: self.column.delta(delta_column)?, + rank: self.rank.delta(delta_rank)?, + file: self.file.delta(delta_file)?, }) } } #[derive(PartialEq, Clone, Copy)] -enum Row { +enum Rank { _1, _2, _3, @@ -54,7 +54,7 @@ enum Row { } #[derive(PartialEq, Clone, Copy)] -enum Column { +enum File { A, B, C, @@ -98,32 +98,32 @@ where } } -impl GridAxis for Row { - const ALL_VALUES: [Row; 8] = [ - Row::_1, - Row::_2, - Row::_3, - Row::_4, - Row::_5, - Row::_6, - Row::_7, - Row::_8, +impl GridAxis for Rank { + const ALL_VALUES: [Rank; 8] = [ + Rank::_1, + Rank::_2, + Rank::_3, + Rank::_4, + Rank::_5, + Rank::_6, + Rank::_7, + Rank::_8, ]; fn get_index(&self) -> u8 { *self as u8 } } -impl GridAxis for Column { - const ALL_VALUES: [Column; 8] = [ - Column::A, - Column::B, - Column::C, - Column::D, - Column::E, - Column::F, - Column::G, - Column::H, +impl GridAxis for File { + const ALL_VALUES: [File; 8] = [ + File::A, + File::B, + File::C, + File::D, + File::E, + File::F, + File::G, + File::H, ]; fn get_index(&self) -> u8 { *self as u8 @@ -141,11 +141,11 @@ impl PieceType { PieceType::Pawn => [Color::Black, Color::White] .iter() .flat_map(|color| { - Column::ALL_VALUES.iter().map(|&column| Piece { + File::ALL_VALUES.iter().map(|&file| Piece { piece_type: self.clone(), position: Position { - row: color.get_pawn_row(), - column, + rank: color.get_pawn_rank(), + file, }, color: color.clone(), }) @@ -185,14 +185,14 @@ impl Piece { ) -> Vec { deltas .iter() - .filter_map(|&delta_row_column| { - self.position.delta(delta_row_column).ok() + .filter_map(|&delta_rank_file| { + self.position.delta(delta_rank_file).ok() }) .collect() } fn _pawn_get_move_deltas(&self) -> Vec<(i8, i8)> { let direction = self.color.get_direction(); - if self.position.row == self.color.get_pawn_row() { + if self.position.rank == self.color.get_pawn_rank() { vec![(1 * direction, 0), (2 * direction, 0)] } else { vec![(1 * direction, 0)] @@ -205,13 +205,13 @@ impl Piece { } struct Board { - state: [[Option; Column::ALL_VALUES.len()]; Row::ALL_VALUES.len()], + state: [[Option; File::ALL_VALUES.len()]; Rank::ALL_VALUES.len()], } impl Board { fn set_at(&mut self, position: &Position, piece: Piece) { - self.state[position.row.get_index() as usize] - [position.column.get_index() as usize] = Some(piece); + self.state[position.rank.get_index() as usize] + [position.file.get_index() as usize] = Some(piece); } fn new() -> Board { let mut board = Board {