/// <summary> /// Performs the move. I move is only pseudo legal (putting own king in check) /// the move isn't executed. /// </summary> /// <returns>True if move could be carried out, false otherwise.</returns> private bool CastlingExecute(Board board) { BoardState afterState = m_beforeState = board.State; //Kings move board.MovePiece(m_from, m_to); //Rooks move board.MovePiece(m_rookFrom, m_rookTo); SetCastlingAvailabilety(ref afterState); SetEnPassentTarget(ref afterState); EndTurn(ref afterState); board.State = afterState; board.AddToHistory(); if (board.IsCheck(m_beforeState.ColorToPlay)) { CastlingUnExecute(board); return(false); } return(true); }
/// <summary> /// Takes back (undo) the castling move. Nothing is done to verify if undoing the move is actually /// valid for the board associated to this move. /// </summary> private void CastlingUnExecute(Board board) { board.RemoveFromHistory(); //Undoing rooks move board.MovePiece(m_rookTo, m_rookFrom); //Undoing kings move board.MovePiece(m_to, m_from); board.State = m_beforeState; }
/// <summary> /// Takes back (undo) the En-Passant capture move. Nothing is done to verify if undoing the move is actually /// valid for the board associated to this move. /// </summary> private void EnPassantUnExecute(Board board) { board.RemoveFromHistory(); board.MovePiece(m_to, m_from); board.PlacePiece(m_beforeState.EnPassantTarget, m_capture); board.State = m_beforeState; }
/// <summary> /// Takes back (undo) the move. Nothing is done to verify if undoing the move is actually /// valid for the board associated to this move. /// </summary> private void StandardUnExecute(Board board) { board.RemoveFromHistory(); board.MovePiece(m_to, m_from); board.PlacePiece(m_to, m_capture); board.State = m_beforeState; }
/// <summary> /// Performs the move. I move is only pseudo legal (putting own king in check) /// the move isn't executed. /// </summary> /// <returns>True if move could be carried out, false otherwise.</returns> public virtual bool Execute() { BoardState afterState = m_beforeState = m_board.State; m_board.MovePiece(m_from, m_to); SetCastlingAvailabilety(ref afterState); SetEnPassentTarget(ref afterState); EndTurn(ref afterState); m_board.State = afterState; m_board.AddToHistory(); if (m_board.IsCheck(m_beforeState.ColorToPlay)) { UnExecute(); return(false); } return(true); }
/// <summary> /// Performs the move. I move is only pseudo legal (putting own king in check) /// the move isn't executed. /// </summary> /// <returns>True if move could be carried out, false otherwise.</returns> private bool EnPassantExecute(Board board) { BoardState afterState = m_beforeState = board.State; board.PlacePiece(m_beforeState.EnPassantTarget, Piece.None); board.MovePiece(m_from, m_to); SetCastlingAvailabilety(ref afterState); SetEnPassentTarget(ref afterState); EndTurn(ref afterState); board.State = afterState; board.AddToHistory(); if (board.IsCheck(m_beforeState.ColorToPlay)) { EnPassantUnExecute(board); return(false); } return(true); }
/// <summary> /// Performs the move. If move is only pseudo legal (putting own king in check) /// the move isn't executed. /// </summary> /// <returns>True if move could be carried out, false otherwise.</returns> private bool StandardExecute(Board board) { BoardState afterState = m_beforeState = board.State; board.MovePiece(m_from, m_to); SetCastlingAvailabilety(ref afterState); SetEnPassentTarget(ref afterState); EndTurn(ref afterState); board.State = afterState; board.AddToHistory(); if (board.IsCheck(m_beforeState.ColorToPlay)) { StandardUnExecute(board); return false; } return true; }