Given the position of a **Bishop** and a **Pawn** on a **8 * 8 chessboard**, the task is to check whether the Bishop can take down the Pawn in one move or not. The position of Bishop and Pawn is denoted using row and column number of the chessboard.

**Examples:**

Input:bishopX = 5, bishopY = 5, pawnX = 1, pawnY = 1

Output:Yes

Input:bishopX = 5, bishopY = 5, pawnX = 1, pawnY = 3

Output:No

**Approach:** In a game of chess, the Bishop can only move diagonally and there is no restriction in the distance for each move. If we consider Bishop’s position as origin, it can be concluded that Bishop can attack at **45** degree, **135** degree, **225** degree and **315** degree angles only. So, the Bishop can attack the Pawn only if they are in such position that the slop obtained from their position is equal to tangent of 45 degree or 135 degree or 225 degree or 315 degree angle.

As we know the equation of slope for two points-

Also,

For all the attacking angles of Bishop (i.e 45°, 135°, 225°, and 315°) value of slope will be either 1 or -1.

tan(45°) = 1

tan(135°) = -1

tan(225°) = 1

tan(315°) = -1

So, for angle 45° and 225°, equation of slope will be

x2 – x1 = y2 – y1

and for angle 135° and 315°, equation of slope will be

-x2 + x1 = y2 – y1

- Considering the position of Bishop and Pawn as points on 2-D co-ordinate, Check if any of two equation is true
**x2 – x1 = y2 – y1****-x2 + x1 = y2 – y1**

- Otherwise print
**No**.

Below is the implementation of the above approach:

## C++

`// C++ implementation of above approach ` `#include <bits/stdc++.h> ` `using` `namespace` `std; ` ` ` `// Function that return true if ` `// the Bishop can take down the pawn ` `bool` `canTakeDown(` `int` `bishopX, ` `int` `bishopY, ` `int` `pawnX, ` `int` `pawnY) ` `{ ` ` ` ` ` `// If pawn is at angle ` ` ` `// 45 or 225 degree from ` ` ` `// bishop's Position ` ` ` `if` `(pawnX - bishopX == pawnY - bishopY) ` ` ` `return` `true` `; ` ` ` ` ` `// If pawn is at angle ` ` ` `// 135 or 315 degree from ` ` ` `// bishop's Position ` ` ` `else` `if` `(-pawnX + bishopX == pawnY - bishopY) ` ` ` `return` `true` `; ` ` ` ` ` `else` ` ` `return` `false` `; ` `} ` ` ` `// Driver code ` `int` `main() ` `{ ` ` ` `// Bishop's Position ` ` ` `int` `bishopX = 5, bishopY = 5; ` ` ` ` ` `// Pawn's Position ` ` ` `int` `pawnX = 1, pawnY = 1; ` ` ` ` ` `if` `(canTakeDown(bishopX, bishopY, pawnX, pawnY)) ` ` ` `cout << ` `"Yes"` `; ` ` ` `else` ` ` `cout << ` `"No"` `; ` `} ` |

*chevron_right*

*filter_none*

## Java

`// Java implementation of above approach ` `class` `GFG { ` ` ` ` ` `// Function that return true if ` ` ` `// the Bishop can take down the pawn ` ` ` `static` `boolean` `canTakeDown(` `int` `bishopX, ` `int` `bishopY, ` `int` `pawnX, ` `int` `pawnY) ` ` ` `{ ` ` ` ` ` `// If pawn is at angle ` ` ` `// 45 or 225 degree from ` ` ` `// bishop's Position ` ` ` `if` `(pawnX - bishopX == pawnY - bishopY) ` ` ` `return` `true` `; ` ` ` ` ` `// If pawn is at angle ` ` ` `// 135 or 315 degree from ` ` ` `// bishop's Position ` ` ` `else` `if` `(-pawnX + bishopX == pawnY - bishopY) ` ` ` `return` `true` `; ` ` ` ` ` `else` ` ` `return` `false` `; ` ` ` `} ` ` ` ` ` `// Driver code ` ` ` `public` `static` `void` `main(String[] args) ` ` ` `{ ` ` ` `// Bishop's Position ` ` ` `int` `bishopX = ` `5` `, bishopY = ` `5` `; ` ` ` ` ` `// Pawn's Position ` ` ` `int` `pawnX = ` `1` `, pawnY = ` `1` `; ` ` ` ` ` `if` `(canTakeDown(bishopX, bishopY, pawnX, pawnY)) ` ` ` `System.out.println(` `"Yes"` `); ` ` ` `else` ` ` `System.out.println(` `"No"` `); ` ` ` `} ` `} ` |

*chevron_right*

*filter_none*

## Python3

`# Python3 implementation of above approach ` ` ` `# Function that return true if ` `# the Bishop can take down the pawn ` `def` `canTakeDown(bishopX, bishopY, pawnX, pawnY) : ` ` ` ` ` ` ` `# If pawn is at angle ` ` ` `# 45 or 225 degree from ` ` ` `# bishop's Position ` ` ` `if` `(pawnX ` `-` `bishopX ` `=` `=` `pawnY ` `-` `bishopY) : ` ` ` `return` `True` ` ` ` ` `# If pawn is at angle ` ` ` `# 135 or 315 degree from ` ` ` `# bishop's Position ` ` ` `elif` `(` `-` `pawnX ` `+` `bishopX ` `=` `=` `pawnY ` `-` `bishopY): ` ` ` `return` `True` ` ` ` ` `else` `: ` ` ` `return` `False` ` ` ` ` `# Driver code ` ` ` `# Bishop's Position ` `bishopX ` `=` `5` `bishopY ` `=` `5` ` ` `# Pawn's Position ` `pawnX ` `=` `1` `pawnY ` `=` `1` ` ` `if` `(canTakeDown(bishopX, bishopY, pawnX, pawnY)) : ` ` ` `print` `(` `"Yes"` `) ` `else` `: ` ` ` `print` `(` `"No"` `) ` |

*chevron_right*

*filter_none*

## C#

`// C# implementation of above approach ` `using` `System; ` `class` `GFG { ` ` ` ` ` `// Function that return true if ` ` ` `// the Bishop can take down the pawn ` ` ` `static` `bool` `canTakeDown(` `int` `bishopX, ` `int` `bishopY, ` `int` `pawnX, ` `int` `pawnY) ` ` ` `{ ` ` ` ` ` `// If pawn is at angle ` ` ` `// 45 or 225 degree from ` ` ` `// bishop's Position ` ` ` `if` `(pawnX - bishopX == pawnY - bishopY) ` ` ` `return` `true` `; ` ` ` ` ` `// If pawn is at angle ` ` ` `// 135 or 315 degree from ` ` ` `// bishop's Position ` ` ` `else` `if` `(-pawnX + bishopX == pawnY - bishopY) ` ` ` `return` `true` `; ` ` ` ` ` `else` ` ` `return` `false` `; ` ` ` `} ` ` ` ` ` `// Driver code ` ` ` `public` `static` `void` `Main() ` ` ` `{ ` ` ` `// Bishop's Position ` ` ` `int` `bishopX = 5, bishopY = 5; ` ` ` ` ` `// Pawn's Position ` ` ` `int` `pawnX = 1, pawnY = 1; ` ` ` ` ` `if` `(canTakeDown(bishopX, bishopY, pawnX, pawnY)) ` ` ` `Console.WriteLine(` `"Yes"` `); ` ` ` `else` ` ` `Console.WriteLine(` `"No"` `); ` ` ` `} ` `} ` |

*chevron_right*

*filter_none*

## PHP

`<?php ` `// PHP implementation of above approach ` ` ` `// Function that return true if ` `// the Bishop can take down the pawn ` `function` `canTakeDown(` `$bishopX` `, ` `$bishopY` `, ` ` ` `$pawnX` `, ` `$pawnY` `) ` `{ ` ` ` ` ` `// If pawn is at angle ` ` ` `// 45 or 225 degree from ` ` ` `// bishop's Position ` ` ` `if` `(` `$pawnX` `- ` ` ` `$bishopX` `== ` `$pawnY` `- ` `$bishopY` `) ` ` ` `return` `true; ` ` ` ` ` `// If pawn is at angle ` ` ` `// 135 or 315 degree from ` ` ` `// bishop's Position ` ` ` `else` `if` `(-` `$pawnX` `+ ` ` ` `$bishopX` `== ` `$pawnY` `- ` ` ` `$bishopY` `) ` ` ` `return` `true; ` ` ` ` ` `else` ` ` `return` `false; ` `} ` ` ` `// Driver code ` ` ` `// Bishop's Position ` `$bishopX` `= 5; ` `$bishopY` `= 5; ` ` ` `// Pawn's Position ` `$pawnX` `= 1; ` `$pawnY` `= 1; ` ` ` `if` `(canTakeDown(` `$bishopX` `, ` `$bishopY` `, ` ` ` `$pawnX` `, ` `$pawnY` `)) ` ` ` `echo` `"Yes"` `; ` `else` ` ` `echo` `"No"` `; ` ` ` `// This code is contributed by jit_t ` `?> ` |

*chevron_right*

*filter_none*

**Output:**

Yes

Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the **DSA Self Paced Course** at a student-friendly price and become industry ready.

## Recommended Posts:

- Chessboard Pawn-Pawn game
- Count the total number of squares that can be visited by Bishop in one move
- Check if the number is valid when flipped upside down
- Check whether a number can be expressed as a product of single digit numbers
- Check whether an array can be made strictly decreasing by modifying at most one element
- Check whether a number can be represented by sum of two squares
- Check whether the number can be made perfect square after adding 1
- Check whether a number can be represented as sum of K distinct positive integers
- Queries to check whether all the elements can be made positive by flipping signs exactly K times
- Check whether two strings can be made equal by copying their characters with the adjacent ones
- Check whether N can be a Perfect Cube after adding or subtracting K
- Check whether an array of strings can correspond to a particular number X
- Check whether the number can be made perfect square after adding K
- Check whether the number can be made palindromic after adding K
- Check whether a number can be represented as difference of two squares
- Check whether a straight line can be formed using N co-ordinate points
- Check whether a number can be represented by the product of two squares
- Check whether an Array can be made 0 by splitting and merging repeatedly
- Check whether a number can be represented as difference of two consecutive cubes
- Check whether a given point lies inside a triangle or not

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.