Java program:
public class Gfg { private static int checkBoard ( char [ ] [ ] board ) { for ( int i = 0 ; i < 8 ; i ++ ) { for ( int j = 0 ; j < 8 ; j ++ ) { if ( board [ i ] [ j ] == ' k ' ) { if ( lookForn ( board , ' N ' , i , j ) ) return 1 ; if ( lookForp ( board , ' P ' , i , j ) ) return 1 ; if ( lookForr ( board , ' R ' , i , j ) ) return 1 ; if ( lookForb ( board , ' B ' , i , j ) ) return 1 ; if ( lookForq ( board , ' Q ' , i , j ) ) return 1 ; if ( lookFork ( board , ' K ' , i , j ) ) return 1 ; } if ( board [ i ] [ j ] == ' K ' ) { if ( lookForn ( board , ' n ' , i , j ) ) return 2 ; if ( lookForp ( board , ' p ' , i , j ) ) return 2 ; if ( lookForr ( board , ' r ' , i , j ) ) return 2 ; if ( lookForb ( board , ' b ' , i , j ) ) return 2 ; if ( lookForq ( board , ' q ' , i , j ) ) return 2 ; if ( lookFork ( board , ' k ' , i , j ) ) return 2 ; } } } return 0 ; } private static boolean lookFork ( char [ ] [ ] board , char c , int i , int j ) { int [ ] x = { - 1 , - 1 , - 1 , 0 , 0 , 1 , 1 , 1 } ; int [ ] y = { - 1 , 0 , 1 , - 1 , 1 , - 1 , 0 , 1 } ; for ( int k = 0 ; k < 8 ; k ++ ) { int m = i + x [ k ] ; int n = j + y [ k ] ; if ( inBounds ( m , n ) && board [ m ] [ n ] == c ) return true ; } return false ; } private static boolean lookForq ( char [ ] [ ] board , char c , int i , int j ) { if ( lookForb ( board , c , i , j ) || lookForr ( board , c , i , j ) ) return true ; return false ; } private static boolean lookForb ( char [ ] [ ] board , char c , int i , int j ) { int k = 0 ; while ( inBounds ( i + ++ k , j + k ) ) { if ( board [ i + k ] [ j + k ] == c ) return true ; if ( board [ i + k ] [ j + k ] != ' - ' ) break ; } k = 0 ; while ( inBounds ( i + ++ k , j - k ) ) { if ( board [ i + k ] [ j - k ] == c ) return true ; if ( board [ i + k ] [ j - k ] != ' - ' ) break ; } k = 0 ; while ( inBounds ( i - ++ k , j + k ) ) { if ( board [ i - k ] [ j + k ] == c ) return true ; if ( board [ i - k ] [ j + k ] != ' - ' ) break ; } k = 0 ; while ( inBounds ( i - ++ k , j - k ) ) { if ( board [ i - k ] [ j - k ] == c ) return true ; if ( board [ i - k ] [ j - k ] != ' - ' ) break ; } return false ; } private static boolean lookForr ( char [ ] [ ] board , char c , int i , int j ) { int k = 0 ; while ( inBounds ( i + ++ k , j ) ) { if ( board [ i + k ] [ j ] == c ) return true ; if ( board [ i + k ] [ j ] != ' - ' ) break ; } k = 0 ; while ( inBounds ( i + -- k , j ) ) { if ( board [ i + k ] [ j ] == c ) return true ; if ( board [ i + k ] [ j ] != ' - ' ) break ; } k = 0 ; while ( inBounds ( i , j + ++ k ) ) { if ( board [ i ] [ j + k ] == c ) return true ; if ( board [ i ] [ j + k ] != ' - ' ) break ; } k = 0 ; while ( inBounds ( i , j + -- k ) ) { if ( board [ i ] [ j + k ] == c ) return true ; if ( board [ i ] [ j + k ] != ' - ' ) break ; } return false ; } private static boolean lookForn ( char [ ] [ ] board , char c , int i , int j ) { int [ ] x = { 2 , 2 , - 2 , - 2 , 1 , 1 , - 1 , - 1 } ; int [ ] y = { 1 , - 1 , 1 , - 1 , 2 , - 2 , 2 , - 2 } ; for ( int k = 0 ; k < 8 ; k ++ ) { int m = i + x [ k ] ; int n = j + y [ k ] ; if ( inBounds ( m , n ) && board [ m ] [ n ] == c ) return true ; } return false ; } private static boolean lookForp ( char [ ] [ ] board , char c , int i , int j ) { char lookFor ; if ( Character . isUpperCase ( c ) ) { lookFor = ' P ' ; if ( inBounds ( i + 1 , j - 1 ) && board [ i + 1 ] [ j - 1 ] == lookFor ) return true ; if ( inBounds ( i + 1 , j + 1 ) && board [ i + 1 ] [ j + 1 ] == lookFor ) return true ; } else { lookFor = ' p ' ; if ( inBounds ( i - 1 , j - 1 ) && board [ i - 1 ] [ j - 1 ] == lookFor ) return true ; if ( inBounds ( i - 1 , j + 1 ) && board [ i - 1 ] [ j + 1 ] == lookFor ) return true ; } return false ; } private static boolean inBounds ( int i , int j ) { return i >= 0 && i < 8 && j >= 0 && j < 8 ; } public static void main ( String [ ] args ) { char [ ] [ ] board = { { ' - ' , ' - ' , ' - ' , ' k ' , ' - ' , ' - ' , ' - ' , ' - ' } , { ' p ' , ' p ' , ' p ' , ' - ' , ' p ' , ' p ' , ' p ' , ' p ' } , { ' - ' , ' - ' , ' - ' , ' - ' , ' - ' , ' b ' , ' - ' , ' - ' } , { ' - ' , ' - ' , ' - ' , ' R ' , ' - ' , ' - ' , ' - ' , ' - ' } , { ' - ' , ' - ' , ' - ' , ' - ' , ' - ' , ' - ' , ' - ' , ' - ' } , { ' - ' , ' - ' , ' - ' , ' - ' , ' - ' , ' - ' , ' - ' , ' - ' } , { ' P ' , ' - ' , ' P ' , ' P ' , ' P ' , ' P ' , ' P ' , ' P ' } , { ' K ' , ' - ' , ' - ' , ' - ' , ' - ' , ' - ' , ' - ' , ' - ' } } ; if ( checkBoard ( board ) == 0 ) System . out . println ( " No ▁ king ▁ in ▁ danger " ) ; else if ( checkBoard ( board ) == 1 ) System . out . println ( " White ▁ king ▁ in ▁ danger " ) ; else System . out . println ( " Black ▁ king ▁ in ▁ danger " ) ; } }

Index/key variables: i, j, k, m, n
Accumulator variables: i, j, k
Iterator variables: i, j, k
Class/struct names: Gfg