Skip to content

Commit 6483c71

Browse files
committed
NEEDED TO BE DONE: PAWN PROMOTION (ALMOST DONE), CHECK and CHECKMATE SYSTEM (DIFFICULTIES)
1 parent ed16eb4 commit 6483c71

File tree

9 files changed

+331
-11
lines changed

9 files changed

+331
-11
lines changed

Board.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,31 @@ def on_touch_up(self, touch):
8989
position_dic[str(chess_position_numerical)] = 'None'
9090
position_dic[str(pos_chess)] = str(piece_that_moved)
9191

92+
elif valid_or_not == "Castle":
93+
#Move the piece to the location
94+
self.ids[piece_that_moved].pos = (conversion.to_number()[pos_chess][0], conversion.to_number()[pos_chess][1])
95+
if str(pos_chess) == 'g1':
96+
self.ids['Right White Rook'].pos = (conversion.to_number()['f1'][0], conversion.to_number()['f1'][1])
97+
position_dic['h1'] = 'None'
98+
position_dic['f1'] = 'Right White Rook'
99+
if str(pos_chess) == 'c1':
100+
self.ids['Left White Rook'].pos = (conversion.to_number()['d1'][0], conversion.to_number()['d1'][1])
101+
position_dic['a1'] = 'None'
102+
position_dic['d1'] = 'Left White Rook'
103+
if str(pos_chess) == 'g8':
104+
self.ids['Right Black Rook'].pos = (conversion.to_number()['f8'][0], conversion.to_number()['f8'][1])
105+
position_dic['h8'] = 'None'
106+
position_dic['f8'] = 'Right Black Rook'
107+
if str(pos_chess) == 'c8':
108+
self.ids['Left Black Rook'].pos = (conversion.to_number()['d8'][0], conversion.to_number()['d8'][1])
109+
position_dic['a8'] = 'None'
110+
position_dic['d8'] = 'Left Black Rook'
111+
#Updates the Dictionary of all the piece locations
112+
position_dic[str(chess_position_numerical)] = 'None'
113+
position_dic[str(pos_chess)] = str(piece_that_moved)
114+
115+
elif valid_or_not == "New_Piece":
116+
pass
92117
else:
93118
#If the move was not valid
94119

Checking_for_valid_move/checking_for_blocked_path.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ def __init__(self, position_piece, pos_chess):
2727
self.letter_number_of_end = dictionar_of_letters_to_numbers[str(position_piece)[0]]
2828

2929
self.letter_that_stayed_the_same = str(pos_chess)[0]
30-
self.number_of_start = str(pos_chess)[1]
30+
self.number_of_start = int(str(pos_chess)[1])
3131
self.number_of_end = int(str(position_piece)[1])
3232

3333
self.blocked = "No"
@@ -104,7 +104,7 @@ def letter_same(self, position_piece, pos_chess):
104104

105105
self.number_of_start += 1
106106
#Iterates through the squares
107-
while str(self.number_of_start) != str(number_of_end):
107+
while str(self.number_of_start) != str(self.number_of_end):
108108

109109
#Assignes new_number to a square the rook went past
110110
new_number = self.number_of_start

Checking_for_valid_move/king.py

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
from Data_Conversion.difference_for_letter import dictionar_of_letters_to_numbers
2-
2+
from Data_Conversion.position_of_pieces import position_dic
33
def King(position_piece, pos_chess):
44
'''
55
The rules I used to determine the path of the king:
@@ -11,6 +11,9 @@ def King(position_piece, pos_chess):
1111
2. Check if the numeric value of the letter moved up or down by one
1212
if so, Check if the number stayed the same
1313
A. This is to check if the King moved left or right only by one
14+
15+
3. Check if the player is trying to Castle, I hard-coded this in because of the little amount of checks needed
16+
1417
'''
1518

