MCPcopy Create free account
hub / github.com/asweigart/PythonStdioGames / getMoveablePegs

Function getMoveablePegs

src/gamesbyexample/pegsolitaire.py:103–118  ·  view source on GitHub ↗

Return a list of spaces that have pegs that can be moved.

(board)

Source from the content-addressed store, hash-verified

101
102
103def 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
121def askForPlayerMove(board):

Callers 1

askForPlayerMoveFunction · 0.85

Calls 1

canMoveInDirectionFunction · 0.85

Tested by

no test coverage detected