Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
Ahmad Reza Cheraghi
swarm-sim
Commits
6b638d6d
Commit
6b638d6d
authored
Sep 26, 2019
by
Ahmad Reza
Browse files
Renamed the attributes coords to coordinations and alpha to transparency
parent
2b269a47
Changes
10
Hide whitespace changes
Inline
Side-by-side
lib/csv_generator.py
View file @
6b638d6d
"""
TODO:
1- Order the names based on particles, markers, and tiles and
alpha
betic
1- Order the names based on particles, markers, and tiles and
transparency
betic
2- A new column called round_success
3- On demand extenstion of the metrics.
...
...
lib/marker.py
View file @
6b638d6d
...
...
@@ -6,8 +6,8 @@ from lib.swarm_sim_header import *
class
Marker
(
matter
.
Matter
):
"""In the classe marker all the methods for the characterstic of a marker is included"""
def
__init__
(
self
,
world
,
x
,
y
,
color
=
black
,
alpha
=
1
):
def
__init__
(
self
,
world
,
x
,
y
,
color
=
black
,
transparency
=
1
):
"""Initializing the marker constructor"""
super
().
__init__
(
world
,
(
x
,
y
),
color
,
alpha
,
type
=
"marker"
,
mm_size
=
world
.
config_data
.
marker_mm_size
)
super
().
__init__
(
world
,
(
x
,
y
),
color
,
transparency
,
type
=
"marker"
,
mm_size
=
world
.
config_data
.
marker_mm_size
)
lib/matter.py
View file @
6b638d6d
...
...
@@ -7,42 +7,42 @@ from lib.swarm_sim_header import *
class
Matter
:
"""In the classe marker all the methods for the characterstic of a marker is included"""
def
__init__
(
self
,
world
,
coords
,
color
=
black
,
alpha
=
1
,
type
=
None
,
mm_size
=
100
):
def
__init__
(
self
,
world
,
coord
inate
s
,
color
=
black
,
transparency
=
1
,
type
=
None
,
mm_size
=
100
):
"""Initializing the marker constructor"""
self
.
coords
=
coords
self
.
coord
inate
s
=
coord
inate
s
self
.
color
=
color_map
[
color
]
self
.
__id
=
str
(
uuid
.
uuid4
())
self
.
world
=
world
self
.
_memory
=
{}
self
.
__
alpha
=
alpha
self
.
__
transparency
=
transparency
self
.
type
=
type
self
.
memory_limitation
=
world
.
config_data
.
memory_limitation
self
.
mm_size
=
mm_size
self
.
modified
=
False
self
.
created
=
False
def
set_
alpha
(
self
,
alpha
):
def
set_
transparency
(
self
,
transparency
):
"""
Set the
alpha
value of the particle
Set the
transparency
value of the particle
:param
alpha: The alpha
of the particle
:param
transparency: The transparency
of the particle
:return: None
"""
if
(
0
<=
alpha
<=
1
):
self
.
__
alpha
=
round
(
alpha
,
2
)
elif
alpha
<
0
:
self
.
__
alpha
=
0
elif
alpha
>
1
:
self
.
__
alpha
=
1
if
(
0
<=
transparency
<=
1
):
self
.
__
transparency
=
round
(
transparency
,
2
)
elif
transparency
<
0
:
self
.
__
transparency
=
0
elif
transparency
>
1
:
self
.
__
transparency
=
1
self
.
touch
()
def
get_
alpha
(
self
):
def
get_
transparency
(
self
):
"""
Returns the
alpha
value of the particle
Returns the
transparency
value of the particle
:return:
alpha
:return:
transparency
"""
return
round
(
self
.
__
alpha
,
2
)
return
round
(
self
.
__
transparency
,
2
)
def
read_memory_with
(
self
,
key
):
"""
...
...
lib/particle.py
View file @
6b638d6d
...
...
@@ -16,9 +16,9 @@ from lib.swarm_sim_header import *
class
Particle
(
matter
.
Matter
):
"""In the classe marker all the methods for the characterstic of a marker is included"""
def
__init__
(
self
,
world
,
x
,
y
,
color
=
black
,
alpha
=
1
,
particle_counter
=
0
):
def
__init__
(
self
,
world
,
x
,
y
,
color
=
black
,
transparency
=
1
,
particle_counter
=
0
):
"""Initializing the marker constructor"""
super
().
__init__
(
world
,
(
x
,
y
),
color
,
alpha
,
super
().
__init__
(
world
,
(
x
,
y
),
color
,
transparency
,
type
=
"particle"
,
mm_size
=
world
.
config_data
.
particle_mm_size
)
self
.
number
=
particle_counter
self
.
__isCarried
=
False
...
...
@@ -53,7 +53,7 @@ class Particle(matter.Matter):
:return: True: On a tile; False: Not on a Tile
"""
if
self
.
coords
in
self
.
world
.
tile_map_coords
:
if
self
.
coord
inate
s
in
self
.
world
.
tile_map_coord
inate
s
:
return
True
else
:
return
False
...
...
@@ -64,7 +64,7 @@ class Particle(matter.Matter):
:return: True: On a particle; False: Not on a particle
"""
if
self
.
coords
in
self
.
world
.
particle_map_coords
:
if
self
.
coord
inate
s
in
self
.
world
.
particle_map_coord
inate
s
:
return
True
else
:
return
False
...
...
@@ -75,7 +75,7 @@ class Particle(matter.Matter):
:return: True: On a marker; False: Not on a marker
"""
if
self
.
coords
in
self
.
world
.
marker_map_coords
:
if
self
.
coord
inate
s
in
self
.
world
.
marker_map_coord
inate
s
:
return
True
else
:
return
False
...
...
@@ -87,16 +87,16 @@ class Particle(matter.Matter):
:param direction: The directionection must be either: E, SE, SW, W, NW, or NE
:return: True: Success Moving; False: Non moving
"""
direction_coord
=
get_coords_in_direction
(
self
.
coords
,
direction
)
direction_coord
=
get_coord
inate
s_in_direction
(
self
.
coord
inate
s
,
direction
)
direction
,
direction_coord
=
self
.
check_within_border
(
direction
,
direction_coord
)
if
check_values_are_coordinates
(
direction_coord
[
0
],
direction_coord
[
1
]):
if
self
.
coords
in
self
.
world
.
particle_map_coords
:
del
self
.
world
.
particle_map_coords
[
self
.
coords
]
if
self
.
coord
inate
s
in
self
.
world
.
particle_map_coord
inate
s
:
del
self
.
world
.
particle_map_coord
inate
s
[
self
.
coord
inate
s
]
if
not
direction_coord
in
self
.
world
.
particle_map_coords
:
self
.
coords
=
direction_coord
self
.
world
.
particle_map_coords
[
self
.
coords
]
=
self
if
not
direction_coord
in
self
.
world
.
particle_map_coord
inate
s
:
self
.
coord
inate
s
=
direction_coord
self
.
world
.
particle_map_coord
inate
s
[
self
.
coord
inate
s
]
=
self
logging
.
info
(
"particle %s successfully moved to %s"
,
str
(
self
.
get_id
()),
direction
)
self
.
world
.
csv_round
.
update_metrics
(
steps
=
1
)
self
.
csv_particle_writer
.
write_particle
(
steps
=
1
)
...
...
@@ -107,17 +107,17 @@ class Particle(matter.Matter):
def
check_for_carried_tile_or_particle
(
self
):
if
self
.
carried_tile
is
not
None
:
self
.
carried_tile
.
coords
=
self
.
coords
self
.
carried_tile
.
coord
inate
s
=
self
.
coord
inate
s
self
.
carried_tile
.
touch
()
elif
self
.
carried_particle
is
not
None
:
self
.
carried_particle
.
coords
=
self
.
coords
self
.
carried_particle
.
coord
inate
s
=
self
.
coord
inate
s
self
.
carried_particle
.
touch
()
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_coords_in_direction
(
self
.
coords
,
direction
)
direction_coord
=
get_coord
inate
s_in_direction
(
self
.
coord
inate
s
,
direction
)
return
direction
,
direction_coord
def
move_to_in_bounds
(
self
,
direction
):
...
...
@@ -127,8 +127,8 @@ class Particle(matter.Matter):
:param direction: The directionection must be either: E, SE, SW, W, NW, or NE
:return: True: Success Moving; False: Non moving
"""
direction_coord
=
get_coords_in_direction
(
self
.
coords
,
direction
)
sim_coord
=
coords_to_sim
(
direction_coord
)
direction_coord
=
get_coord
inate
s_in_direction
(
self
.
coord
inate
s
,
direction
)
sim_coord
=
coord
inate
s_to_sim
(
direction_coord
)
if
self
.
world
.
get_sim_x_size
()
>=
abs
(
sim_coord
[
0
])
and
\
self
.
world
.
get_sim_y_size
()
>=
abs
(
sim_coord
[
1
]):
return
self
.
move_to
(
direction
)
...
...
@@ -169,9 +169,9 @@ class Particle(matter.Matter):
:param direction: the directionection to check if a matter is there
:return: True: if a matter is there, False: if not
"""
if
get_coords_in_direction
(
self
.
coords
,
direction
)
in
self
.
world
.
get_tile_map_coords
()
\
or
get_coords_in_direction
(
self
.
coords
,
direction
)
in
self
.
world
.
get_particle_map_coords
()
\
or
get_coords_in_direction
(
self
.
coords
,
direction
)
in
self
.
world
.
get_marker_map_coords
():
if
get_coord
inate
s_in_direction
(
self
.
coord
inate
s
,
direction
)
in
self
.
world
.
get_tile_map_coord
inate
s
()
\
or
get_coord
inate
s_in_direction
(
self
.
coord
inate
s
,
direction
)
in
self
.
world
.
get_particle_map_coord
inate
s
()
\
or
get_coord
inate
s_in_direction
(
self
.
coord
inate
s
,
direction
)
in
self
.
world
.
get_marker_map_coord
inate
s
():
return
True
else
:
return
False
...
...
@@ -181,7 +181,7 @@ class Particle(matter.Matter):
:param direction: the directionection to check if a tile is there
:return: True: if a tile is there, False: if not
"""
if
get_coords_in_direction
(
self
.
coords
,
direction
)
in
self
.
world
.
get_tile_map_coords
():
if
get_coord
inate
s_in_direction
(
self
.
coord
inate
s
,
direction
)
in
self
.
world
.
get_tile_map_coord
inate
s
():
return
True
else
:
return
False
...
...
@@ -191,7 +191,7 @@ class Particle(matter.Matter):
:param direction: the directionection to check if a particle is there
:return: True: if a particle is there, False: if not
"""
if
get_coords_in_direction
(
self
.
coords
,
direction
)
in
self
.
world
.
get_particle_map_coords
():
if
get_coord
inate
s_in_direction
(
self
.
coord
inate
s
,
direction
)
in
self
.
world
.
get_particle_map_coord
inate
s
():
return
True
else
:
return
False
...
...
@@ -201,48 +201,48 @@ class Particle(matter.Matter):
:param direction: the directionection to check if a marker is there
:return: True: if a marker is there, False: if not
"""
if
get_coords_in_direction
(
self
.
coords
,
direction
)
in
self
.
world
.
get_marker_map_coords
():
if
get_coord
inate
s_in_direction
(
self
.
coord
inate
s
,
direction
)
in
self
.
world
.
get_marker_map_coord
inate
s
():
return
True
else
:
return
False
def
get_matter_in
(
self
,
direction
=
E
):
if
get_coords_in_direction
(
self
.
coords
,
direction
)
in
self
.
world
.
get_tile_map_coords
():
return
self
.
world
.
get_tile_map_coords
()[
get_coords_in_direction
(
self
.
coords
,
direction
)]
elif
get_coords_in_direction
(
self
.
coords
,
direction
)
in
self
.
world
.
get_particle_map_coords
():
return
self
.
world
.
get_particle_map_coords
()[
get_coords_in_direction
(
self
.
coords
,
direction
)]
elif
get_coords_in_direction
(
self
.
coords
,
direction
)
in
self
.
world
.
get_marker_map_coords
():
return
self
.
world
.
get_marker_map_coords
()[
get_coords_in_direction
(
self
.
coords
,
direction
)]
if
get_coord
inate
s_in_direction
(
self
.
coord
inate
s
,
direction
)
in
self
.
world
.
get_tile_map_coord
inate
s
():
return
self
.
world
.
get_tile_map_coord
inate
s
()[
get_coord
inate
s_in_direction
(
self
.
coord
inate
s
,
direction
)]
elif
get_coord
inate
s_in_direction
(
self
.
coord
inate
s
,
direction
)
in
self
.
world
.
get_particle_map_coord
inate
s
():
return
self
.
world
.
get_particle_map_coord
inate
s
()[
get_coord
inate
s_in_direction
(
self
.
coord
inate
s
,
direction
)]
elif
get_coord
inate
s_in_direction
(
self
.
coord
inate
s
,
direction
)
in
self
.
world
.
get_marker_map_coord
inate
s
():
return
self
.
world
.
get_marker_map_coord
inate
s
()[
get_coord
inate
s_in_direction
(
self
.
coord
inate
s
,
direction
)]
else
:
return
False
def
get_tile_in
(
self
,
direction
=
E
):
if
get_coords_in_direction
(
self
.
coords
,
direction
)
in
self
.
world
.
get_tile_map_coords
():
return
self
.
world
.
get_tile_map_coords
()[
get_coords_in_direction
(
self
.
coords
,
direction
)]
if
get_coord
inate
s_in_direction
(
self
.
coord
inate
s
,
direction
)
in
self
.
world
.
get_tile_map_coord
inate
s
():
return
self
.
world
.
get_tile_map_coord
inate
s
()[
get_coord
inate
s_in_direction
(
self
.
coord
inate
s
,
direction
)]
else
:
return
False
def
get_particle_in
(
self
,
direction
=
E
):
if
get_coords_in_direction
(
self
.
coords
,
direction
)
in
self
.
world
.
get_particle_map_coords
():
return
self
.
world
.
get_particle_map_coords
()[
get_coords_in_direction
(
self
.
coords
,
direction
)]
if
get_coord
inate
s_in_direction
(
self
.
coord
inate
s
,
direction
)
in
self
.
world
.
get_particle_map_coord
inate
s
():
return
self
.
world
.
get_particle_map_coord
inate
s
()[
get_coord
inate
s_in_direction
(
self
.
coord
inate
s
,
direction
)]
else
:
return
False
def
get_marker_in
(
self
,
direction
=
E
):
if
get_coords_in_direction
(
self
.
coords
,
direction
)
in
self
.
world
.
get_marker_map_coords
():
return
self
.
world
.
get_marker_map_coords
()[
get_coords_in_direction
(
self
.
coords
,
direction
)]
if
get_coord
inate
s_in_direction
(
self
.
coord
inate
s
,
direction
)
in
self
.
world
.
get_marker_map_coord
inate
s
():
return
self
.
world
.
get_marker_map_coord
inate
s
()[
get_coord
inate
s_in_direction
(
self
.
coord
inate
s
,
direction
)]
else
:
return
False
def
get_marker
(
self
):
if
self
.
coords
in
self
.
world
.
marker_map_coords
:
return
self
.
world
.
get_marker_map_coords
()[
self
.
coords
]
if
self
.
coord
inate
s
in
self
.
world
.
marker_map_coord
inate
s
:
return
self
.
world
.
get_marker_map_coord
inate
s
()[
self
.
coord
inate
s
]
else
:
return
False
def
get_tile
(
self
):
if
self
.
self
.
coords
in
self
.
world
.
get_tile_map_coords
():
return
self
.
world
.
get_tile_map_coords
()[
self
.
coords
]
if
self
.
self
.
coord
inate
s
in
self
.
world
.
get_tile_map_coord
inate
s
():
return
self
.
world
.
get_tile_map_coord
inate
s
()[
self
.
coord
inate
s
]
else
:
return
False
...
...
@@ -307,28 +307,28 @@ class Particle(matter.Matter):
:param hop: The hop distance from thee actual position of the scanning particle
:return: A list of the founded matters
"""
starting_x
=
self
.
coords
[
0
]
starting_y
=
self
.
coords
[
1
]
starting_x
=
self
.
coord
inate
s
[
0
]
starting_y
=
self
.
coord
inate
s
[
1
]
scanned_list
=
[]
logging
.
info
(
"particle on %s is scanning for %s in %i hops"
,
str
(
self
.
coords
),
matter
,
hop
)
logging
.
info
(
"particle on %s is scanning for %s in %i hops"
,
str
(
self
.
coord
inate
s
),
matter
,
hop
)
if
matter
==
"particles"
:
scanned_list
=
global_scanning
(
self
.
world
.
particle_map_coords
,
hop
,
starting_x
,
starting_y
)
scanned_list
=
global_scanning
(
self
.
world
.
particle_map_coord
inate
s
,
hop
,
starting_x
,
starting_y
)
elif
matter
==
"tiles"
:
scanned_list
=
global_scanning
(
self
.
world
.
tile_map_coords
,
hop
,
starting_x
,
starting_y
)
scanned_list
=
global_scanning
(
self
.
world
.
tile_map_coord
inate
s
,
hop
,
starting_x
,
starting_y
)
elif
matter
==
"markers"
:
scanned_list
=
global_scanning
(
self
.
world
.
marker_map_coords
,
hop
,
starting_x
,
starting_y
)
scanned_list
=
global_scanning
(
self
.
world
.
marker_map_coord
inate
s
,
hop
,
starting_x
,
starting_y
)
else
:
scanned_list
=
global_scanning
(
self
.
world
.
particle_map_coords
,
hop
,
starting_x
,
starting_y
)
scanned_list
=
global_scanning
(
self
.
world
.
particle_map_coord
inate
s
,
hop
,
starting_x
,
starting_y
)
if
scanned_list
is
not
None
:
scanned_list
.
extend
(
global_scanning
(
self
.
world
.
tile_map_coords
,
hop
,
starting_x
,
starting_y
))
scanned_list
.
extend
(
global_scanning
(
self
.
world
.
marker_map_coords
,
hop
,
starting_x
,
starting_y
))
scanned_list
.
extend
(
global_scanning
(
self
.
world
.
tile_map_coord
inate
s
,
hop
,
starting_x
,
starting_y
))
scanned_list
.
extend
(
global_scanning
(
self
.
world
.
marker_map_coord
inate
s
,
hop
,
starting_x
,
starting_y
))
else
:
scanned_list
=
global_scanning
(
self
.
world
.
tile_map_coords
,
hop
,
starting_x
,
starting_y
)
scanned_list
=
global_scanning
(
self
.
world
.
tile_map_coord
inate
s
,
hop
,
starting_x
,
starting_y
)
if
scanned_list
is
not
None
:
scanned_list
.
extend
(
global_scanning
(
self
.
world
.
marker_map_coords
,
hop
,
starting_x
,
starting_y
))
scanned_list
.
extend
(
global_scanning
(
self
.
world
.
marker_map_coord
inate
s
,
hop
,
starting_x
,
starting_y
))
else
:
scanned_list
=
global_scanning
(
self
.
world
.
marker_map_coords
,
hop
,
starting_x
,
starting_y
)
scanned_list
=
global_scanning
(
self
.
world
.
marker_map_coord
inate
s
,
hop
,
starting_x
,
starting_y
)
if
scanned_list
is
not
None
:
return
scanned_list
else
:
...
...
@@ -431,48 +431,48 @@ class Particle(matter.Matter):
scanned_list
=
self
.
scan_for_matters_in
(
matter
=
'markers'
,
hop
=
hop
)
return
scanned_list
def
take_me
(
self
,
coords
=
0
):
def
take_me
(
self
,
coord
inate
s
=
0
):
"""
The particle is getting taken from the the other particle on the given coordinate
:param coords: Coordination of particle that should be taken
:param coord
inate
s: Coordination of particle that should be taken
:return: True: Successful taken; False: Cannot be taken or wrong Coordinates
"""
if
not
self
.
__isCarried
:
if
self
.
coords
in
self
.
world
.
particle_map_coords
:
del
self
.
world
.
particle_map_coords
[
self
.
coords
]
if
self
.
coord
inate
s
in
self
.
world
.
particle_map_coord
inate
s
:
del
self
.
world
.
particle_map_coord
inate
s
[
self
.
coord
inate
s
]
self
.
__isCarried
=
True
self
.
coords
=
coords
self
.
set_
alpha
(
0.5
)
self
.
coord
inate
s
=
coord
inate
s
self
.
set_
transparency
(
0.5
)
self
.
touch
()
return
True
else
:
return
False
def
drop_me
(
self
,
coords
):
def
drop_me
(
self
,
coord
inate
s
):
"""
The actual particle is getting dropped
:param coords: the given position
:param coord
inate
s: the given position
:return: None
"""
self
.
world
.
particle_map_coords
[
coords
]
=
self
self
.
coords
=
coords
self
.
world
.
particle_map_coord
inate
s
[
coord
inate
s
]
=
self
self
.
coord
inate
s
=
coord
inate
s
self
.
__isCarried
=
False
self
.
set_
alpha
(
1
)
self
.
set_
transparency
(
1
)
self
.
touch
()
def
create_tile
(
self
,
color
=
gray
,
alpha
=
1
):
def
create_tile
(
self
,
color
=
gray
,
transparency
=
1
):
"""
Creates a tile on the particles actual position
:return: New Tile or False
"""
logging
.
info
(
"Going to create a tile on position %s"
,
str
(
self
.
coords
))
new_tile
=
self
.
world
.
add_tile
(
self
.
coords
[
0
],
self
.
coords
[
1
],
color
,
alpha
)
logging
.
info
(
"Going to create a tile on position %s"
,
str
(
self
.
coord
inate
s
))
new_tile
=
self
.
world
.
add_tile
(
self
.
coord
inate
s
[
0
],
self
.
coord
inate
s
[
1
],
color
,
transparency
)
if
new_tile
:
self
.
world
.
tile_map_coords
[
self
.
coords
[
0
],
self
.
coords
[
1
]].
created
=
True
self
.
world
.
tile_map_coord
inate
s
[
self
.
coord
inate
s
[
0
],
self
.
coord
inate
s
[
1
]].
created
=
True
self
.
csv_particle_writer
.
write_particle
(
tile_created
=
1
)
self
.
world
.
csv_round
.
update_tiles_num
(
len
(
self
.
world
.
get_tiles_list
()))
self
.
world
.
csv_round
.
update_metrics
(
tile_created
=
1
)
...
...
@@ -480,7 +480,7 @@ class Particle(matter.Matter):
else
:
return
False
def
create_tile_in
(
self
,
direction
=
None
,
color
=
gray
,
alpha
=
1
):
def
create_tile_in
(
self
,
direction
=
None
,
color
=
gray
,
transparency
=
1
):
"""
Creates a tile either in a given directionection
...
...
@@ -490,10 +490,10 @@ class Particle(matter.Matter):
logging
.
info
(
"particle with id %s is"
,
self
.
get_id
())
logging
.
info
(
"Going to create a tile in %s "
,
str
(
direction
)
)
if
direction
!=
None
:
coords
=
get_coords_in_direction
(
self
.
coords
,
direction
)
new_tile
=
self
.
world
.
add_tile
(
coords
[
0
],
coords
[
1
],
color
,
alpha
)
coord
inate
s
=
get_coord
inate
s_in_direction
(
self
.
coord
inate
s
,
direction
)
new_tile
=
self
.
world
.
add_tile
(
coord
inate
s
[
0
],
coord
inate
s
[
1
],
color
,
transparency
)
if
new_tile
:
self
.
world
.
tile_map_coords
[
coords
[
0
],
coords
[
1
]].
created
=
True
self
.
world
.
tile_map_coord
inate
s
[
coord
inate
s
[
0
],
coord
inate
s
[
1
]].
created
=
True
logging
.
info
(
"Tile is created"
)
self
.
world
.
new_tile_flag
=
True
self
.
csv_particle_writer
.
write_particle
(
tile_created
=
1
)
...
...
@@ -506,7 +506,7 @@ class Particle(matter.Matter):
logging
.
info
(
"Not created tile "
)
return
False
def
create_tile_on
(
self
,
x
=
None
,
y
=
None
,
color
=
gray
,
alpha
=
1
):
def
create_tile_on
(
self
,
x
=
None
,
y
=
None
,
color
=
gray
,
transparency
=
1
):
"""
Creates a tile either on a given x,y coordinates
...
...
@@ -517,21 +517,21 @@ class Particle(matter.Matter):
logging
.
info
(
"particle with id %s is"
,
self
.
get_id
())
if
x
is
not
None
and
y
is
not
None
:
coords
=
(
x
,
y
)
coord
inate
s
=
(
x
,
y
)
if
check_values_are_coordinates
(
x
,
y
):
logging
.
info
(
"Going to create a tile on position \(%i , %i\)"
,
x
,
y
)
if
self
.
world
.
add_tile
(
coords
[
0
],
coords
[
1
],
color
,
alpha
)
==
True
:
self
.
world
.
tile_map_coords
[
coords
[
0
],
coords
[
1
]].
created
=
True
if
self
.
world
.
add_tile
(
coord
inate
s
[
0
],
coord
inate
s
[
1
],
color
,
transparency
)
==
True
:
self
.
world
.
tile_map_coord
inate
s
[
coord
inate
s
[
0
],
coord
inate
s
[
1
]].
created
=
True
self
.
world
.
new_tile_flag
=
True
self
.
csv_particle_writer
.
write_particle
(
tile_created
=
1
)
self
.
world
.
csv_round
.
update_tiles_num
(
len
(
self
.
world
.
get_tiles_list
())
)
self
.
world
.
csv_round
.
update_metrics
(
tile_created
=
1
)
return
True
else
:
logging
.
info
(
"Not created tile on coords \(%i , %i\)"
,
y
,
x
)
logging
.
info
(
"Not created tile on coord
inate
s \(%i , %i\)"
,
y
,
x
)
return
False
else
:
logging
.
info
(
"Not created tile on coords \(%i , %i\)"
,
y
,
x
)
logging
.
info
(
"Not created tile on coord
inate
s \(%i , %i\)"
,
y
,
x
)
return
False
def
delete_tile
(
self
):
...
...
@@ -542,8 +542,8 @@ class Particle(matter.Matter):
"""
logging
.
info
(
"Particle %s is"
,
self
.
get_id
())
logging
.
info
(
"is going to delete a tile on current position"
)
if
self
.
coords
in
self
.
world
.
get_tile_map_coords
():
if
self
.
world
.
remove_tile_on
(
self
.
coords
):
if
self
.
coord
inate
s
in
self
.
world
.
get_tile_map_coord
inate
s
():
if
self
.
world
.
remove_tile_on
(
self
.
coord
inate
s
):
self
.
csv_particle_writer
.
write_particle
(
tile_deleted
=
1
)
return
True
else
:
...
...
@@ -574,20 +574,20 @@ class Particle(matter.Matter):
:return: True: Deleting successful; False: Deleting unsuccessful
"""
coords
=
()
coord
inate
s
=
()
if
direction
is
not
None
:
coords
=
get_coords_in_direction
(
self
.
coords
,
direction
)
coord
inate
s
=
get_coord
inate
s_in_direction
(
self
.
coord
inate
s
,
direction
)
logging
.
info
(
"Deleting tile in %s directionection"
,
str
(
direction
))
if
coords
is
not
None
:
if
self
.
world
.
remove_tile_on
(
coords
):
logging
.
info
(
"Deleted tile with tile on coords %s"
,
str
(
coords
))
if
coord
inate
s
is
not
None
:
if
self
.
world
.
remove_tile_on
(
coord
inate
s
):
logging
.
info
(
"Deleted tile with tile on coord
inate
s %s"
,
str
(
coord
inate
s
))
self
.
csv_particle_writer
.
write_particle
(
tile_deleted
=
1
)
return
True
else
:
logging
.
info
(
"Could not delet tile on coords %s"
,
str
(
coords
))
logging
.
info
(
"Could not delet tile on coord
inate
s %s"
,
str
(
coord
inate
s
))
return
False
else
:
logging
.
info
(
"Could not delet tile on coords %s"
,
str
(
coords
))
logging
.
info
(
"Could not delet tile on coord
inate
s %s"
,
str
(
coord
inate
s
))
return
False
def
delete_tile_on
(
self
,
x
=
None
,
y
=
None
):
...
...
@@ -598,18 +598,18 @@ class Particle(matter.Matter):
:param y: y coordinate
:return: True: Deleting successful; False: Deleting unsuccessful
"""
coords
=
()
coord
inate
s
=
()
if
x
is
not
None
and
y
is
not
None
:
coords
=
(
x
,
y
)
if
self
.
world
.
remove_tile_on
(
coords
):
logging
.
info
(
"Deleted tile with tile on coords %s"
,
str
(
coords
))
coord
inate
s
=
(
x
,
y
)
if
self
.
world
.
remove_tile_on
(
coord
inate
s
):
logging
.
info
(
"Deleted tile with tile on coord
inate
s %s"
,
str
(
coord
inate
s
))
self
.
csv_particle_writer
.
write_particle
(
tile_deleted
=
1
)
return
True
else
:
logging
.
info
(
"Could not delet tile on coords %s"
,
str
(
coords
))
logging
.
info
(
"Could not delet tile on coord
inate
s %s"
,
str
(
coord
inate
s
))
return
False
else
:
logging
.
info
(
"Could not delet tile on coords %s"
,
str
(
coords
))
logging
.
info
(
"Could not delet tile on coord
inate
s %s"
,
str
(
coord
inate
s
))
return
False
def
take_tile
(
self
):
...
...
@@ -620,9 +620,9 @@ class Particle(matter.Matter):
:return: True: successful taken; False: unsuccessful taken
"""
if
self
.
carried_particle
is
None
and
self
.
carried_tile
is
None
:
if
self
.
coords
in
self
.
world
.
tile_map_coords
:
self
.
carried_tile
=
self
.
world
.
tile_map_coords
[
self
.
coords
]
if
self
.
carried_tile
.
take
(
coords
=
self
.
coords
):
if
self
.
coord
inate
s
in
self
.
world
.
tile_map_coord
inate
s
:
self
.
carried_tile
=
self
.
world
.
tile_map_coord
inate
s
[
self
.
coord
inate
s
]
if
self
.
carried_tile
.
take
(
coord
inate
s
=
self
.
coord
inate
s
):
logging
.
info
(
"Tile has been taken"
)
self
.
world
.
csv_round
.
update_metrics
(
tiles_taken
=
1
)
self
.
csv_particle_writer
.
write_particle
(
tiles_taken
=
1
)
...
...
@@ -648,7 +648,7 @@ class Particle(matter.Matter):
if
id
in
self
.
world
.
tile_map_id
:
logging
.
info
(
"Tile with tile id %s is in the world"
,
str
(
id
))
self
.
carried_tile
=
self
.
world
.
tile_map_id
[
id
]
if
self
.
carried_tile
.
take
(
coords
=
self
.
coords
):
if
self
.
carried_tile
.
take
(
coord
inate
s
=
self
.
coord
inate
s
):
logging
.
info
(
"Tile with tile id %s has been taken"
,
str
(
id
))
self
.
world
.
csv_round
.
update_metrics
(
tiles_taken
=
1
)
self
.
csv_particle_writer
.
write_particle
(
tiles_taken
=
1
)
...
...
@@ -671,11 +671,11 @@ class Particle(matter.Matter):
:return: True: successful taken; False: unsuccessful taken
"""
if
self
.
carried_particle
is
None
and
self
.
carried_tile
is
None
:
coords
=
get_coords_in_direction
(
self
.
coords
,
direction
)
if
coords
in
self
.
world
.
tile_map_coords
:
self
.
carried_tile
=
self
.
world
.
tile_map_coords
[
coords
]
coord
inate
s
=
get_coord
inate
s_in_direction
(
self
.
coord
inate
s
,
direction
)
if
coord
inate
s
in
self
.
world
.
tile_map_coord
inate
s
:
self
.
carried_tile
=
self
.
world
.
tile_map_coord
inate
s
[
coord
inate
s
]
logging
.
info
(
"Tile with tile id %s is in the world"
,
str
(
self
.
carried_tile
.
get_id
()))
if
self
.
carried_tile
.
take
(
coords
=
self
.
coords
):
if
self
.
carried_tile
.
take
(
coord
inate
s
=
self
.
coord
inate
s
):
logging
.
info
(
"Tile with tile id %s has been taken"
,
str
(
self
.
carried_tile
.
get_id
()))
self
.
world
.
csv_round
.
update_metrics
(
tiles_taken
=
1
)
self
.
csv_particle_writer
.
write_particle
(
tiles_taken
=
1
)
...
...
@@ -700,11 +700,11 @@ class Particle(matter.Matter):
"""
if
self
.
carried_particle
is
None
and
self
.
carried_tile
is
None
:
if
check_values_are_coordinates
(
x
,
y
):
coords
=
(
x
,
y
)
if
coords
in
self
.
world
.
tile_map_coords
:
self
.
carried_tile
=
self
.
world
.
tile_map_coords
[
coords
]
coord
inate
s
=
(
x
,
y
)
if
coord
inate
s
in
self
.
world
.
tile_map_coord
inate
s
:
self
.
carried_tile
=
self
.
world
.
tile_map_coord
inate
s
[
coord
inate
s
]
logging
.
info
(
"Tile with tile id %s is in the world"
,
str
(
self
.
carried_tile
.
get_id
()))
if
self
.
carried_tile
.
take
(
coords
=
self
.
coords
):
if
self
.
carried_tile
.
take
(
coord
inate
s
=
self
.
coord
inate
s
):
self
.
world
.
csv_round
.
update_metrics
(
tiles_taken
=
1
)
self
.
csv_particle_writer
.
write_particle
(
tiles_taken
=
1
)
logging
.
info
(
"Tile with tile id %s has been taken"
,
str
(
self
.
carried_tile
.
get_id
()))
...
...
@@ -729,9 +729,9 @@ class Particle(matter.Matter):
:return: None
"""
if
self
.
carried_tile
is
not
None
:
if
self
.
coords
not
in
self
.
world
.
tile_map_coords
:
if
self
.
coord
inate
s
not
in
self
.
world
.
tile_map_coord
inate
s
:
try
:
# cher: insert so to overcome the AttributeError
self
.
carried_tile
.
drop_me
(
self
.
coords
)
self
.
carried_tile
.
drop_me
(
self
.
coord
inate
s
)
except
AttributeError
:
pass
self
.
carried_tile
=
None
...
...
@@ -752,16 +752,16 @@ class Particle(matter.Matter):
:param direction: The directionection on which the tile should be dropped. Options: E, SE, SW, W, NW, NE,
"""
if
self
.
carried_tile
is
not
None
:
coords
=
get_coords_in_direction
(
self
.
coords
,
direction
)
if
coords
not
in
self
.
world
.
tile_map_coords
:
coord
inate
s
=
get_coord
inate
s_in_direction
(
self
.
coord
inate
s
,
direction
)
if
coord
inate
s
not
in
self
.
world
.
tile_map_coord
inate
s
:
try
:
# cher: insert so to overcome the AttributeError
self
.
carried_tile
.
drop_me
(
coords
)
self
.
carried_tile
.
drop_me
(
coord
inate
s
)
except
AttributeError
:
pass
self
.
carried_tile
=
None
self
.
world
.
csv_round
.
update_metrics
(
tiles_dropped
=
1
)
self
.
csv_particle_writer
.
write_particle
(
tiles_dropped
=
1
)
logging
.
info
(
"Dropped tile on %s coordinate"
,
str
(
coords
))
logging
.
info
(
"Dropped tile on %s coordinate"
,
str
(
coord
inate
s
))
return
True
else
:
logging
.
info
(
"Is not possible to drop the tile on that position"
)
...
...
@@ -780,16 +780,16 @@ class Particle(matter.Matter):
"""
if
self
.
carried_tile
is
not
None
:
if
check_values_are_coordinates
(
x
,
y
):
coords
=
(
x
,
y
)
if
coords
not
in
self
.
world
.
get_tile_map_coords
():
coord
inate
s
=
(
x
,
y
)
if
coord
inate
s
not
in
self
.
world
.
get_tile_map_coord
inate
s
():
try
:
# cher: insert so to overcome the AttributeError
self
.
carried_tile
.
drop_me
(
coords
)
self
.
carried_tile
.
drop_me
(
coord
inate
s
)
except
AttributeError
:
pass
self
.
carried_tile
=
None
self
.
world
.
csv_round
.
update_metrics
(
tiles_dropped
=
1
)
self
.
csv_particle_writer
.
write_particle
(
tiles_dropped
=
1
)
logging
.
info
(
"Dropped tile on %s coordinate"
,
str
(
coords
))