From ed722319c543cbfae3f69ac35403104ac61d0abe Mon Sep 17 00:00:00 2001 From: Mecaneer23 <74385377+Mecaneer23@users.noreply.github.com> Date: Tue, 14 May 2024 13:48:31 -0500 Subject: [PATCH] feat: ensure food location is always within board --- snake.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/snake.py b/snake.py index 3403dad..568e25a 100755 --- a/snake.py +++ b/snake.py @@ -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: @@ -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