Find all diagonal counts in only one direction If I need to get the number of diagonal squares in all directions:



I do the following formula 2 N − 2 − |x − y| − |x + y − N − 1|

The above example has 13 and that's what the formula gives.

Now, what if you wanted to get the diagonal squares, but only in one direction?

The top right has 4 squares, the top left has 3, the bottom left has 3 and the bottom right has 3.

Assume I have that program to compute all legal diagonals for the Queen, and as I demonstrated above I can get all diagonals by one step using above formula, written like : 

int positiveDiagonal = Math.abs(r_q - c_q);
int negativeDiagonal = Math.abs(r_q + c_q - n - 1);
int totalDiagonal = 2 * n - 2 - positiveDiagonal - negativeDiagonal;


So, assume there is a soldier on position (5,5), that's make the Queen can't move to others diagonals in the same direction with total 4 count.

Sample Input - 1:


Board length = 8
Queen on position (4, 4)
There is no soldiers.
Explanation : 


Because there is no pieces (soldiers), we just get all diagonals we calculated using our formula.



Output - 1: 13



Sample Input - 2:


Board length = 8
Queen on position (4, 4)
There is a soldiers on point (5, 3)
Explanation : 


Because there is a piece or whatever, on point (5, 3), The Queen can't go to (5, 3), (6, 2) and (7, 1).



Output - 2: The total diagonals we got from formula is 13 and by calculating the soldier diagonals [The steps that queen can't go through], the result would be  10.



Sample Input - 3:


Board length = 5
Queen on position (5, 5)
There is a soldiers on point (1, 1)
Explanation : 


Because there is a piece (soldier), on point (1, 1), The Queen can't go to that square.



Output - 3: By subtracting this square from total diagonals which equal 4 it's results  3



Sample Input - 4:


Board length = 5
Queen on position (3, 3)
Soldiers on positions (5, 5) , (2, 1), and (4, 4)
Explanation : 


Because there is a piece (soldier), on point (5, 5) and (4, 4), The Queen can't go to these squares.



Output - 4 = 6
Jelly, 41 37 bytes

æ.µṬ+ḢṬ$+⁴²x@0¤s⁴µŒD;UŒD$ṣ€1Ẏ=2Ẹ$ƇF¬S


Try it online!

A dyadic link that takes as its left argument the zero-indexed positions of the queen and any soldiers as a list (queen first, any subsequent entries a solider) and as right argument the board size. Returns an integer that represents the number of squares available for moves on the diagonal. 

Explanation

æ.                                    | dot product of piece positions with board size, right-padded with 1
  µ                                   | start new chain with this as input
   Ṭ                                  | make a boolean array with 1 at the position of each piece
    +ḢṬ$                              | and add the same again for the Queen so the Queen has a 2
        +⁴²x@0¤                       | expand to the board dimension square with zeroes
               s⁴                     | split into lists the length of the board dimension
                 µ                    | start a new chain
                  ŒD;UŒD$             | concatenate the diagonals and the diagonals of the flipped board
                         ṣ€1          | split at soldiers
                            Ẏ         | tighten (make a single list of lists)
                             =2Ẹ$Ƈ    | filter keeping only those diagonals with the Queen in
                                 F¬S  | count the number of zeroes