Digital chessboard (written in C) algorithm