douglascdev / douglascdev/snake

Improve performance for Food's random position initialization

Open
#4 0 comments 0 reactions 0 assignees View on GitHub
enhancement good first issue help wanted
Dominant language
Python
Stars
4
Forks
5
PR merge metrics
No merged PRs in 30d

Description

When a Food object is created, a random generation function is used to create it's position, excluding the snake's position from the possible generated positions:

```
self.rect = random_pos_rect(
Game.DEFAULT_RECT, [sprite.rect for sprite in snake_group.sprites()]
)
```

- Change the way the second argument is passed to this function, passing the group and checking for collisions with it instead, to improve performance.
- Keep the full list of points on screen in memory for the function and only limit the width and height within the generator.
- If the excluded_rects is empty, return a random item of the list without creating the rects_without_collision list.

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.