Commit c44d614b authored by Ahmad Reza Cheraghi's avatar Ahmad Reza Cheraghi
Browse files

Upload New File

parent f4b872d1
"""
The particles move randomly and creating in the first half of the simulation round times tiles, particles, and locations.
And in the second round timer particles starts delete the particles, tile, and locaiton.
"""
import logging
import random
E = 0
SE = 1
SW = 2
W = 3
NW = 4
NE = 5
S = 6 # S for stop and not south
direction = [E, SE, SW, W, NW, NE]
def create(world):
copy_particles= world.particles
for particle in copy_particles:
particle.create_tile_in(dir=random.choice([0, 1, 2, 3, 4, 5]))
# particle.create_tile_in(x=random.choice([0, 1, 2, 3, 4, 5]), y=random.choice([0, 2, 4, 6, 8 , 10]))
particle.create_particle_in(dir=random.choice([0, 1, 2, 3, 4, 5]))
# particle.create_particle_in(x=random.choice([0, 1, 2, 3, 4, 5]), y=random.choice([0, 2, 4, 6, 8, 10]))
particle.create_location_in(dir=random.choice([0, 1, 2, 3, 4, 5]))
# particle.create_location_in(x=random.choice([0, 1, 2, 3, 4, 5]), y=random.choice([0, 2, 4, 6, 8 , 10]))
def scenario(sim, world):
two_particle_inverse_walk(world)
if sim.get_actual_round() <= sim.get_max_round() / 2:
create(world)
else:
scan_and_delete_tile(world)
def two_particle_inverse_walk(world):
logging.debug("two_particle_inverse_walk")
if world.get_particle_list()[0].state == E and world.get_particle_list()[1].state == W:
if \
world.get_particle_list()[0].coords[0] == world.max_x_size() / 2 and \
world.get_particle_list()[1].coords[0] == -world.max_x_size() / 2:
logging.info("Changing direction state from EW to WE at coords particle 0 %s and partice 1 %s",
world.particles[0].coords[0], world.particles[1].coords[0])
world.get_particle_list()[0].state = W
world.get_particle_list()[1].state = E
else:
logging.info("Moving particle 0 to E %s and particle 1 to W %s",
world.get_particle_list()[0].coords[0], world.get_particle_list()[1].coords[0])
world.get_particle_list()[0].move_to(E)
world.get_particle_list()[1].move_to(W)
elif world.get_particle_list()[0].state == W and world.get_particle_list()[1].state == E:
if \
world.get_particle_list()[0].coords[0] == -world.max_x_size() / 2 and \
world.get_particle_list()[1].coords[0] == world.max_x_size() / 2:
logging.info("Changing direction state from WE to EW at coords particle 0 %s and partice 1 %s",
world.get_particle_list()[0].coords[0], world.get_particle_list()[1].coords[0])
world.get_particle_list()[0].state = E
world.get_particle_list()[1].state = W
else:
logging.info("Moving particle 0 to W %s and particle 1 to E %s",
world.get_particle_list()[0].coords[0], world.get_particle_list()[1].coords[0])
world.get_particle_list()[0].move_to(W)
world.get_particle_list()[1].move_to(E)
def scan_and_delete_tile(world, hop=1):
for particle in world.get_particle_list():
scanned_list = particle.scan_for_aim_within( hop=hop)
for foundings in scanned_list :
if foundings.type == 'tile':
particle.delete_tile(foundings.id)
elif foundings.type == 'particle':
particle.delete_particle(foundings.id)
elif foundings.type == 'location':
particle.delete_location(foundings.id)
def delete_all (world):
"""
:param self:
:return:
"""
for particle in world.get_particle_list():
particle.create_tile_in(dir=random.choice([0, 1, 2, 3, 4, 5]))
particle.create_tile_in(x=random.choice([0, 1, 2, 3, 4, 5]), y=random.choice([0, 2, 4, 6, 8 , 10]))
#particle.create_particle_in(dir=random.choice([0, 1, 2, 3, 4, 5]))
#particle.create_particle_in(x=random.choice([0, 1, 2, 3, 4, 5]), y=random.choice([0, 2, 4, 6, 8, 10]))
particle.create_location_in(dir=random.choice([0, 1, 2, 3, 4, 5]))
particle.create_location_in(x=random.choice([0, 1, 2, 3, 4, 5]), y=random.choice([0, 2, 4, 6, 8 , 10]))
def random_walk(self):
for particle in self.get_particle_list():
particle.move_to(random.choice([0, 1, 2, 3, 4, 5]))
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