-
Notifications
You must be signed in to change notification settings - Fork 0
/
king.py
74 lines (61 loc) · 1.84 KB
/
king.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
pos_letters = ["a", "b", "c", "d", "e", "f", "g", "h"]
import pygame as pg
class King:
def __init__(self, color, position):
self.color = str(color)
self.position = position
self.moved = 0
def __repr__(self) -> str:
if self.color == "b":
return "k"
else:
return "K"
def move(self, current_pos):
moves = []
ch = current_pos[0]
nm = int(current_pos[1])
# Forward
if nm + 1 > 8:
pass
else:
moves.append(f"{ch}{nm+1}")
# Back
if nm - 1 < 0:
pass
else:
moves.append(f"{ch}{nm-1}")
# Right
if pos_letters.index(ch) + 1 > 7:
pass
else:
moves.append(f"{pos_letters[pos_letters.index(ch)+1]}{nm}")
# left
if pos_letters.index(ch) - 1 < 0:
pass
else:
moves.append(f"{pos_letters[pos_letters.index(ch)-1]}{nm}")
# diag-left-forward
if pos_letters.index(ch) - 1 < 0 or nm + 1 > 8:
pass
else:
moves.append(f"{pos_letters[pos_letters.index(ch)-1]}{nm+1}")
# diag-right-forward
if pos_letters.index(ch) + 1 > 7 or nm + 1 > 8:
pass
else:
moves.append(f"{pos_letters[pos_letters.index(ch)+1]}{nm+1}")
# diag-left-back
if pos_letters.index(ch) - 1 < 0 or nm - 1 < 1:
pass
else:
moves.append(f"{pos_letters[pos_letters.index(ch)-1]}{nm-1}")
# diag-right-back
if pos_letters.index(ch) + 1 > 7 or nm - 1 < 1:
pass
else:
moves.append(f"{pos_letters[pos_letters.index(ch)+1]}{nm-1}")
return moves
def draw(self):
if self.color == "w":
return "white_king"
return "black_king"