MCPcopy Create free account
hub / github.com/Mrinank-Bhowmick/python-beginner-projects / Knight

Method Knight

projects/Chess/main.py:177–226  ·  view source on GitHub ↗
(self, x, y, grid)

Source from the content-addressed store, hash-verified

175 return self.vMoves
176
177 def Knight(self, x, y, grid):
178 if (
179 x < 6
180 and y < 7
181 and (grid[x + 2][y + 1] == 0 or not self.sameColor(x + 2, y + 1, grid))
182 ):
183 self.vMoves.append([x + 2, y + 1])
184 if (
185 x < 6
186 and y > 0
187 and (grid[x + 2][y - 1] == 0 or not self.sameColor(x + 2, y - 1, grid))
188 ):
189 self.vMoves.append([x + 2, y - 1])
190 if (
191 x > 1
192 and y < 7
193 and (grid[x - 2][y + 1] == 0 or not self.sameColor(x - 2, y + 1, grid))
194 ):
195 self.vMoves.append([x - 2, y + 1])
196 if (
197 x > 1
198 and y > 0
199 and (grid[x - 2][y - 1] == 0 or not self.sameColor(x - 2, y - 1, grid))
200 ):
201 self.vMoves.append([x - 2, y - 1])
202 if (
203 x < 7
204 and y < 6
205 and (grid[x + 1][y + 2] == 0 or not self.sameColor(x + 1, y + 2, grid))
206 ):
207 self.vMoves.append([x + 1, y + 2])
208 if (
209 x > 0
210 and y < 6
211 and (grid[x - 1][y + 2] == 0 or not self.sameColor(x - 1, y + 2, grid))
212 ):
213 self.vMoves.append([x - 1, y + 2])
214 if (
215 x < 7
216 and y > 1
217 and (grid[x + 1][y - 2] == 0 or not self.sameColor(x + 1, y - 2, grid))
218 ):
219 self.vMoves.append([x + 1, y - 2])
220 if (
221 x > 0
222 and y > 1
223 and (grid[x - 1][y - 2] == 0 or not self.sameColor(x - 1, y - 2, grid))
224 ):
225 self.vMoves.append([x - 1, y - 2])
226 return self.vMoves
227
228 def Pawn(self, x, y, grid):
229 if grid[x][y] == "p":

Callers 1

generateValidMovesMethod · 0.95

Calls 1

sameColorMethod · 0.95

Tested by

no test coverage detected