Return a list of spaces that have pegs that can be moved.
(board)
| 101 | |
| 102 | |
| 103 | def getMoveablePegs(board): |
| 104 | """Return a list of spaces that have pegs that can be moved.""" |
| 105 | moveablePegs = [] # Contain a list of spaces whose peg can jump. |
| 106 | for space in ALL_SPACES: |
| 107 | if board[space] == EMPTY: |
| 108 | continue # There's no peg here, so it's not a valid move. |
| 109 | |
| 110 | # Determine if the peg at this space can move: |
| 111 | if (canMoveInDirection(board, space, NORTH) |
| 112 | or canMoveInDirection(board, space, SOUTH) |
| 113 | or canMoveInDirection(board, space, WEST) |
| 114 | or canMoveInDirection(board, space, EAST)): |
| 115 | moveablePegs.append(space) |
| 116 | continue |
| 117 | |
| 118 | return moveablePegs |
| 119 | |
| 120 | |
| 121 | def askForPlayerMove(board): |
no test coverage detected