Skip to content

Commit

Permalink
feat: ensure food location is always within board
Browse files Browse the repository at this point in the history
  • Loading branch information
mecaneer23 committed May 14, 2024
1 parent ac1cb3c commit ed72231
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions snake.py
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ def __init__(
self._char = char
self._rows = rows
self._cols = cols
self._location = Location(rows // 2, cols // 2)
self._location = Location(cols // 2, rows // 2)
self._color = color

def get_location(self) -> Location:
Expand All @@ -177,8 +177,8 @@ def reroll(self, snake: Snake) -> None:
"""Randomly update the location of the food"""
while True:
loc = Location(
randint(0, self._rows - 1),
randint(0, self._cols - 1),
randint(0, self._rows - 1),
)
if loc in snake:
continue
Expand Down

0 comments on commit ed72231

Please sign in to comment.