0

Write a program that, given the coordinates of King and another figure on the chessboard determines whether the K is in check

I have to imput the type of the attacking figure(Q,B,N,R), coordinates of the king and the attacker

14th Nov 2016, 7:15 PM
Martin Veselinov
Martin Veselinov - avatar
1 Resposta
+ 3
Not sure how to write it in C++ but the logic should go like this, using coordinates: if R, check if x or y of attacker and K match; else if B, check if abs(x of B - x of K) == abs(y of B - y of K); else if Q, do all the checks above; else if Knight, check if (abs(x of Knight - x of K)==2 And abs(y of Knight - y of K)==1) Or (abs(x of Knight - x of K)==1 And abs(y of Knight - y of K)==2). Btw abs(x) returns the absolute i.e. positive value of x. Hope this helps 👍
13th Dec 2016, 1:37 AM
Jafca
Jafca - avatar