From 6d748d395f9ff0e20f2a49c0941d1705e098ce59 Mon Sep 17 00:00:00 2001 From: shillerben Date: Sun, 10 Sep 2023 22:19:02 -0500 Subject: [PATCH] Don't run off the edge --- src/server.py | 3 --- src/snakes/starter_snake.py | 12 ++++++++++-- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/src/server.py b/src/server.py index b94898e..806b56a 100644 --- a/src/server.py +++ b/src/server.py @@ -1,4 +1,3 @@ -import logging import os from fastapi import FastAPI, Request @@ -41,5 +40,3 @@ async def identify_server(request: Request, call_next): response = await call_next(request) response.headers["server"] = "shillerben/gitea/starter-snake-python" return response - -logging.getLogger("werkzeug").setLevel(logging.ERROR) diff --git a/src/snakes/starter_snake.py b/src/snakes/starter_snake.py index 2e68dd5..a0330b6 100644 --- a/src/snakes/starter_snake.py +++ b/src/snakes/starter_snake.py @@ -49,8 +49,16 @@ class StarterSnake(Snake): is_move_safe["up"] = False # TODO: Step 1 - Prevent your Battlesnake from moving out of bounds - # board_width = game_state['board']['width'] - # board_height = game_state['board']['height'] + board_width = game_state.board.width + board_height = game_state.board.height + if my_head.x == 0: + is_move_safe["left"] = False + elif my_head.x == board_width - 1: + is_move_safe["right"] = False + if my_head.y == 0: + is_move_safe["down"] = False + elif my_head.y == board_height - 1: + is_move_safe["up"] = False # TODO: Step 2 - Prevent your Battlesnake from colliding with itself # my_body = game_state['you']['body']