-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmovement.py
More file actions
108 lines (79 loc) · 2.82 KB
/
movement.py
File metadata and controls
108 lines (79 loc) · 2.82 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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
import copy
from moves import *
def ValidateNInput(N: str) -> int:
if not N in ['1', '2', '3', '4', '5', '6', '7', '8']:
raise ValueError('Must input a number between 1 and 8')
return int(N) - 1
def ValidateLInput(L: str) -> int:
L = L.upper()
allowedLValues = ['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H']
if not L in allowedLValues:
raise ValueError('Must input a letter between A and H')
return allowedLValues.index(L)
def MoveLetter():
while True:
try:
return ValidateLInput(input('Select a square A-H: '))
except ValueError as e:
print(e)
def MoveNumber():
while True:
try:
return ValidateNInput(input('Select a square 1-8: '))
except ValueError as e:
print(e)
def taken(output, turn, game):
for piece in game.board:
(X, Y) = piece.coordinates
if (X, Y) == output:
if piece.colour == turn:
print('You already have a piece there, try again!')
return False
else:
if turn == 0:
game.taken_blacks.append(piece)
game.board.remove(piece)
else:
game.taken_whites.append(piece)
game.board.remove(piece)
return True
def CheckPiece(inputX, inputY, turn, game):
for piece in game.board:
(X, Y) = piece.coordinates
input = (int(inputX), int(inputY))
if (X, Y) == input and piece.colour == turn:
return True
return False
def ChoosePiece(inputX, inputY, turn, game) -> Piece:
for piece in game.board:
(X, Y) = piece.coordinates
input = (int(inputX), int(inputY))
if (X, Y) == input and piece.colour == turn:
return piece
return game.board[0]
def inCheck(turn, game):
# Get king coordinates
for piece in game.board:
if piece.colour == turn and piece.type == 'King':
(X, Y) = piece.coordinates
for piece in game.board:
if piece.colour != turn:
piece_moves = moves(piece, game)
if piece_moves[X, Y]:
return True
return False
def inCheckMate(turn, game):
for piece in game.board:
if piece.colour == turn:
piece_moves = moves(piece, game)
for x in range(8):
for y in range(8):
if piece_moves[x, y]:
game_2 = copy.deepcopy(game)
K = taken((x, y), turn, game_2)
piece_index = game.board.index(piece)
piece_2 = game_2.board[piece_index]
piece_2.coordinates = (x, y)
if not inCheck(turn, game_2):
return False
return True