Skip to content

Commit ed16eb4

Browse files
committed
Increased Code Quality - Still Needs some work but mostly there
1 parent a335ac1 commit ed16eb4

File tree

14 files changed

+399
-462
lines changed

14 files changed

+399
-462
lines changed

Board.py

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,34 +2,34 @@
22
from kivy.uix.screenmanager import Screen
33

44
from Data_Conversion.position_of_mouse import find_position
5-
from Data_Conversion.position_of_pieces import teams_turn
65
from Data_Conversion.position_of_pieces import position_dic
7-
86
from Data_Conversion.chess_coords_to_real_coords import convert_coordinates
7+
98
from valid_move import is_valid_move
109

1110
class Scatter_Text_widget(Screen):
1211

12+
1313
def __init__(self, **kwargs):
1414
#Initializes the class with variables
1515
super(Scatter_Text_widget, self).__init__(**kwargs)
1616

17+
self.position = find_position()
18+
self.position_piece = position_dic
1719
def on_touch_down(self, touch):
1820
#This function gets called when the mouse is pressed
1921

2022
res = super(Scatter_Text_widget, self).on_touch_down(touch)
2123
#This makes sure the labels keep their Scatter Property and the mouse input can be obtained
2224

2325
if res:
24-
position_piece = position_dic
25-
position = find_position()
2626

2727
#Gets the chess coord of where the mouse pressed
28-
pos_chess = position.chess_position(touch.pos)
28+
pos_chess = self.position.chess_position(touch.pos)
2929

3030
#Saves the input to a text file
3131
#Probably a bad way to do this, especially for security concerns
32-
clicked_input = [pos_chess,position_piece[str(pos_chess)]]
32+
clicked_input = [pos_chess,self.position_piece[str(pos_chess)]]
3333

3434
#Writes twrites the input into the file
3535
with open('Data_Conversion\saved_input.txt', 'w') as f:
@@ -41,12 +41,10 @@ def on_touch_up(self, touch):
4141
res = super(Scatter_Text_widget, self).on_touch_up(touch)
4242
#Makes sure Scatter properties and touch input work alligned
4343
if res:
44-
position = find_position()
45-
position_piece = position_dic
4644
conversion = convert_coordinates
4745

4846
#Gets the position of the mouse, and translates it into a chess corrd
49-
pos_chess = position.chess_position(touch.pos)
47+
pos_chess = self.position.chess_position(touch.pos)
5048

5149
#opens the text file, to get the previous data
5250
with open('Data_Conversion\saved_input.txt', 'r') as f:
@@ -67,7 +65,7 @@ def on_touch_up(self, touch):
6765
Checks with another python file to see if the move was valid or not, against all rules of Chess
6866
'''
6967
st = is_valid_move()
70-
valid_or_not = st.main(chess_position_numerical, position_piece, pos_chess, piece_that_moved)
68+
valid_or_not = st.main(chess_position_numerical, self.position_piece, pos_chess, piece_that_moved)
7169

7270
#IF THE MOVE WAS VALID
7371
if valid_or_not == "True":
@@ -80,7 +78,7 @@ def on_touch_up(self, touch):
8078

8179
elif valid_or_not == "True, Captured":
8280
#If the move was valid, and a capture occured
83-
piece_occupied = str(position_piece[pos_chess])
81+
piece_occupied = str(self.position_piece[pos_chess])
8482

8583
#Deletes the piece that was captured
8684
self.ids[piece_occupied].pos = (1000,1000)

Checking_for_valid_move/Queen.py

Lines changed: 7 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,11 @@
11

22
from Checking_for_valid_move.rook import rook
33
from Checking_for_valid_move.bishop import Bishop
4-
def Queen(position_piece, pos_chess):
5-
'''
6-
CHECK Bishop AND Rook
7-
IF ONE IS TRUE;
8-
THEN QUEEN IS TRUE
9-
'''
104

11-
rook_result = rook(position_piece, pos_chess)
12-
Bishop_result = Bishop(position_piece, pos_chess)
13-
14-
if rook_result == True or Bishop_result == True:
15-
return True
16-
17-
else:
18-
return False
5+
def Queen(position_piece, pos_chess, piece_that_moved):
6+
'''
7+
The rules I used to determine the path of the Queen:
8+
1. See if the Rook or the Bishop returns a valid move
9+
'''
10+
if rook(position_piece, pos_chess) == True or Bishop(position_piece, pos_chess, piece_that_moved) == True:
11+
return True

Checking_for_valid_move/bishop.py

Lines changed: 27 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,42 @@
11
from Data_Conversion.difference_for_letter import dictionar_of_letters_to_numbers
22
from Checking_for_valid_move.checking_for_blocked_path import is_path_blocked
33

4-
def Bishop(position_piece, pos_chess):
4+
def Bishop(position_piece, pos_chess, piece_that_moved):
55
'''
6-
NUMBER DID NOT STAY THE SAME
7-
GET DIFFerecne
8-
CALCULATE DIFFerecne for LETTER
9-
CHECK TO SEE IF THAT MAKES SENSE
6+
The Rules I used to determine the path of a Bishop:
7+
8+
1. The number in the chess corrdinates did not stay the same
9+
A. This is to make sure the Bishop did not go straight up/ down or to the left/right
10+
11+
2. Get the difference of the numbers (EXAMPLE: a1 and d4 would have a difference of 3)
12+
A. This is to make sure the move was a correct diagonal, not a random move that wasn't
13+
straight up or down.
14+
15+
3. Calculate the difference of the letters (if a = 1, b = 2 and so on), the example above applies here
16+
A. This is still to make sure the move was a diagonal
17+
18+
4. Check the differences, if they are the same then the move was a correct Diagonal
19+
A. Just like the example had the same difference, it was a correct diagonal
1020
'''
21+
22+
#Step 1: Check if number changed
1123
if str(position_piece)[1] != str(pos_chess)[1]:
1224

25+
#Step two: Get the difference of the numbers
1326
difference_of_number = int(str(position_piece)[1]) - int(str(pos_chess)[1])
27+
28+
#Step 3: Get numeric representation of the letters (Calculate difference in the if statement)
1429
first_letter = dictionar_of_letters_to_numbers[str(position_piece)[0]]
1530
second_letter = dictionar_of_letters_to_numbers[str(pos_chess)[0]]
1631

17-
bishop_path = is_path_blocked.path_bishop()
32+
#Loads in another file, used in the second if statement
33+
bishop_path = is_path_blocked.path_bishop(pos_chess, position_piece, piece_that_moved)
1834

35+
#Step 4: Check the differences
1936
if abs(first_letter - second_letter) == abs(difference_of_number):
20-
if bishop_path.recurse(position_piece, pos_chess, difference_of_number, first_letter, second_letter) == "True":
21-
22-
return True
23-
else:
24-
return False
25-
else:
2637

27-
return False
28-
else:
38+
#If they equal, check to make sure the Bishop's path is clear so it doesn't jump over anything
39+
if bishop_path.recurse(difference_of_number, first_letter, second_letter) == "True":
2940

30-
return False
41+
#If the path was clear, return a legal Move
42+
return True

Checking_for_valid_move/check.py

Lines changed: 0 additions & 34 deletions
This file was deleted.

0 commit comments

Comments
 (0)