def test_snake_wall(self): self.board = Board(width=50, height=50) self.board.add_object("snake", Point(x=1, y=30)) snake = self.board.objects['snake'][0] _, _, done, _ = self.board.step(constants.GET_ACTION_MEANING.index("LEFT")) self.board.step(1) self.assertEqual(True, done, "Game over is not detected upon dying") self.assertEqual(False, snake.alive, "Snake didn't die upon hitting the wall")
def test_snake_eat_apple(self): self.board = Board(width=50, height=50) self.board.add_object("snake", Point(x=20, y=33)) self.board.add_object("apple", Point(x=20, y=32)) snake = self.board.objects['snake'][0] _, reward, _, _ = self.board.step(constants.GET_ACTION_MEANING.index("UP")) self.assertEqual(constants.DEFAULT_REWARD_PER_APPLE + constants.DEFAULT_REWARD_PER_STEP, reward, "Snake eating apple incorrect points awarded") self.assertEqual(LEN_SNAKE_START+1, len(snake), "Snake length is not increased after eating apple")
def __init__(self): board = Board() render = SingleImage(board.width, board.height) self._image = np.zeros((board.width, board.height, 3), dtype=np.uint8) super().__init__(board, render)
def setUp(self) -> None: self.board = Board(width=25, height=25)
def __init__(self): board = Board() render = Console() super().__init__(board, render)
def __init__(self, width=None, height=None): self.board = Board(width, height) self.image = np.zeros((self.board.width, self.board.height, 3), dtype=np.uint8)