/// <summary> /// Returns the estimated material exchange value of the given move on the /// given position as determined by static analysis. /// </summary> /// <param name="position">The position the move is to be played on.</param> /// <param name="move">The move to evaluate.</param> /// <returns>The estimated material exchange value of the move.</returns> private static Int32 EvaluateStaticExchange(Position position, Int32 move) { Int32 from = Move.From(move); Int32 to = Move.To(move); Int32 piece = Move.Piece(move); Int32 capture = Move.Capture(move); position.Bitboard[piece] ^= 1UL << from; position.OccupiedBitboard ^= 1UL << from; position.Square[to] = piece; Int32 value = 0; if (Move.IsPromotion(move)) { Int32 promotion = Move.Special(move); position.Square[to] = promotion; value += PieceValue[promotion] - PieceValue[Piece.Pawn]; } value += PieceValue[capture] - EvaluateStaticExchange(position, 1 - position.SideToMove, to); position.Bitboard[piece] ^= 1UL << from; position.OccupiedBitboard ^= 1UL << from; position.Square[to] = capture; return(value); }
/// <summary> /// Returns the move specified by the given information. /// </summary> /// <param name="position">The position the move is to be played on.</param> /// <param name="from">The initial square of the move.</param> /// <param name="to">The final square of the move.</param> /// <returns>The move specified by the given information.</returns> private Int32 CreateMove(Position position, Int32 from, Int32 to) { foreach (Int32 move in position.LegalMoves()) { if (from == Move.From(move) && to == Move.To(move)) { Int32 special = Move.Special(move); if (Move.IsPromotion(move)) { switch (SelectionBox.Show("What piece would you like to promote to?", "Queen", "Rook", "Bishop", "Knight")) { case "Queen": special = position.SideToMove | Piece.Queen; break; case "Rook": special = position.SideToMove | Piece.Rook; break; case "Bishop": special = position.SideToMove | Piece.Bishop; break; case "Knight": special = position.SideToMove | Piece.Knight; break; } } return(Move.Create(position, from, to, special)); } } return(Move.Invalid); }
/// <summary> /// Animates the given move between the given initial and final locations. /// </summary> /// <param name="move">The move to animate.</param> /// <param name="initial">The initial location of the moving piece.</param> /// <param name="final">The final location of the moving piece.</param> private static void Animate(Int32 move, Point initial, Point final) { VisualPiece piece = null; lock (PiecesLock) for (Int32 i = 0; i < _pieces.Count; i++) { if (_pieces[i].IsAt(initial)) { piece = _pieces[i]; break; } } new Thread(new ThreadStart(() => { piece.MoveTo(final); if (Move.IsPromotion(move)) { piece.Promote(Move.Special(move)); } })) { IsBackground = true }.Start(); }