Open
Conversation
…ates into functions
ageorgou
reviewed
Dec 15, 2021
Contributor
ageorgou
left a comment
There was a problem hiding this comment.
Very nice, your version clearly shows what each part of the code does, through the method names and their docstrings.
Nice use of typing hints.
As some of the lines (especially when calling methods) are quite long, you could break them down, keeping one argument per line, and using some intermediate variables.
For example:
self.update_vel([(other.velocity['x']-self.velocity['x'])*scaling/number_of_boids, (other.velocity['y']-self.velocity['y'])*scaling/number_of_boids])could become
self.updat_vel([
(other.velocity['x']-self.velocity['x'])*scaling/number_of_boids,
(other.velocity['y']-self.velocity['y'])*scaling/number_of_boids
])or
x_velocity_diff = (other.velocity['x']-self.velocity['x'])*scaling/number_of_boids
y_velocity_diff = (other.velocity['y']-self.velocity['y'])*scaling/number_of_boids
self.update_vel(x_velocity_diff, y_velocity_diff)| self.velocity = {'x' : x_velocity, 'y' : y_velocity} | ||
|
|
||
| def update_pos(self): | ||
| self.position['x'] += self.velocity['y'] |
Contributor
There was a problem hiding this comment.
I'm guessing this is a typo!
Suggested change
| self.position['x'] += self.velocity['y'] | |
| self.position['x'] += self.velocity['x'] |
|
|
||
| def away_from_neighbours(self:Boid, other:Boid, number_of_boids:int, distance = 100): | ||
| """Updates the velocity of self so that it moves away from other if other is nearer than distance""" | ||
| if (other.position['x']-self.position['x'])**2 + (other.position['y']-self.position['y'])**2 < distance: |
Contributor
There was a problem hiding this comment.
This line is quite long, and is repeated in the other method. Perhaps it could be extracted into its own method, such as can_see(self:Boid, other:Boid).
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Group 23