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
4c7aec6a
Commit
4c7aec6a
authored
Sep 18, 2019
by
Ahmad Reza
Browse files
the method check_coords is renamed to check_values_are_coordinates
parent
b1014a79
Changes
3
Show whitespace changes
Inline
Side-by-side
lib/particle.py
View file @
4c7aec6a
...
...
@@ -91,7 +91,7 @@ class Particle(matter.Matter):
"""
direction_coord
=
get_coords_in_direction
(
self
.
coords
,
direction
)
direction
,
direction_coord
=
self
.
check_within_border
(
direction
,
direction_coord
)
if
check_
coord
s
(
direction_coord
[
0
],
direction_coord
[
1
]):
if
check_
values_are_coordinate
s
(
direction_coord
[
0
],
direction_coord
[
1
]):
if
self
.
coords
in
self
.
world
.
particle_map_coords
:
del
self
.
world
.
particle_map_coords
[
self
.
coords
]
...
...
@@ -520,7 +520,7 @@ 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
)
if
check_
coord
s
(
x
,
y
):
if
check_
values_are_coordinate
s
(
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
...
...
@@ -701,7 +701,7 @@ class Particle(matter.Matter):
:return: True: successful taken; False: unsuccessful taken
"""
if
self
.
carried_particle
is
None
and
self
.
carried_tile
is
None
:
if
check_
coord
s
(
x
,
y
):
if
check_
values_are_coordinate
s
(
x
,
y
):
coords
=
(
x
,
y
)
if
coords
in
self
.
world
.
tile_map_coords
:
self
.
carried_tile
=
self
.
world
.
tile_map_coords
[
coords
]
...
...
@@ -781,7 +781,7 @@ class Particle(matter.Matter):
:param y: y coordinate
"""
if
self
.
carried_tile
is
not
None
:
if
check_
coord
s
(
x
,
y
):
if
check_
values_are_coordinate
s
(
x
,
y
):
coords
=
(
x
,
y
)
if
coords
not
in
self
.
world
.
get_tile_map_coords
():
try
:
# cher: insert so to overcome the AttributeError
...
...
@@ -859,7 +859,7 @@ class Particle(matter.Matter):
"""
coords
=
(
0
,
0
)
if
x
is
not
None
and
y
is
not
None
:
if
check_
coord
s
(
x
,
y
):
if
check_
values_are_coordinate
s
(
x
,
y
):
coords
=
(
x
,
y
)
logging
.
info
(
"Going to create a particle on position %s"
,
str
(
coords
))
new_particle
=
self
.
world
.
add_particle
(
coords
[
0
],
coords
[
1
],
color
,
alpha
)
...
...
@@ -934,7 +934,7 @@ class Particle(matter.Matter):
:return: True: Deleting successful; False: Deleting unsuccessful
"""
if
x
is
not
None
and
y
is
not
None
:
if
check_
coord
s
(
x
,
y
):
if
check_
values_are_coordinate
s
(
x
,
y
):
coords
=
(
x
,
y
)
if
self
.
world
.
remove_particle_on
(
coords
):
logging
.
info
(
"Deleted particle with particle on coords %s"
,
str
(
coords
))
...
...
@@ -1035,7 +1035,7 @@ class Particle(matter.Matter):
:return: True: Successful taken; False: Cannot be taken or wrong Coordinates
"""
if
self
.
carried_particle
is
None
and
self
.
carried_tile
is
None
:
if
check_
coord
s
(
x
,
y
):
if
check_
values_are_coordinate
s
(
x
,
y
):
coords
=
(
x
,
y
)
if
coords
in
self
.
world
.
particle_map_coords
:
self
.
carried_particle
=
self
.
world
.
particle_map_coords
[
coords
]
...
...
@@ -1113,7 +1113,7 @@ class Particle(matter.Matter):
:param x: x coordinate
:param y: y coordinate
"""
if
self
.
carried_particle
is
not
None
and
x
is
not
None
and
y
is
not
None
and
check_
coord
s
(
x
,
y
):
if
self
.
carried_particle
is
not
None
and
x
is
not
None
and
y
is
not
None
and
check_
values_are_coordinate
s
(
x
,
y
):
coords
=
(
x
,
y
)
if
coords
not
in
self
.
world
.
particle_map_coords
:
try
:
# cher: insert so to overcome the AttributeError
...
...
@@ -1196,7 +1196,7 @@ class Particle(matter.Matter):
"""
coords
=
(
0
,
0
)
if
x
is
not
None
and
y
is
not
None
:
if
check_
coord
s
(
x
,
y
):
if
check_
values_are_coordinate
s
(
x
,
y
):
coords
=
(
x
,
y
)
logging
.
info
(
"Going to create a marker on position %s"
,
str
(
coords
))
new_marker
=
self
.
world
.
add_marker
(
coords
[
0
],
coords
[
1
],
color
,
alpha
)
...
...
@@ -1271,7 +1271,7 @@ class Particle(matter.Matter):
:return: True: Deleting successful; False: Deleting unsuccessful
"""
if
x
is
not
None
and
y
is
not
None
:
if
check_
coord
s
(
x
,
y
):
if
check_
values_are_coordinate
s
(
x
,
y
):
coords
=
(
x
,
y
)
if
self
.
world
.
remove_marker_on
(
coords
):
logging
.
info
(
"Deleted marker oords %s"
,
str
(
coords
))
...
...
lib/swarm_sim_header.py
View file @
4c7aec6a
...
...
@@ -85,7 +85,7 @@ def direction_in_range(direction):
return
direction
%
6
def
check_
coord
s
(
coords_x
,
coords_y
):
def
check_
values_are_coordinate
s
(
coords_x
,
coords_y
):
"""
Checks if the given coordinates are matching the
hexagon coordinates
...
...
lib/world.py
View file @
4c7aec6a
...
...
@@ -273,7 +273,7 @@ class World:
if
alpha
<
0
or
alpha
>
1
:
alpha
=
1
if
len
(
self
.
particles
)
<
self
.
config_data
.
max_particles
:
if
check_
coord
s
(
x
,
y
)
==
True
:
if
check_
values_are_coordinate
s
(
x
,
y
)
==
True
:
if
(
x
,
y
)
not
in
self
.
get_particle_map_coords
():
self
.
particle_id_counter
+=
1
new_particle
=
particle
.
Particle
(
self
,
x
,
y
,
color
,
alpha
,
self
.
particle_id_counter
)
...
...
@@ -357,7 +357,7 @@ class World:
"""
if
alpha
<
0
or
alpha
>
1
:
alpha
=
1
if
check_
coord
s
(
x
,
y
)
==
True
:
if
check_
values_are_coordinate
s
(
x
,
y
)
==
True
:
if
(
x
,
y
)
not
in
self
.
tile_map_coords
:
self
.
new_tile
=
tile
.
Tile
(
self
,
x
,
y
,
color
,
alpha
)
print
(
"Before adding "
,
len
(
self
.
tiles
)
)
...
...
@@ -386,7 +386,7 @@ class World:
:param y: the y coordinates on which the tile should be added
:return: True: Successful added; False: Unsuccsessful
"""
if
check_
coord
s
(
x
,
y
)
==
True
:
if
check_
values_are_coordinate
s
(
x
,
y
)
==
True
:
if
(
x
,
y
)
not
in
self
.
tile_map_coords
:
self
.
new_tile
=
tile
.
Tile
(
self
,
x
,
y
,
color
,
alpha
)
self
.
tiles
.
append
(
self
.
new_tile
)
...
...
@@ -466,7 +466,7 @@ class World:
"""
if
alpha
<
0
or
alpha
>
1
:
alpha
=
1
if
check_
coord
s
(
x
,
y
)
==
True
:
if
check_
values_are_coordinate
s
(
x
,
y
)
==
True
:
if
(
x
,
y
)
not
in
self
.
marker_map_coords
:
self
.
new_marker
=
marker
.
Marker
(
self
,
x
,
y
,
color
,
alpha
)
self
.
markers
.
append
(
self
.
new_marker
)
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment