MCPcopy Create free account
hub / github.com/ParthPant/chess-rs / undo_commit

Method undo_commit

chrs-lib/src/data/mod.rs:271–304  ·  view source on GitHub ↗
(&mut self, commit: &MoveCommit)

Source from the content-addressed store, hash-verified

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);

Callers 5

is_legalMethod · 0.80
undoMethod · 0.80
nega_maxMethod · 0.80
quiescenceMethod · 0.80
perft_implFunction · 0.80

Calls 12

update_castleFunction · 0.85
CastleFlagsClass · 0.85
get_colorMethod · 0.80
undo_normalMethod · 0.80
undo_double_pushMethod · 0.80
undo_en_passantMethod · 0.80
undo_castleMethod · 0.80
undo_promotionMethod · 0.80
set_ep_targetMethod · 0.80
clear_ep_targetMethod · 0.80
rawMethod · 0.80
toggle_active_colorMethod · 0.80

Tested by

no test coverage detected