Compare commits
	
		
			2 Commits
		
	
	
		
			dee0eaa9f9
			...
			15bc179410
		
	
	| Author | SHA1 | Date | |
|---|---|---|---|
| 15bc179410 | |||
| f74aa1f633 | 
| @ -19,8 +19,8 @@ SELECTION_GRAY = (128, 128, 128, 80) | ||||
| SELECTION_BORDER = (80, 80, 90) | ||||
| 
 | ||||
| # Grid settings | ||||
| GRID_WIDTH = 30 | ||||
| GRID_HEIGHT = 25 | ||||
| GRID_WIDTH = 100 | ||||
| GRID_HEIGHT = 100 | ||||
| CELL_SIZE = 20 | ||||
| RENDER_BUFFER = 50 | ||||
| 
 | ||||
|  | ||||
| @ -5,6 +5,7 @@ import pygame | ||||
| import math | ||||
| from config.constants import * | ||||
| from world.base.brain import CellBrain | ||||
| from world.objects import DefaultCell | ||||
| 
 | ||||
| 
 | ||||
| class Renderer: | ||||
| @ -98,6 +99,9 @@ class Renderer: | ||||
|             return | ||||
| 
 | ||||
|         for obj in world.get_objects(): | ||||
|             if not isinstance(obj, DefaultCell): | ||||
|                 continue | ||||
| 
 | ||||
|             obj_x, obj_y = obj.position.get_position() | ||||
|             radius = obj.interaction_radius | ||||
| 
 | ||||
|  | ||||
| @ -350,7 +350,7 @@ class DefaultCell(BaseEntity): | ||||
| 
 | ||||
|         movement_cost = abs(output_data["angular_acceleration"]) + abs(output_data["linear_acceleration"]) | ||||
| 
 | ||||
|         self.energy -= (self.behavioral_model.neural_network.network_cost * 0.03) + 1 + (0.3 * movement_cost) | ||||
|         self.energy -= (self.behavioral_model.neural_network.network_cost * 0.1) + 1 + (0.3 * movement_cost) | ||||
| 
 | ||||
|         return self | ||||
| 
 | ||||
|  | ||||
| @ -5,51 +5,18 @@ from config.constants import MAX_VELOCITY, MAX_ROTATIONAL_VELOCITY | ||||
| 
 | ||||
