Skip to content

Commit 703cc1f

Browse files
Reduce match statement into an if-let statement (#6)
* Reduce match statement into an if-let statement
1 parent 395c7ae commit 703cc1f

1 file changed

Lines changed: 22 additions & 29 deletions

File tree

src/game.rs

Lines changed: 22 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -159,11 +159,8 @@ impl Game {
159159
let mut copy = self.start_pos;
160160

161161
for x in self.moves.iter() {
162-
match *x {
163-
Action::MakeMove(m) => {
164-
copy = copy.make_move_new(m);
165-
}
166-
_ => {}
162+
if let Action::MakeMove(m) = *x {
163+
copy = copy.make_move_new(m);
167164
}
168165
}
169166

@@ -211,31 +208,27 @@ impl Game {
211208
// and filling a list of legal_moves_per_turn list for 3-fold repitition
212209
legal_moves_per_turn.push((board.get_hash(), MoveGen::new_legal(&board).collect()));
213210
for x in self.moves.iter() {
214-
match *x {
215-
Action::MakeMove(m) => {
216-
let white_castle_rights = board.castle_rights(Color::White);
217-
let black_castle_rights = board.castle_rights(Color::Black);
218-
if board.piece_on(m.get_source()) == Some(Piece::Pawn) {
219-
reversible_moves = 0;
220-
legal_moves_per_turn.clear();
221-
} else if board.piece_on(m.get_dest()).is_some() {
222-
reversible_moves = 0;
223-
legal_moves_per_turn.clear();
224-
} else {
225-
reversible_moves += 1;
226-
}
227-
board = board.make_move_new(m);
228-
229-
if board.castle_rights(Color::White) != white_castle_rights
230-
|| board.castle_rights(Color::Black) != black_castle_rights
231-
{
232-
reversible_moves = 0;
233-
legal_moves_per_turn.clear();
234-
}
235-
legal_moves_per_turn
236-
.push((board.get_hash(), MoveGen::new_legal(&board).collect()));
211+
if let Action::MakeMove(m) = *x {
212+
let white_castle_rights = board.castle_rights(Color::White);
213+
let black_castle_rights = board.castle_rights(Color::Black);
214+
if board.piece_on(m.get_source()) == Some(Piece::Pawn) {
215+
reversible_moves = 0;
216+
legal_moves_per_turn.clear();
217+
} else if board.piece_on(m.get_dest()).is_some() {
218+
reversible_moves = 0;
219+
legal_moves_per_turn.clear();
220+
} else {
221+
reversible_moves += 1;
222+
}
223+
board = board.make_move_new(m);
224+
225+
if board.castle_rights(Color::White) != white_castle_rights
226+
|| board.castle_rights(Color::Black) != black_castle_rights
227+
{
228+
reversible_moves = 0;
229+
legal_moves_per_turn.clear();
237230
}
238-
_ => {}
231+
legal_moves_per_turn.push((board.get_hash(), MoveGen::new_legal(&board).collect()));
239232
}
240233
}
241234

0 commit comments

Comments
 (0)