Commit 9d9f8776 authored by Ahmad Reza's avatar Ahmad Reza
Browse files

New feature for the border.

In the config it is possible to choise between two world types: Flat and Mirror.
If the world is flat a particle cannot move outside the border.
If it is mirrored then a particle will show up at the oposite side when it goes outside the border.
parent edddcb8b
......@@ -37,11 +37,11 @@ gui = default_gui
;# Triangular grid default configs:
;grid_class = TriangularGrid
;particle_model_file = 2d_particle.obj
;tile_model_file = 2d_hex_tile.obj
;location_model_file = 2d_location.obj
;grid_size = 100
grid_class = TriangularGrid
particle_model_file = 2d_particle.obj
tile_model_file = 2d_hex_tile.obj
location_model_file = 2d_location.obj
grid_size = 100
;# end of Triangular grid configs
......@@ -55,11 +55,11 @@ gui = default_gui
# ccp grid default configs:
grid_class = CCPGrid
particle_model_file = 3d_particle.obj
tile_model_file = 3d_ccp_tile.obj
location_model_file = 3d_location.obj
grid_size = 10
;grid_class = CCPGrid
;particle_model_file = 3d_particle.obj
;tile_model_file = 3d_ccp_tile.obj
;location_model_file = 3d_location.obj
;grid_size = 10
# end of ccp grid configs
......@@ -111,12 +111,18 @@ render_distance = 1000
## False = Unlimited world size
## True = limited world size
border = False
border = True
## Swarm-World Type Flat=0 Mirrored =1
## Works only with border flag set on True
type = 0
## Swarm-World world size in points
## Works only with border flag set on True
size_x = 2000.0
size_y = 2000.0
size_x = 2.0
size_y = 2.0
size_z = 2.0
## Maximum number of particles that can be created while simulating
max_particles = 100000000
......@@ -140,9 +146,9 @@ tile_mm_size = 2
;solution = marking_3d_local
##Moving
#scenario = lonely_particle
scenario = lonely_particle
#scenario = n_particle_in_line
#solution = random_walk
solution = random_walk
#solution = triangular_round_walk
#solution = random_walk_with_take_and_drop
......@@ -157,8 +163,8 @@ tile_mm_size = 2
## Read and Write
#scenario = two_particles_tiles_markers
#solution = read_write
scenario = test_interfaces
solution = test_all_the_interfaces
;
;scenario = test_interfaces
;solution = test_all_the_interfaces
......@@ -70,7 +70,9 @@ class ConfigData:
self.size_x = config.getfloat("World", "size_x")
self.size_y = config.getfloat("World", "size_y")
self.size_z = config.getfloat("World", "size_z")
self.border = config.getboolean("World", "border")
self.type = config.getboolean("World", "type")
self.max_particles = config.getint("World", "max_particles")
self.memory_limitation = config.getboolean("Matter", "memory_limitation")
......
......@@ -88,7 +88,7 @@ class Particle(matter.Matter):
:return: True: Success Moving; False: Non moving
"""
direction_coord = get_coordinates_in_direction(self.coordinates, direction)
direction, direction_coord = self.check_within_border(direction, direction_coord)
direction_coord = self.check_within_border(direction, direction_coord)
if self.world.grid.are_valid_coordinates(direction_coord) \
and direction_coord not in self.world.particle_map_coordinates:
if self.coordinates in self.world.particle_map_coordinates:
......@@ -116,12 +116,22 @@ class Particle(matter.Matter):
self.world.vis.particle_changed(self.carried_particle)
def check_within_border(self, direction, direction_coord):
if self.world.config_data.border == 1 and \
(abs(direction_coord[0]) > self.world.get_sim_x_size() or abs(
direction_coord[1]) > self.world.get_sim_y_size()):
direction = direction - 3 if direction > 2 else direction + 3
direction_coord = get_coordinates_in_direction(self.coordinates, direction)
return direction, direction_coord
if self.world.config_data.border == 1:
if self.world.config_data.type == 1:
if abs(direction_coord[0]) > self.world.get_world_x_size():
direction_coord = (-1 * (self.coordinates[0] - direction[0]), direction_coord[1], direction_coord[2])
if abs(direction_coord[1]) > self.world.get_world_y_size():
direction_coord = (direction_coord[0], -1* (self.coordinates[1] - direction[1]), direction_coord[2])
if abs(direction_coord[2]) > self.world.get_world_z_size():
direction_coord = (direction_coord[0], direction_coord[1], -1* (self.coordinates[2] - direction[2]))
else:
if abs(direction_coord[0]) > self.world.get_world_x_size():
direction_coord = (self.coordinates[0], direction_coord[1], direction_coord[2])
if abs(direction_coord[1]) > self.world.get_world_y_size():
direction_coord = (direction_coord[0], self.coordinates[1], direction_coord[2])
if abs(direction_coord[2]) > self.world.get_world_z_size():
direction_coord = (direction_coord[0], direction_coord[1], self.coordinates[2])
return direction_coord
def read_from_with(self, target, key=None):
"""
......
......@@ -315,6 +315,13 @@ class World:
"""
return self.config_data.size_y
def get_world_z_size(self):
"""
:return: Returns the maximal z size of the world
"""
return self.config_data.size_z
def get_world_size(self):
"""
:return: Returns the maximal (x,y) size of the world as a tupel
......
......@@ -3,9 +3,7 @@ import random
def solution(world):
dirs = world.grid.get_directions_list()
if world.get_actual_round() % 1 == 0:
for particle in world.get_particle_list():
print(world.get_actual_round()," Particle No.", particle.number)
particle.move_to(random.choice(dirs))
particle.move_to(random.choice(world.grid.get_directions_list()))
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment