-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathchess.py
96 lines (65 loc) · 2.6 KB
/
chess.py
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
86
87
88
89
90
91
92
93
94
95
96
# START
i1 = input('Adj meg egy mezőt "A 0" formátumban.\t')
i2 = input('Adj meg egy másik mezőt "A 0" formátumban.\t')
first = (i1.split()[0], int(i1.split()[1]))
second = (i2.split()[0], int(i2.split()[1]))
letters = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h']
class Movements():
def __init__(self, first_block, second_block, letters):
self.first_block = first_block
self.second_block = second_block
self.letters = letters
def forward(self):
if self.first_block[0] == self.second_block[0] and self.first_block[1] != self.second_block[1]:
return True
def aside(self):
if self.first_block[1] == self.second_block[1] and self.first_block[0] != self.second_block[0]:
return True
def cross(self):
if abs(self.letters.index(self.first_block[0].lower())-self.letters.index(self.second_block[0].lower())) == abs((self.first_block[1]-self.second_block[1])):
return True
# CREATE OBJECTS
piece = Movements(first, second, letters)
# DEFINE THE PIECES
def pawn_move(obj):
print('Paraszt:')
if obj.forward() and obj.first_block[1]+1 == obj.second_block[1]:
print('Ez egy jó lépés a paraszttal.\n')
else:
print('Nem lehet ilyen lépni\n')
def rook_move(obj):
print('Bástya:')
if obj.forward() or obj.aside():
print('Ez egy jó lépés a bástyával\n')
else:
print('Nem lehet ilyet lépni\n')
def king_move(obj):
print('Kiráy')
if (obj.forward() and abs(obj.first_block[1] - obj.second_block[1]) == 1) or (obj.aside() and abs(letters.index(first[0].lower()) - letters.index(second[0].lower())) == 1) or (obj.cross() and abs(obj.first_block[1] - obj.second_block[1]) == 1):
print('Ez egy jó lépés a királlyal.\n')
else:
print('Nem lehet ilyet lépni\n')
def queen_move(obj):
print('Királynő')
if obj.forward() or obj.aside() or obj.cross():
print('Ez egy jó lépés a királynővel\n')
else:
print('Nem lehet ilyet lépni\n')
def bishop_move(obj):
print('Futó')
if obj.cross():
print('Ez egy jó lépés a futóval.\n')
else:
print('Nem lehet ilyet lépni.\n')
def knight_move(obj):
print('Ló')
if abs(obj.first_block[1] - obj.second_block[1]) * abs(letters.index(obj.first_block[0].lower()) - letters.index(obj.second_block[0].lower())) == 2:
print('Ez egy jó lépés a lóval.\n')
else:
print('Nem jó a lépés\n')
pawn_move(piece)
rook_move(piece)
king_move(piece)
queen_move(piece)
bishop_move(piece)
knight_move(piece)