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

Function canMoveInDirection

src/gamesbyexample/pegsolitaire.py:87–100  ·  view source on GitHub ↗

Return True if the peg can make the given move.

(board, space, direction)

Source from the content-addressed store, hash-verified

85
86
87def canMoveInDirection(board, space, direction):
88 """Return True if the peg can make the given move."""
89 nextSpace, secondNextSpace = getNeighboringSpaces(space, direction)
90
91 # Check if the neighboring space exists:
92 if nextSpace in ALL_SPACES:
93 # Check if there is a peg in the neighboring space:
94 if board[nextSpace] == PEG:
95 # Check if the neighbor's neighboring space exists:
96 if secondNextSpace in ALL_SPACES:
97 # Check if there is an empty space there:
98 if board[secondNextSpace] == EMPTY:
99 return True
100 return False
101
102
103def getMoveablePegs(board):

Callers 2

getMoveablePegsFunction · 0.85
askForPlayerMoveFunction · 0.85

Calls 1

getNeighboringSpacesFunction · 0.85

Tested by

no test coverage detected