Count the total number of squares that can be visited by Bishop in one move | C ++ implementation of above approach ; Function to return the count of total positions the Bishop can visit in a single move ; Count top left squares ; Count bottom right squares ; Count top right squares ; Count bottom left squares ; Return total count ; Driver code ; Bishop 's Position
#include <bits/stdc++.h> NEW_LINE using namespace std ; int countSquares ( int row , int column ) { int topLeft = min ( row , column ) - 1 ; int bottomRight = 8 - max ( row , column ) ; int topRight = min ( row , 9 - column ) - 1 ; int bottomLeft = 8 - max ( row , 9 - column ) ; return ( topLeft + topRight + bottomRight + bottomLeft ) ; } int main ( ) { int row = 4 , column = 4 ; cout << countSquares ( row , column ) ; return 0 ; }