aboutsummaryrefslogtreecommitdiff
path: root/problem.cpp
diff options
context:
space:
mode:
authorAlex Auvolat <alex.auvolat@ens.fr>2015-02-01 18:19:59 +0100
committerAlex Auvolat <alex.auvolat@ens.fr>2015-02-01 18:19:59 +0100
commit92d18c25a2ff68e76bc268b3ad891c78e4cb58d7 (patch)
treed60987465e74db0360d667999d065bb35d33c8a4 /problem.cpp
parentcacec4dbb8b5cc017b9c6d9975f8f792db13cc7a (diff)
downloadRobotique-Projet-92d18c25a2ff68e76bc268b3ad891c78e4cb58d7.tar.gz
Robotique-Projet-92d18c25a2ff68e76bc268b3ad891c78e4cb58d7.zip
Implement random point chosing algorithm
Diffstat (limited to 'problem.cpp')
-rw-r--r--problem.cpp28
1 files changed, 23 insertions, 5 deletions
diff --git a/problem.cpp b/problem.cpp
index 11f4d8e..67287fa 100644
--- a/problem.cpp
+++ b/problem.cpp
@@ -48,8 +48,8 @@ bool hilare_a_mvt::intersects(const obstacle &o) const {
}
bool hilare_a_mvt::intersects(const problem &p) const {
- for (auto i = p.obstacles.begin(); i != p.obstacles.end(); i++) {
- if (intersects(*i)) return true;
+ for (auto& i: p.obstacles) {
+ if (intersects(i)) return true;
}
return false;
}
@@ -212,10 +212,28 @@ solution solver_internal::try_find_solution() {
void solver_internal::step(const problem &p) {
// take new random point
- // try to connect to all existing points
+ double min_x = p.obstacles[0].c.c.x, min_y = p.obstacles[0].c.c.y;
+ double max_x = min_x, max_y = min_y;
+ for (auto& o: p.obstacles) {
+ if (o.c.c.x < min_x) min_x = o.c.c.x;
+ if (o.c.c.y < min_y) min_y = o.c.c.y;
+ if (o.c.c.x > max_x) max_x = o.c.c.x;
+ if (o.c.c.y > max_y) max_y = o.c.c.y;
+ }
+ hilare_a rp = p.begin_pos;
+ rp.x = frand(min_x, max_x);
+ rp.y = frand(min_y, max_y);
+ rp.theta = frand(-M_PI, M_PI);
+ rp.phi = frand(-M_PI, M_PI);
- // TODO
- sf::sleep(sf::milliseconds(10)); // no CPU hog
+ // try to connect to all existing points
+ for (unsigned i = 0; i < pts.size(); i++) {
+ solution s = solution::direct_sol(pts[i], rp);
+ if (s.movement.size() > 0 && !s.intersects(p)) {
+ paths[i][pts.size()] = s;
+ }
+ }
+ pts.push_back(rp);
}
/* vim: set ts=4 sw=4 tw=0 noet :*/