Skip to content
This repository was archived by the owner on Dec 12, 2023. It is now read-only.

Create main.js #194

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 29 additions & 0 deletions problems/queen-threatens-king/main.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
function threatens()
{
let
Kx = Kx /* x coordinate of king's position */
,Ky = Ky /* y coordinate of king's position */
,Qx = Qx /* x coordinate of queen's position */
,Qy = Qy; /* x coordinate of king's position */

/*both pieces on the same diagonal if result is zero*/
Let dia = ((Kx-Qx)*(Kx-Qx))-((Ky-Qy)*(Ky-Qy));

/*check if the both pieces are on the same axes or diagonal*/
if((Kx==Qx)||(Ky==Qy)||(dia==0))
/*King is threatened*/
{
let threatened = true;

return threatened;
}

else
/*King not threatened*/
{
let threatened = false;

return threatened;
}

}