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

Function getRandomNeighbor

src/gamesbyexample/slitheringsnakes.py:167–177  ·  view source on GitHub ↗
(x, y)

Source from the content-addressed store, hash-verified

165
166
167def getRandomNeighbor(x, y):
168 while True:
169 direction = random.choice((NORTH, SOUTH, EAST, WEST))
170 if direction == NORTH and y != 0:
171 return (x, y - 1)
172 elif direction == SOUTH and y != HEIGHT - 1:
173 return (x, y + 1)
174 elif direction == EAST and x != WIDTH - 1:
175 return (x + 1, y)
176 elif direction == WEST and x != 0:
177 return (x - 1, y)
178
179
180# If this program was run (instead of imported), run the game:

Callers 1

__init__Method · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected