-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathchess2.py
More file actions
85 lines (68 loc) · 3.7 KB
/
Copy pathchess2.py
File metadata and controls
85 lines (68 loc) · 3.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
'''
Chess king moves horizontally, vertically or diagonally to any adjacent cell. Given two different cells of the chessboard, determine whether a king can go from the first cell to the second in one move.
The program receives the input of four numbers from 1 to 8, each specifying the column and row number, first two - for the first cell, and then the last two - for the second cell. The program should output YES if a king can go from the first cell to the second in one move, or NO otherwise.
'''
a = int(input("Enter the column number of the first cell: "))
b = int(input(" Enter the row number of the first cell: "))
c = int(input("Enter the column number of the second cell: "))
d = int(input("Enter the row number of the second cell: "))
if a==c:
if d==b-1 or d==b+1:
print('YES')
else:
print('NO')
elif b==d:
if c==a-1 or c==a+1:
print('YES')
else:
print('NO')
elif c==a+1:
if d==b+1 or d==b-1:
print('YES')
else:
print('NO')
elif c==a-1:
if d==b+1 or d==b-1:
print('YES')
else:
print('NO')
else:
print('NO')
'''
In chess, the bishop moves diagonally, any number of squares. Given two different squares of the chessboard, determine whether a bishop can go from the first to the second in one move.
The program receives as input four numbers from 1 to 8, specifying the column and row numbers of the starting square and the column and row numbers of the ending square. The program should output YES if a Bishop can go from the first square to the second in one move, or NO otherwise.
'''
a = int(input("Enter the column number of the first cell: "))
b = int(input("Enter the row number of the first cell: "))
c = int(input("Enter the column number of the second cell: "))
d = int(input("Enter the row number of the second cell: "))
if abs(a - c) == abs(b - d):
print('YES')
else:
print('NO')
'''
Chess queen moves horizontally, vertically or diagonally to any number of cells. Given two different cells of the chessboard, determine whether a queen can go from the first cell to the second in one move.
The program receives the input of four numbers from 1 to 8, each specifying the column and row number, first two - for the first cell, and then the last two - for the second cell. The program should output YES if a queen can go from the first cell to the second in one move, or NO otherwise.
'''
a = int(input("Enter the column number of the first cell: "))
b = int(input("Enter the row number of the first cell: "))
c = int(input("Enter the column number of the second cell: "))
d = int(input("Enter the row number of the second cell: "))
if abs(a-c)==abs(b-d):
print('YES')
elif a==c or b==d:
print('YES')
else:
print('NO')
'''
Chess knight moves like the letter L. It can move two cells horizontally and one cell vertically, or two cells vertically and one cells horizontally. Given two different cells of the chessboard, determine whether a knight can go from the first cell to the second in one move.
The program receives the input of four numbers from 1 to 8, each specifying the column and row number, first two - for the first cell, and then the last two - for the second cell. The program should output YES if a knight can go from the first cell to the second in one move, or NO otherwise.
'''
a = int(input("Enter the column number of the first cell: "))
b = int(input("Enter the row number of the first cell: "))
c = int(input("Enter the column number of the second cell: "))
d = int(input("Enter the row number of the second cell: "))
if abs(c-a)==1 and abs(d-b)==2 or abs(c-a)==2 and abs(d-b)==1:
print('YES')
else:
print('NO')