private static BitBoard GetSimilarAttacks(this IPosition position, Move move) { var pt = move.GetMovingPieceType(); return(pt == EPieceType.Pawn || pt == EPieceType.King ? BitBoards.ZeroBb : move.GetToSquare().GetAttacks(pt, position.Pieces()) ^ move.GetFromSquare()); }
private static string ToRan(Move move, IPosition pos) { var from = move.GetFromSquare(); var to = move.GetToSquare(); var notation = new StringBuilder(12); if (move.IsCastlelingMove()) { notation.Append(ECastlelingExtensions.GetCastlelingString(to, from)); } else { var pt = move.GetMovingPieceType(); if (pt != EPieceType.Pawn) { notation.Append(pt.GetPieceChar()); } notation.Append(from.ToString()); if (move.IsEnPassantMove()) { notation.Append("ep"); notation.Append(from.FileChar()); } else if (move.IsCaptureMove()) { if (pt == EPieceType.Pawn) { notation.Append(from.FileChar()); } notation.Append('x'); notation.Append(move.GetCapturedPiece().Type().GetPieceChar()); } else { notation.Append('-'); } notation.Append(to.ToString()); if (move.IsPromotionMove()) { notation.Append('='); notation.Append(move.GetPromotedPiece().GetUnicodeChar()); } } if (pos.InCheck) { notation.Append(pos.GetCheckChar()); } return(notation.ToString()); }
public static (bool, Move) Locate(this Move move, IPosition pos) { // force position to contain the latest moves for the position moves to be searched in var moveList = pos.GenerateMoves(); var element = moveList.GetMove(move.GetFromSquare(), move.GetToSquare()); return(element == null ? (false, EmptyMove) : (true, element)); }
private static string ToSan(this Move move, MoveGenerator moveGenerator) { var from = move.GetFromSquare(); var to = move.GetToSquare(); var notation = new StringBuilder(12); if (move.IsCastlelingMove()) { notation.Append(ECastlelingExtensions.GetCastlelingString(to, from)); } else { var pt = move.GetMovingPieceType(); if (pt != EPieceType.Pawn) { notation.Append(move.GetMovingPiece().GetPgnChar()); move.Disambiguation(from, moveGenerator.Position, notation); } if (move.IsEnPassantMove()) { notation.Append("ep"); notation.Append(from.FileChar()); } else if (move.IsCaptureMove()) { if (pt == EPieceType.Pawn) { notation.Append(from.FileChar()); } notation.Append('x'); } notation.Append(to.ToString()); if (move.IsPromotionMove()) { notation.Append('='); notation.Append(move.GetPromotedPiece().GetPgnChar()); } } if (moveGenerator.InCheck) { notation.Append(moveGenerator.GetCheckChar()); } return(notation.ToString()); }
public static (bool, Move) Locate(this Move move, IPosition pos) { // force position to contain the latest moves for the position moves to be searched in var mg = new MoveGenerator(pos); mg.GenerateMoves(); var element = mg.Moves.FirstOrDefault(x => x.GetFromSquare() == move.GetFromSquare() && x.GetToSquare() == move.GetToSquare()); return(element == null ? (false, EmptyMove) : (true, element)); }
public static (bool, Move) Locate(this Move move, Game game) { // force position to contain the latest moves for the position moves to be searched in game.State.GenerateMoves(); var element = game.State.Moves.FirstOrDefault(x => x.GetFromSquare() == move.GetFromSquare() && x.GetToSquare() == move.GetToSquare()); return(element == null ? (false, EmptyMove) : (true, element)); //for (int i = 0; i < game.State.Moves.Count; i++) { // if (move.GetFromSquare() == game.State.Moves[i].GetFromSquare() && move.GetToSquare() == game.State.Moves[i].GetToSquare()) // return (true, game.State.Moves[i]); //} //return (false, EmptyMove); }