public IEnumerable <FigureMove> NextPawnMove(FigureCoord figureCoord) { if (figureCoord.figure.GetColor() == ColorType.white) { InitWhite(); } else { InitBlack(); } bit = figureCoord.coord.GetBit(); figureCoord.coord.extract(out x, out y); owned = board.GetOwnedBits(); this.figureCoord = figureCoord; foreach (FigureMove move in NextPawnMove_Double()) // e2-e4 { yield return(move); } foreach (FigureMove move in NextPawnMove_Forward()) // e2-e3 { foreach (FigureMove promove in NextPawnMove_Promotion(move)) { yield return(promove); } } foreach (FigureMove move in NextPawnMove_Fight()) // ed { foreach (FigureMove promove in NextPawnMove_Promotion(move)) { yield return(promove); } } }
IEnumerable <FigureMove> NextKnightMove_Steps(FigureCoord figureCoord) { ColorType other = figureCoord.figure.GetColor().Swap(); int[,] KnightSteps = { { -1, -2 }, { +1, -2 }, { -2, -1 }, { +2, -1 }, { -2, +1 }, { +2, +1 }, { -1, +2 }, { +1, +2 } }; FigureMove figureMove = new FigureMove(figureCoord); for (int j = 0; j < 8; j++) { if (figureCoord.coord.Shift(KnightSteps[j, 0], KnightSteps[j, 1], out figureMove.to)) { if (board.IsEmpty(figureMove.to)) { yield return(figureMove); } else if (board.IsColor(figureMove.to, other)) { yield return(figureMove); } } } }
ulong AllKnightMoves(FigureCoord figureCoord) { ulong knight = figureCoord.coord.GetBit(); ColorType color = figureCoord.figure.GetColor(); return(AllKnightSquares(knight) & ~board.GetColorBits(color)); }
IEnumerable <FigureMove> NextKingMove_Steps(FigureCoord figureCoord) { FigureMove figureMove = new FigureMove(figureCoord); ColorType otherColor = figureCoord.figure.GetColor().Swap(); int[,] KingSteps = { { -1, -1 }, { -1, 0 }, { -1, +1 }, { 0, -1 }, { 0, +1 }, { +1, -1 }, { +1, 0 }, { +1, +1 } }; for (int j = 0; j < 8; j++) { if (figureCoord.coord.Shift(KingSteps[j, 0], KingSteps[j, 1], out figureMove.to)) { if (board.IsEmpty(figureMove.to)) { yield return(figureMove); } else if (board.IsColor(figureMove.to, otherColor)) { yield return(figureMove); } } } }
ulong AllKingMoves(FigureCoord figureCoord) { ulong king = figureCoord.coord.GetBit(); ColorType color = figureCoord.figure.GetColor(); return(AllKingSquares(king) & ~board.GetColorBits(color)); }
public FigureMove(FigureCoord figure, Coord to) { this.figure = figure; this.to = to; is_enpassant = false; enpassant = new Coord(); is_promotion = false; promotion = figure.figure; is_castle = false; castle = figure; }
IEnumerable <FigureMove> NextRookMove_BitMask(FigureCoord figureCoord) { ulong rookMoves = AllRookSlides(figureCoord); rookMoves.ulong2ascii().Print(); foreach (Coord to in Bitboard.NextCoord(rookMoves)) { yield return(new FigureMove(figureCoord, to)); } }
IEnumerable <FigureMove> NextQueenMove_BitMask(FigureCoord figureCoord) { ulong bishopMoves = AllQueenMoves(figureCoord); bishopMoves.ulong2ascii().Print(); foreach (Coord to in Bitboard.NextCoord(bishopMoves)) { yield return(new FigureMove(figureCoord, to)); } }
IEnumerable <FigureMove> NextRookMove(FigureCoord figureCoord) { switch (SlideStrategy) { case 1: return(NextRookMove_Steps(figureCoord)); case 2: default: return(NextRookMove_BitMask(figureCoord)); } }
IEnumerable <FigureMove> NextKnightMove_BitMask(FigureCoord figureCoord) { ulong knightMoves = AllKnightMoves(figureCoord); knightMoves.ulong2ascii().Print(); foreach (Coord to in Bitboard.NextCoord(knightMoves)) { yield return(new FigureMove(figureCoord, to)); } }
IEnumerable <FigureMove> NextKnightMove(FigureCoord figureCoord) { switch (KnightStrategy) { case 1: return(NextKnightMove_Steps(figureCoord)); case 2: return(NextKnightMove_BitMask(figureCoord)); case 3: default: return(NextKnightMove_Array64(figureCoord)); } }
IEnumerable <FigureMove> NextFigureMove(FigureCoord figureCoord) { switch (figureCoord.figure) { case FigureType.wKing: case FigureType.bKing: foreach (FigureMove move in new MovesKing(board).NextKingMove(figureCoord)) { yield return(move); } break; case FigureType.wKnight: case FigureType.bKnight: foreach (FigureMove move in new MovesKnight(board).NextKnightMove(figureCoord)) { yield return(move); } break; case FigureType.wRook: case FigureType.bRook: foreach (FigureMove move in new MovesQueen(board).NextRookMove(figureCoord)) { yield return(move); } break; case FigureType.wBishop: case FigureType.bBishop: foreach (FigureMove move in new MovesQueen(board).NextBishopMove(figureCoord)) { yield return(move); } break; case FigureType.wQueen: case FigureType.bQueen: foreach (FigureMove move in new MovesQueen(board).NextQueenMove(figureCoord)) { yield return(move); } break; case FigureType.wPawn: case FigureType.bPawn: foreach (FigureMove move in new MovesPawn(board).NextPawnMove(figureCoord)) { yield return(move); } break; } }
ulong AllRookSlides(FigureCoord figureCoord) { ulong rook = figureCoord.coord.GetBit(); ColorType color = figureCoord.figure.GetColor(); ulong stops = board.GetOwnedBits(); return ((Slide6(rook, stops) | Slide4(rook, stops) | Slide8(rook, stops) | Slide2(rook, stops)) & ~board.GetColorBits(color)); }
ulong AllRookSteps(FigureCoord figureCoord) { figureCoord.coord.extract(out int x, out int y); ColorType color = figureCoord.figure.GetColor(); ulong stops = board.GetOwnedBits(); return ((Step6(x, y, stops) | Step4(x, y, stops) | Step8(x, y, stops) | Step2(x, y, stops)) & ~board.GetColorBits(color)); }
ulong AllBishopMoves(FigureCoord figureCoord) { ulong bishop = figureCoord.coord.GetBit(); ColorType color = figureCoord.figure.GetColor(); ulong stops = board.GetOwnedBits(); return ((Slide1(bishop, stops) | Slide3(bishop, stops) | Slide7(bishop, stops) | Slide9(bishop, stops)) & ~board.GetColorBits(color)); }
IEnumerable <FigureMove> NextFigureMove(FigureCoord figureCoord) { switch (figureCoord.figure) {/* * case FigureType.wKing: * case FigureType.bKing: * foreach (FigureMove move in NextKingMove(figureCoord)) * yield return move; * break; * * case FigureType.wKnight: * case FigureType.bKnight: * foreach (FigureMove move in NextKnightMove(figureCoord)) * yield return move; * break; */ case FigureType.wRook: case FigureType.bRook: foreach (FigureMove move in NextRookMove(figureCoord)) { yield return(move); } break; /* * case FigureType.wBishop: * case FigureType.bBishop: * foreach (FigureMove move in NextBishopMove(figureCoord)) * yield return move; * break; * * case FigureType.wQueen: * case FigureType.bQueen: * foreach (FigureMove move in NextQueenMove(figureCoord)) * yield return move; * break; */ case FigureType.wPawn: foreach (FigureMove move in NextWhitePawnMove(figureCoord)) { yield return(move); } break; case FigureType.bPawn: foreach (FigureMove move in NextBlackPawnMove(figureCoord)) { yield return(move); } break; } }
public IEnumerable <FigureMove> NextKingMove(FigureCoord figureCoord) { this.figureCoord = figureCoord; switch (KingStrategy) { case 1: return(NextKingMove_Steps()); case 2: return(NextKingMove_BitMask()); case 3: default: return(NextKingMove_Array64()); } }
ulong AllQueenMoves(FigureCoord figureCoord) { ulong queen = figureCoord.coord.GetBit(); ColorType color = figureCoord.figure.GetColor(); ulong stops = board.GetOwnedBits(); return ((Slide1(queen, stops) | Slide2(queen, stops) | Slide3(queen, stops) | Slide4(queen, stops) | Slide6(queen, stops) | Slide7(queen, stops) | Slide8(queen, stops) | Slide9(queen, stops)) & ~board.GetColorBits(color)); }
IEnumerable <FigureMove> NextKingMove_Array64(FigureCoord figureCoord) { if (kingMovesArray == null) { kingMovesArray = new ulong[64]; for (int j = 0; j < 64; j++) { kingMovesArray[j] = AllKingSquares(1UL << j); } } ulong kingMoves = kingMovesArray [figureCoord.coord.xy]; foreach (Coord to in Bitboard.NextCoord(kingMoves)) { yield return(new FigureMove(figureCoord, to)); } }
IEnumerable <FigureMove> NextKnightMove_Array64(FigureCoord figureCoord) { if (knightMovesArray == null) { knightMovesArray = new ulong[64]; for (int j = 0; j < 64; j++) { knightMovesArray[j] = AllKnightSquares(1UL << j); } } ulong knightMoves = knightMovesArray[figureCoord.coord.xy]; //knightMoves.ulong2ascii().Print(); foreach (Coord to in Bitboard.NextCoord(knightMoves)) { yield return(new FigureMove(figureCoord, to)); } }
IEnumerable <FigureMove> NextWhitePawnMove(FigureCoord figureCoord) { figureCoord.coord.extract(out int x, out int y); ulong bit = figureCoord.coord.GetBit(); ulong owned = board.GetOwnedBits(); if (0 == (owned & (bit << 8))) { if (y < 6) { yield return(new FigureMove(figureCoord, new Coord((byte)(figureCoord.coord.xy + 8)))); } else { for (FigureType promo = FigureType.wKnight; promo <= FigureType.wQueen; promo++) { FigureMove move = new FigureMove(figureCoord, new Coord((byte)(figureCoord.coord.xy + 8))); move.is_promotion = true; move.promotion = promo; yield return(move); } } } if (y == 1) { if (0 == (owned & (bit << 8))) { if (0 == (owned & (bit << 16))) { FigureMove move = new FigureMove(figureCoord, new Coord((byte)(figureCoord.coord.xy + 16))); move.is_enpassant = true; move.enpassant = new Coord(x, y + 1); } } } }
public bool is_castle; public FigureCoord castle; // начальная координата ладьи для рокировки public FigureMove(FigureCoord figure) : this(figure, figure.coord) { }
IEnumerable <FigureMove> NextQueenMove(FigureCoord figureCoord) { return(NextQueenMove_BitMask(figureCoord)); }
IEnumerable <FigureMove> NextBlackPawnMove(FigureCoord figureCoord) { yield break; }
public IEnumerable <FigureMove> NextBishopMove(FigureCoord figureCoord) { this.figureCoord = figureCoord; return(NextBishopMove_BitMask()); }