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

Method Pawn

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

Source from the content-addressed store, hash-verified

226 return self.vMoves
227
228 def Pawn(self, x, y, grid):
229 if grid[x][y] == "p":
230 if x == 1 and grid[x + 2][y] == 0:
231 self.vMoves.append([x + 2, y])
232 if grid[x + 1][y] == 0:
233 self.vMoves.append([x + 1, y])
234 if (
235 y > 0
236 and x < 7
237 and grid[x + 1][y - 1] != 0
238 and grid[x + 1][y - 1].isupper()
239 ):
240 self.vMoves.append([x + 1, y - 1])
241 if (
242 y < 7
243 and x < 7
244 and grid[x + 1][y + 1] != 0
245 and grid[x + 1][y + 1].isupper()
246 ):
247 self.vMoves.append([x + 1, y + 1])
248 elif grid[x][y] == "P":
249 if x == 6 and grid[x - 2][y] == 0:
250 self.vMoves.append([x - 2, y])
251 if grid[x - 1][y] == 0:
252 self.vMoves.append([x - 1, y])
253 if (
254 x > 0
255 and y > 0
256 and grid[x - 1][y - 1] != 0
257 and grid[x - 1][y - 1].islower()
258 ):
259 self.vMoves.append([x - 1, y - 1])
260 if (
261 x > 0
262 and y < 7
263 and grid[x - 1][y + 1] != 0
264 and grid[x - 1][y + 1].islower()
265 ):
266 self.vMoves.append([x - 1, y + 1])
267
268 for i in range(len(self.vMoves)):
269 if (
270 self.vMoves[i][1] >= 0
271 and self.vMoves[i][0] >= 0
272 and self.vMoves[i][1] < 8
273 and self.vMoves[i][0] < 8
274 ):
275 self.vMoves2.append(self.vMoves[i])
276
277 return self.vMoves2
278
279 def sameColor(self, x, y, grid):
280 if self.white:

Callers 1

generateValidMovesMethod · 0.95

Calls

no outgoing calls

Tested by

no test coverage detected