| class Physics: | ||||
|     """ | ||||
|     Physics | ||||
|     ⠀⠀⢀⣀⢀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⣀⡠⣄⠀⠀⠀⠀⠀ | ||||
|     ⠀⣴⠊⠛⠦⣅⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢸⠃⠈⠈⠳⡄⠀⠀⠀ | ||||
|     ⠸⣿⠀⠀⠀⠉⢹⣆⠀⠀⠀⠠⡶⠖⢦⡄⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠈⢻⡄⠀⠀⠈⡆⠀⠀ | ||||
|     ⠀⠈⣧⠀⠀⠀⠀⠉⠓⠂⠐⠋⠀⠀⢸⣷⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⣴⡆⢀⢰⣶⣄⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢀⡒⠀⣤⢀⠀⠈⡇⠀⠀⠀⢹⡂⠀ | ||||
|     ⠀⠀⢹⣇⠀⠀⠀⠀⠀⠀⠀⠀⠀⠰⠞⠄⠀⠀⠀⠀⠀⠀⠀⣀⣤⣾⠿⠁⠈⠁⠉⠻⢷⠶⠴⢭⡄⠤⡀⠀⠀⠀⠀⠀⢿⡇⠀⠈⢢⠀⣸⡇⠀⠀⠀⠐⠁⠀ | ||||
|     ⠀⠀⠀⢻⠀⠀⠀⠀⠀⠀⠀⠀⢐⡏⡀⠀⠀⠀⠀⠀⠀⣠⡚⠛⠋⠁⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠈⠑⢮⡀⡀⠀⠀⠀⠉⢳⡄⠀⡘⠛⠋⠀⠀⠀⠀⠀⡄⠀ | ||||
|     ⠀⠀⠀⢀⣇⠀⠀⠀⠀⠀⠀⠀⢸⠀⠀⠀⠀⠀⢀⣴⠏⠁⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠘⣌⢂⠀⠀⠀⢸⡇⠀⠀⠀⠀⠀⠀⠀⠀⢰⣧⡅ | ||||
|     ⠀⠀⠀⠀⢻⣄⠀⠀⠀⠀⠀⠀⢸⠀⠀⠀⠀⣠⡾⠁⠀⠀⠀⠀⠀⣠⡴⠖⠤⠴⠤⠶⠀⢄⠀⠀⠀⠀⠀⠀⠈⠓⠀⠀⠀⢸⡇⠀⠀⠀⠀⠀⠀⢠⣤⠞⠵⠁ | ||||
|     ⠀⠀⠀⠀⠀⠻⣦⡀⠀⠀⠀⢰⡺⠀⠀⠀⢀⡾⠇⠀⠀⠀⠀⣠⡾⠋⠀⠀⠀⠀⠀⠀⠀⠀⢹⣀⡀⠀⠀⠀⠀⠀⢱⠀⠀⠘⠛⢧⡀⠀⠀⣀⣴⠟⠁⠀⠀⠀ | ||||
|     ⠀⠀⠀⠀⠀⠀⠈⠓⠖⠶⠶⠵⠃⠀⠀⠀⢺⢈⠀⠀⠀⢀⣰⠏⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠠⠙⢆⠀⠀⠀⠀⠀⠸⣄⠁⠀⠀⠈⠻⠒⠚⠏⠁⠀⠀⠀⠀⠀ | ||||
|     ⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢘⡀⠀⠀⠀⢸⠏⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠸⣡⡀⠀⠀⠀⠀⢸⠂⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀ | ||||
|     ⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢸⠃⠀⠀⣠⡎⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⣸⠀⠀⠀⠀⢻⡁⡀⠀⠀⢀⢸⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀ | ||||
|     ⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢸⡔⠀⠀⡾⠀⠀⠀⠀⢀⡤⠞⠁⠀⠀⠀⠹⠄⠀⠀⠀⠈⢯⠀⠀⠀⣠⣼⠅⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀ | ||||
|     ⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠿⣧⠀⢸⡇⠀⠀⢠⡼⠋⠀⠀⠀⠀⠀⠀⠀⠀⢰⠀⠀⠀⠸⡄⠀⢀⣿⣏⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀ | ||||
|     ⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢿⣄⣸⡁⠀⢀⠾⡆⠇⠀⠀⠀⠀⠀⠀⠀⠀⠀⠐⠀⠀⢠⡣⠀⣸⡿⠂⠁⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀ | ||||
|     ⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠿⣬⠛⠁⡆⠉⡆⠃⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠂⢧⠀⣿⡀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀ | ||||
|     ⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠙⣿⣆⣀⣁⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⣠⠀⢀⣸⣤⣿⠯⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀ | ||||
|     ⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠈⠉⠀⠘⠳⣄⡀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⣠⣴⠿⠋⠛⠛⠃⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀ | ||||
|     ⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠉⠙⠛⠲⠖⠒⠒⠂⠒⠒⠒⠛⠉⠁⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀ | ||||
| 
 | ||||
|     ⣿⣿⣿⣿⣿⣿⣿⣿⠿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿ | ||||
|     ⣿⣿⣿⣿⣿⣿⣹⡏⠀⠈⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿ | ||||
|     ⣿⣿⣿⣿⣿⣿⣿⣿⣧⠀⢸⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿ | ||||
|     ⣿⣿⣿⣿⣿⣿⣿⣿⣿⡇⠀⢻⢿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿ | ||||
|     ⣿⣿⣿⣿⣿⣿⣿⠿⣋⡁⢶⣦⣤⣍⠙⢿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿ | ||||
|     ⣿⣿⣿⣿⣿⣿⠉⡴⣿⡟⢸⣿⣿⡿⣷⡄⢻⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿ | ||||
|     ⣿⣿⣿⣿⣿⡿⢸⣿⣿⡗⣼⣿⣿⣯⣽⢻⡆⢿⣿⣿⣿⣿⣿⣿⣿⣿⣿ | ||||
|     ⣿⣿⣿⣿⣿⡇⣾⣿⣿⣾⣿⣿⣾⣿⣯⣿⣧⠘⣿⣿⣿⣿⣿⣿⣿⣿⣿ | ||||
|     ⣿⣿⣿⣿⡟⣱⣿⣿⣿⣿⣿⣽⣾⣿⣽⢻⣏⡄⣿⢿⣿⣿⣿⣿⣿⣿⣿ | ||||
|     ⣿⣿⣿⡿⢡⣿⣯⣿⣿⡿⣟⣻⣿⣿⢿⣿⣏⢻⠘⣿⣿⣿⣿⣿⣿⣿⣿ | ||||
|     ⣿⣿⠗⠒⣛⢻⣿⣿⣿⡟⢻⣿⣏⣿⣷⣠⣿⡘⡧⡘⢿⣿⣿⣿⣿⣿⣿ | ||||
|     ⠛⠁⢴⠺⢿⡀⠻⣿⢿⡇⣼⠏⠯⠈⢿⡿⢘⣿⡘⣦⡘⣿⣿⣿⣿⣿⣿ | ||||
|     ⠀⠀⠀⠀⠈⢻⡆⠈⠈⢠⡇⠐⠀⠀⠈⠃⢸⣯⣧⠉⣧⠸⣿⣿⣿⣿⣿ | ||||
|     ⡄⣀⢃⠀⠀⣸⣿⣧⡀⣼⣿⡀⠀⠀⢠⡄⠸⣿⣿⣷⢉⠃⣿⣿⣿⣿⣿ | ||||
|     ⡇⢹⣦⡻⣿⣿⣿⢩⣷⣿⣿⣿⣷⣾⣾⠇⣶⣞⡛⣷⣌⡀⣿⣿⣿⣿⣿ | ||||
|     ⡶⢄⠻⣿⣾⣿⠓⠬⠽⠟⢛⣿⣿⣿⣟⢐⢻⣿⣿⣿⠿⢡⣿⣿⣿⣿⣿ | ||||
|     ⣿⣇⢱⠙⢿⣿⣶⣖⣲⣶⣿⣿⡿⢋⣡⣿⣿⣿⣿⡟⢠⣿⣿⣿⣿⣿⣿ | ||||
|     ⣿⣿⣷⣅⢲⣌⠛⠿⠿⠿⢟⠁⣴⣷⣾⣿⣾⡿⠟⣰⣿⣷⣮⣭⣭⣟⣻ | ||||
|     ⣿⣿⣿⣿⣷⣌⡐⠰⣴⣶⠾⠿⢿⠿⠷⠟⠈⣠⣾⣿⣿⣿⣿⣿⣿⣿⣿ | ||||
|     ⣿⣿⣿⣿⣿⣿⣧⠀⠀⠀⠉⠁⠀⢀⣀⣠⣴⣾⣿⣿⣿⣿⣿⣿⣿⣿⣿ | ||||
|     ⣿⣿⣿⣿⣿⣿⣿⣷⣶⣬⣘⣒⠷⢦⣶⣶⣶⣗⣿⣿⣿⣿⣿⣿⣿⣿⣿ | ||||
|     ⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣶⣶⣶⣾⣿⣿⣟⣛⣿⣿⣿⣿⣿⣿ | ||||
|     Simulates basic 2D physics for an object, including linear and rotational motion | ||||
|     with drag effects. | ||||
|     """ | ||||
|     def __init__(self, drag_coefficient: float, rotational_drag: float): | ||||
|         """ | ||||
|         Initialize the Physics object. | ||||
| 
 | ||||
|         Args: | ||||
|             drag_coefficient (float): Linear drag coefficient. | ||||
|             rotational_drag (float): Rotational drag coefficient. | ||||
|         """ | ||||
| 
 | ||||
|         self.drag_coefficient: float = drag_coefficient | ||||
|         self.rotational_drag: float = rotational_drag | ||||
| 
 | ||||
| @ -61,6 +28,17 @@ class Physics: | ||||
| 
 | ||||
| 
 | ||||
|     def move(self, linear_acceleration: float, angular_acceleration: int, rotational_position): | ||||
|         """ | ||||
|         Update the object's velocity and acceleration based on input forces and drag. | ||||
| 
 | ||||
|         Args: | ||||
|             linear_acceleration (float): The applied linear acceleration. | ||||
|             angular_acceleration (int): The applied angular acceleration. | ||||
|             rotational_position: The current rotational position in degrees. | ||||
| 
 | ||||
|         Returns: | ||||
|             tuple: Updated (velocity, acceleration, rotational_velocity, angular_acceleration). | ||||
|         """ | ||||
|         # Apply drag force | ||||
|         drag_coefficient = self.drag_coefficient | ||||
|         drag_x = -self.velocity[0] * drag_coefficient | ||||
|  | ||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user