public static IEnumerable <Move> GetLegalMoves(Color color, Board board) { foreach (int index in Board.Indexes) { Piece piece = board[index]; if (!piece.IsPiece()) { continue; } if (piece.ToColor() != color) { continue; } IEnumerable <int> movableRange = GetMovableRange(index, color, board); foreach (int candidate in Move.GetMovableIndexes(piece, index)) { if (piece.ToPieceType() == Piece.Knight) { Piece dest = board[candidate]; if (dest != Piece.Empty && dest.ToColor() == color) { continue; } } else if (!movableRange.Contains(candidate)) { continue; } yield return(new Move() { SrcIndex = index, DstIndex = candidate, PieceType = piece.ToPieceType(), Promote = false }); if ((color == Color.Black && Board.GetRank(candidate) <= 3) || (color == Color.White && Board.GetRank(candidate) >= 7)) { yield return(new Move() { SrcIndex = index, DstIndex = candidate, PieceType = piece.ToPieceType(), Promote = true }); } } } }
private static bool CheckWhiteKnightDrop(int index) { return(Board.GetRank(index) < 8); }
private static bool CheckBlackKnightDrop(int index) { return(Board.GetRank(index) > 2); }
private static bool CheckWhitePawnLanceDrop(int index) { return(Board.GetRank(index) < 9); }
private static bool CheckBlackPawnLanceDrop(int index) { return(Board.GetRank(index) > 1); }