private void UndoPromotion(IPiece piece, int move, PromotionTo to) { UngetPromoted(piece, to); ZKey ^= piece.ZKey; BoardArray[piece.HomeSquare] = promoted.Pop(); UnReplacePawn(piece, BoardArray[piece.HomeSquare]); }
private void UngetPromoted(IPiece piece, PromotionTo to) { if (ToMove == Side.Black) { switch (to) { case PromotionTo.Bishop: this.availBishopsWhite.Push(piece); break; case PromotionTo.Knight: this.availKnightsWhite.Push(piece); break; case PromotionTo.Queen: this.availQueensWhite.Push(piece); break; case PromotionTo.Rook: this.availRooksWhite.Push(piece); break; } } else { switch (to) { case PromotionTo.Bishop: this.availBishopsBlack.Push(piece); break; case PromotionTo.Knight: this.availKnightsBlack.Push(piece); break; case PromotionTo.Queen: this.availQueensBlack.Push(piece); break; case PromotionTo.Rook: this.availRooksBlack.Push(piece); break; } } }
public void Move(int move) { halfMovesStack.Push(halfMoves); IPiece p = board[MovePackHelper.GetStartSquare(move)]; if (MovePackHelper.HasCapture(move)) { captured.Push(board[MovePackHelper.GetEndSquare(move)]); board[MovePackHelper.GetEndSquare(move)].Capture(); ZKey ^= ZKeyForCastling[(int)CastlingStatus]; CastlingStatus ^= MovePackHelper.GetCastleMask(move); ZKey ^= ZKeyForCastling[(int)CastlingStatus]; halfMoves = 0; } else { if (p.Type != PieceType.Pawn) { halfMoves++; } } p.Move(move); if (MovePackHelper.HasCastling(move)) { DoCastling(move); } PromotionTo to = MovePackHelper.GetPromotion(move); if (to != PromotionTo.None) { DoPromotion(p, move, to); } moveStack.Push(move); if (!epTouched) { PlaceEnpassant(Square.Invalid); } epTouched = false; if (ToMove == Side.Black) { movesCount++; } Flip(); Debug.Assert(ZKey == CalcZKey()); }
private static object GetPromotionString(int p) { PromotionTo pm = GetPromotion(p); switch (pm) { case PromotionTo.Bishop: return("B"); case PromotionTo.Knight: return("N"); case PromotionTo.Queen: return("Q"); case PromotionTo.Rook: return("R"); default: return(""); } }
private IPiece GetPromoted(PromotionTo to) { if (ToMove == Side.White) { switch (to) { case PromotionTo.Bishop: return(this.availBishopsWhite.Pop()); case PromotionTo.Knight: return(this.availKnightsWhite.Pop()); case PromotionTo.Queen: return(this.availQueensWhite.Pop()); case PromotionTo.Rook: return(this.availRooksWhite.Pop()); } } else { switch (to) { case PromotionTo.Bishop: return(this.availBishopsBlack.Pop()); case PromotionTo.Knight: return(this.availKnightsBlack.Pop()); case PromotionTo.Queen: return(this.availQueensBlack.Pop()); case PromotionTo.Rook: return(this.availRooksBlack.Pop()); } } throw new Exception("Internal error."); }
private void UndoMove(int move) { IPiece p = board[MovePackHelper.GetEndSquare(move)]; p.UnMove(move); if (MovePackHelper.HasCapture(move)) { IPiece resumed = captured.Pop(); resumed.UnCapture(MovePackHelper.GetEndSquare(move)); board[resumed.HomeSquare] = resumed; ZKey ^= ZKeyForCastling[(int)CastlingStatus]; CastlingStatus ^= MovePackHelper.GetCastleMask(move); ZKey ^= ZKeyForCastling[(int)CastlingStatus]; } if (MovePackHelper.HasCastling(move)) { UndoCastling(move); } PromotionTo to = MovePackHelper.GetPromotion(move); if (to != PromotionTo.None) { UndoPromotion(p, move, to); } if (!epTouched) { UnplaceEnPassant(); } epTouched = false; if (ToMove == Side.White) { movesCount--; } halfMoves = halfMovesStack.Pop(); Flip(); Debug.Assert(ZKey == CalcZKey()); }
public static int GetPromotionMerge(PromotionTo promotion) { return((int)promotion << 27); }
private void DoPromotion(IPiece pawn, int move, PromotionTo to) { BoardArray[pawn.HomeSquare] = GetPromoted(to); ZKey ^= pawn.ZKey; ReplacePawn(pawn, BoardArray[pawn.HomeSquare]); }