IEnumerable <FigureMove> NextKingMove_Steps() { 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); } } } }
IEnumerable <FigureMove> NextKnightMove_Steps() { 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); } } } }
IEnumerable <FigureMove> NextPawnMove_Promotion(FigureMove move) { if (y == promoY) { move.is_promotion = true; for (FigureType promo = promoFr; promo <= promoTo; promo++) { move.promotion = promo; yield return(move); } } else { yield return(move); } }
// e2-e4 IEnumerable <FigureMove> NextPawnMove_Double() { if (y == y1) { Coord to1 = new Coord(x, y2); Coord to2 = new Coord(x, y3); if (board.IsEmpty(to1)) { if (board.IsEmpty(to2)) { FigureMove move = new FigureMove(figureCoord, to2); move.is_enpassant = true; move.enpassant = new Coord(x, y2); yield return(move); } } } }
public void MakeMove(FigureMove move) { ulong to = move.to.GetBit(); bits[(int)move.figure.figure] &= ~move.figure.coord.GetBit(); for (int j = 0; j < 12; j++) { bits[j] &= ~to; } if (move.is_promotion) { bits[(int)move.promotion] |= to; } else { bits[(int)move.figure.figure] |= 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 static string Print(this FigureMove move) { return(move.figure.figure + " " + move.figure.coord.Print() + (move.figure.coord == move.to ? "" : "-" + move.to.Print()) + (move.is_promotion ? " " + move.promotion : "")); }