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

Method getRookMoves

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

Source from the content-addressed store, hash-verified

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))
129 enemyColor = "b" if self.whiteToMove else "w"
130 for d in directions:
131 for i in range(1, 8):
132 endRow = r + d[0] * i
133 endCol = c + d[1] * i
134 if 0 <= endRow < 8 and 0 <= endCol < 8:
135 endPiece = self.board[endRow][endCol]
136 if endPiece == "--":
137 moves.append(Move((r,c), (endRow, endCol), self.board))
138 elif endPiece[0] == enemyColor:
139 moves.append(Move((r,c), (endRow, endCol), self.board))
140 break
141 else:
142 break
143 else:
144 break
145
146 def getKnightMoves(self, r,c,moves):
147 knightMoves = ((-2, -1), (-2, 1), (-1, -2), (-1, 2), (1, -2), (1, 2), (2, -1), (2,1))

Callers 1

getQueenMovesMethod · 0.95

Calls 1

MoveClass · 0.85

Tested by

no test coverage detected