/// <summary> /// Generates the move. /// </summary> /// <param name="board">The board</param> /// <param name="from">The starting square</param> /// <param name="to">The ending square</param> /// <returns></returns> internal override Move GenerateMove(Board board, int from, int to) { Move move; // if it's an en passant capture if (IsEnPassantCaptureMove(board, from, to)) { move = new EnPassantCaptureMove(board.Status, from, to); move.ChangeSideToMove(); // change the side to move move.SetEnPassantTarget(null); // reset the en passant target move.ResetPly(); // reset the ply move.IncrementMoves(); // increment the number of moves // we need to verify for check move.Make(board); bool result = !board.BlackKingInCheck(); move.TakeBack(board); return(result ? move : null); } move = base.GenerateMove(board, from, to); if (move != null) { move.ResetPly();// reset the ply // if it's the two-squares move if (IsTwoSquaresMove(board, from, to)) { // set the en passant target move.SetEnPassantTarget(to - Board.SideSquareNo); } // if it's a promotion if (Board.Rank(to) == Board.SideSquareNo - 1) { // we don't need to verify for check again // so the promotion delegate will not be triggered // later we will change the promotion type as needed move = new PromotionMove(board.Status, from, to); move.ChangeSideToMove(); // change the side to move move.SetEnPassantTarget(null); // reset the en passant target move.ResetPly(); // reset the ply move.IncrementMoves(); // increment the number of moves (move as PromotionMove).SetCapture(board[to]); // the capture information is set } return(move); } else { return(null); } }
/// <summary> /// Generates the move. /// </summary> /// <param name="board">The board</param> /// <param name="from">The starting square</param> /// <param name="to">The ending square</param> /// <returns></returns> internal override Move GenerateMove(Board board, int from, int to) { Move move; // if it's an en passant capture if (IsEnPassantCaptureMove(board, from, to)) { move = new EnPassantCaptureMove(board.Status, from, to); move.ChangeSideToMove();// change the side to move move.SetEnPassantTarget(null);// reset the en passant target move.ResetPly();// reset the ply move.IncrementMoves();// increment the number of moves // we need to verify for check move.Make(board); bool result = !board.BlackKingInCheck(); move.TakeBack(board); return result ? move : null; } move = base.GenerateMove(board, from, to); if (move != null) { move.ResetPly();// reset the ply // if it's the two-squares move if (IsTwoSquaresMove(board, from, to)) { // set the en passant target move.SetEnPassantTarget(to - Board.SideSquareNo); } // if it's a promotion if (Board.Rank(to) == Board.SideSquareNo - 1) { // we don't need to verify for check again // so the promotion delegate will not be triggered // later we will change the promotion type as needed move = new PromotionMove(board.Status, from, to); move.ChangeSideToMove();// change the side to move move.SetEnPassantTarget(null);// reset the en passant target move.ResetPly();// reset the ply move.IncrementMoves();// increment the number of moves (move as PromotionMove).SetCapture(board[to]);// the capture information is set } return move; } else { return null; } }