-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
132 lines (94 loc) · 2.97 KB
/
main.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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
from __future__ import annotations
from movement import *
def print_board(board: list[Piece]) -> None:
# Build the board
BlankBoard = np.full((8, 8), '| ')
for piece in game.board:
(X, Y) = piece.coordinates
BlankBoard[X][Y] = piece.symbol
# Display the board
Y_Coordinates = " A B C D E F G H "
for piece in game.taken_blacks:
print(piece.symbol, end='')
print('', end='\n')
for piece in game.taken_whites:
print(piece.symbol, end='')
print('', end='\n')
print(Y_Coordinates, end='\n')
K = 0
for row in BlankBoard:
print('', end='\n')
K += 1
print(K, end=' ')
for collum in row:
print(collum, end='')
print('|', end='\n')
def play(turn):
while not game.over():
print_board(game.board)
if turn == 0:
print('White turn!')
else:
print('Blacks turn!')
if inCheck(turn, game):
if inCheckMate(turn, game):
print('Game Over')
if turn == 0:
print('Black wins')
else:
print('White wins')
break
print('You are in check, protect your king!')
if inCheckMate(turn, game):
print('Game Over')
print('Stalemate')
print('Select which piece to move')
inputX = MoveNumber()
inputY = MoveLetter()
if not CheckPiece (inputX, inputY, turn, game):
print ('You do not have a piece there!')
continue
print('Select where to move')
outputX = MoveNumber()
outputY = MoveLetter()
# print ("Selected piece", outputX, outputY )
if MakeMove(inputX, inputY, outputX, outputY, turn, game):
if turn == 0:
turn = 1
else:
turn = 0
continue
continue
def MakeMove(inputX, inputY, outputX, outputY, turn, game):
Moved = False
output = (int(outputX), int(outputY))
game_2 = copy.deepcopy(game)
piece_2 = ChoosePiece(inputX, inputY, turn, game_2)
(X, Y) = piece_2.coordinates
Moves = moves(piece_2, game_2)
if not Moves[outputX][outputY]:
print("That is not a possible move, try again!")
return False
if turn != piece_2.colour:
print("That is not your piece, try again!")
return False
K = taken(output, turn, game_2)
if K == 0:
return False
piece_2.coordinates = output
# Check if your in check
if inCheck(turn, game_2):
print('This move puts you in check!')
return False
# If not in check, make the changes permenant
piece_index = game_2.board.index(piece_2)
K = taken(output, turn, game)
if K == False:
return False
piece = game.board[piece_index]
piece.coordinates = output
Moved = True
return True
game = Game()
turn = 0
play(turn)