|
| 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" |
0 commit comments