MCPcopy Create free account
hub / github.com/ndleah/python-mini-project / getPawnMoves

Method getPawnMoves

Chess_Game/ChessEngine.py:102–125  ·  view source on GitHub ↗
(self, r, c, moves)

Source from the content-addressed store, hash-verified

100
101
102 def getPawnMoves(self, r, c, moves):
103 if self.whiteToMove:
104 if self.board[r-1][c] == "--":
105 moves.append(Move((r, c),(r-1, c), self.board))
106 if r == 6 and self.board[r-2][c] == "--":
107 moves.append(Move((r, c),(r-2, c), self.board))
108 if c-1 >= 0:
109 if self.board[r-1][c-1][0] == 'b':
110 moves.append(Move((r, c),(r-1, c-1), self.board))
111 if c+1 <= 7:
112 if self.board[r-1][c+1][0] == 'b':
113 moves.append(Move((r, c),(r-1, c+1), self.board))
114
115 else:
116 if self.board[r+1][c] == "--":
117 moves.append(Move((r, c),(r+1, c), self.board))
118 if r == 1 and self.board[r+2][c] == "--":
119 moves.append(Move((r, c),(r+2, c), self.board))
120 if c-1 >= 0:
121 if self.board[r+1][c-1][0] == 'w':
122 moves.append(Move((r, c),(r+1, c-1), self.board))
123 if c+1 <= 7:
124 if self.board[r+1][c+1][0] == 'w':
125 moves.append(Move((r, c),(r+1, c+1), self.board))
126
127 def getRookMoves(self, r, c, moves):
128 directions = ((-1, 0), (0, -1), (1, 0), (0, 1))

Callers

nothing calls this directly

Calls 1

MoveClass · 0.85

Tested by

no test coverage detected