1619
#Step 1 : Check if the number differs by no more or less than one
@@ -31,3 +34,32 @@ def King(position_piece, pos_chess):
3134
#Checks to make sure the numbers are the same
3235
if str(position_piece)[1] == str(pos_chess)[1]:
3336
return True
37+
38+
#Step 3: Checking for a Castle
39+
elif int(dictionar_of_letters_to_numbers[str(position_piece)[0]]) + 2 == int(dictionar_of_letters_to_numbers[str(pos_chess)[0]]) or int(dictionar_of_letters_to_numbers[str(position_piece)[0]]) - 2 == int(dictionar_of_letters_to_numbers[str(pos_chess)[0]]):
40+
#If the piece is a white king
41+
if str(position_piece) == 'e1':
42+
#Checking to see what direction (Right)
43+
if str(pos_chess) == 'g1':
44+
if position_dic['h1'] == "Right White Rook":
45+
if position_dic['f1'] == "None":
46+
return "Castle"
47+
else:
48+
#Checking the swaures, to make sure they are empty
49+
if position_dic['a1'] == "Left White Rook":
50+
if position_dic['d1'] == "None":
51+
if position_dic['b1'] == "None":
52+
return "Castle"
53+
54+
#If the piece is a black King
55+
elif str(position_piece) == 'e8':
56+
if str(pos_chess) == 'g8':
57+
if str(pos_chess) == 'g8':
58+
if position_dic['h8'] == "Right Black Rook":
59+
if position_dic['f8'] == "None":
60+
return "Castle"
61+
else:
62+
if position_dic['a8'] == "Left Black Rook":
63+
if position_dic['d8'] == "None":
64+
if position_dic['b8'] == "None":
65+
return "Castle"
Lines changed: 187 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,187 @@
1+
from Data_Conversion.position_of_pieces import position_dic
2+
from Data_Conversion.difference_for_letter import dictionar_of_letters_to_numbers
3+
4+
'''
5+
Check to see if the king is currently in check
6+
7+
8+
9+
if yes, at the end of every move check again
10+
if still in check, return FALSE and repeat loop
11+
12+
if not in check, end loop and return TRUE
13+
14+
15+
16+
17+
How to check if in check:
18+
19+
ROOK:
20+
21+
Check to the left/right
22+
Check up/down
23+
24+
BISHOP:
25+
26+
Check up/down/left/right
27+
28+
KNIGHT:
29+
30+
CHECK THE FOUR SPOTS IT COULD BE
31+
32+
QUEEN:
33+
CHECK FoR A BISHOP AND A rook
34+
35+
36+
37+
the King is the origin POint
38+
CHECK each squre for each peice:
39+
if another piece 'pops up' before the direction, end the
40+
process becausre that means it is blocked
41+
42+
43+
'''
44+
45+
class end_game():
46+
47+
def __init__(self, turn):
48+
'''
49+
Gets the Position of the King
50+
'''
51+
#Checks to see what player's turn it is, and decides the king's ID based on that Data
52+
if turn == "W":
53+
king_ID = "White King"
54+
#What way the pawns are deadly to the king
55+
self.check_for_pawns = "Up"
56+
else:
57+
king_ID = "Black King"
58+
#What way the pawns are deadly to the king
59+
self.check_for_pawns = "Down"
60+
61+
#Iterates through the board to determine where the king is
62+
for key, value in position_dic.items():
63+
if str(value) == king_ID:
64+
65+
#Assigns this variabel to the square where the king is present
66+
self.king_position = str(key)
67+
68+
self.number_positive = int(self.king_position[1]) + 1
69+
self.number_negative = int(self.king_position[1]) - 1
70+
self.player_turn = turn
71+
self.numeric_value_positive = str(int(dictionar_of_letters_to_numbers[self.king_position[0]]) + 1)
72+
self.numeric_value_negative = str(int(dictionar_of_letters_to_numbers[self.king_position[0]]) - 1)
73+
74+
self.number = self.king_position[1]
75+
self.letter = self.king_position[0]
76+
77+
def rook(self):
78+
'''
79+
CHck if to the left/right wall
80+
check if to the top/bottom wall
81+
'''
82+
numberic = int(self.numeric_value_negative)
83+
if self.numeric_value_negative != '0':
84+
endpoint = 'a' + str(self.number)
85+
for key, value in dictionar_of_letters_to_numbers.items():
86+
if int(value) == numberic:
87+
letter = str(key)
88+
while position_dic[str(letter) + str(self.number) ] == 'None' or str(letter) + str(self.number) == endpoint:
89+
numberic -= 1
90+
for key, value in dictionar_of_letters_to_numbers.items():
91+
if str(value) == numberic:
92+
letter = str(key)
93+
if self.player_turn == 'W':
94+
print("HERE")
95+
if position_dic[str(letter) + str(self.number) ][0] == "L":
96+
if position_dic[str(letter) + str(self.number) ][5] == "B":
97+
if position_dic[str(letter) + str(self.number) ][11] == 'R':
98+
return "False"
99+
else:
100+
pass
101+
else:
102+
pass
103+
104+
elif position_dic[str(letter) + str(self.number) ][0] =="R":
105+
if position_dic[str(letter) + str(self.number) ][6] == "B":
106+
if position_dic[str(letter) + str(self.number) ][12] == 'R':
107+
return "False"
108+
109+
else:
110+
111+
if position_dic[str(letter) + str(self.number) ][0] == "L":
112+
if position_dic[str(letter) + str(self.number) ][5] == "W":
113+
if position_dic[str(letter) + str(self.number) ][11] == 'R':
114+
return "False"
115+
elif position_dic[str(letter) + str(self.number) ][0] =="R":
116+
if position_dic[str(letter) + str(self.number) ][6] == "W":
117+
if position_dic[str(letter) + str(self.number) ][12] == 'R':
118+
119+
return "False"
120+
121+
122+
if self.numeric_value_positive != '9':
123+
'''
124+
CHECK to thE RIGHt
125+
'''
126+
pass
127+
if self.number_positive != 9:
128+
'''
129+
CHeck going DOWN
130+
'''
131+
pass
132+
if self.number_negative != 0:
133+
'''
134+
Check going up
135+
'''
136+
pass
137+
138+
def pawn(self):
139+
140+
if self.check_for_pawns == "Up":
141+
'''
142+
If White
143+
'''
144+
if self.numeric_value_negative != '0':
145+
for key, value in dictionar_of_letters_to_numbers.items():
146+
if str(value) == self.numeric_value_negative:
147+
letter = str(key)
148+
square = str(letter) + str(self.number_positive)
149+
150+
if self.numeric_value_positive != '9':
151+
for key, value in dictionar_of_letters_to_numbers.items():
152+
if str(value) == self.numeric_value_positive:
153+
letter = str(key)
154+
square = str(letter) + str(self.number_positive)
155+
156+
if str(position_dic[square][0]) == "B" and str(position_dic[square][6]) == 'P':
157+
#A Pawn is in that location
158+
return "False"
159+
160+
161+
if self.check_for_pawns == "Down":
162+
'''
163+
If black
164+
'''
165+
if self.numeric_value_negative != '0':
166+
for key, value in dictionar_of_letters_to_numbers.items():
167+
if str(value) == self.numeric_value_negative:
168+
letter = str(key)
169+
square = str(letter) + str(self.number_negative)
170+
171+
if self.numeric_value_positive != '9':
172+
for key, value in dictionar_of_letters_to_numbers.items():
173+
if str(value) == self.numeric_value_positive:
174+
letter = str(key)
175+
square = str(letter) + str(self.number_negative)
176+
177+
if str(position_dic[square][0]) == "W" and str(position_dic[square][6]) == 'P':
178+
#A Pawn is in that location
179+
return "False"
180+
181+
182+
183+
def in_check(self):
184+
check = end_game
185+
if check.pawn(self) != "False":
186+
if check.rook(self) !="False":
187+
return "True"

Checking_for_valid_move/pawn.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
from Data_Conversion.difference_for_letter import dictionar_of_letters_to_numbers
22
from Data_Conversion.position_of_pieces import position_dic
33

4+
45
'''
56
Since the rules of the pawn movement and the movement of capturing is so different, I
67
decided to make two different functions that get called depending if a capturing is happeing
@@ -31,6 +32,7 @@ def negative(self, position_piece, pos_chess):
3132
return "Capture"
3233

3334
def pawn(self, position_piece, pos_chess):
35+
3436
'''
3537
The rules I used to determine the movement of the pawn, when regular are as follows:
3638

Data_Conversion/saved_input.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
['f4', 'Black Pawn5']
1+
['a7', 'Black Pawn1']

pawn_new_piece.kv

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# File name: pawn.py
2+
3+
<new_piece>
4+
5+
FloatLayout:
6+
7+
Label:
8+
pos, 0,0
9+
size_hint: None, None
10+
size: 100,100
11+
text: "YESMAN"
12+
canvas.before:
13+
Rectangle:
14+
pos: self.pos
15+
size: self.size

0 commit comments

Comments
 (0)