(&mut self, commit: &MoveCommit)
| 269 | } |
| 270 | |
| 271 | pub fn undo_commit(&mut self, commit: &MoveCommit) { |
| 272 | let pcolor = commit.m.p.get_color(); |
| 273 | |
| 274 | use MoveType::*; |
| 275 | match commit.m.move_type { |
| 276 | Normal => self.undo_normal(&commit), |
| 277 | DoublePush => self.undo_double_push(&commit), |
| 278 | EnPassant => self.undo_en_passant(&commit), |
| 279 | Castle(castle_type) => self.undo_castle(&commit, castle_type), |
| 280 | Promotion(prom) => { |
| 281 | if let Some(prom) = prom { |
| 282 | self.undo_promotion(&commit, prom); |
| 283 | } else { |
| 284 | log::error!("Promotion Move has no promotion piece assigned to it"); |
| 285 | panic!(); |
| 286 | } |
| 287 | } |
| 288 | } |
| 289 | |
| 290 | if pcolor == Color::Black { |
| 291 | self.fullmove_number -= 1; |
| 292 | } |
| 293 | if let Some(t) = commit.ep_target { |
| 294 | self.set_ep_target(t); |
| 295 | } else { |
| 296 | self.clear_ep_target(); |
| 297 | } |
| 298 | let oldcastleflags = self.castle_flags.0 ^ commit.castledelta.0; |
| 299 | update_castle(self.castle_flags.raw(), &mut self.hash); |
| 300 | update_castle(oldcastleflags, &mut self.hash); |
| 301 | self.castle_flags = CastleFlags(oldcastleflags); |
| 302 | self.halfmove_clock -= 1; |
| 303 | self.toggle_active_color(); |
| 304 | } |
| 305 | |
| 306 | fn undo_normal(&mut self, commit: &MoveCommit) { |
| 307 | self.move_piece(commit.m.p, commit.m.to, commit.m.from); |
no test coverage detected