public void UndoMove(Position from, Position to, Piece captured) { Piece p = this.Board.RemovePiece(to); p.DecreaseMoveCounter(); if (captured != null) { this.Board.InsertPiece(captured, to); this._captured.Remove(captured); } this.Board.InsertPiece(p, from); /*** King-side castling ***/ if (p is King && to.Column == from.Column + 2) { Position fromR = new Position(from.Row, from.Column + 3); Position toR = new Position(from.Row, from.Column + 1); Piece R = this.Board.RemovePiece(toR); R.DecreaseMoveCounter(); this.Board.InsertPiece(R, fromR); } /*** Queen-side castling ***/ if (p is King && to.Column == from.Column - 2) { Position fromR = new Position(from.Row, from.Column - 4); Position toR = new Position(from.Row, from.Column - 1); Piece R = this.Board.RemovePiece(toR); R.DecreaseMoveCounter(); this.Board.InsertPiece(R, fromR); } /*** En Passant ***/ if (p is Pawn) { if (from.Column != to.Column && captured == this.EnPassant) { Piece pawn = this.Board.GetPiece(to); Position posP; if (p.Color == Color.White) { posP = new Position(3, to.Column); } else { posP = new Position(3, to.Column); } this.Board.InsertPiece(pawn, posP); } } }