From a86abce7d1f1567b2f67b42d97334d17fc52fd4d Mon Sep 17 00:00:00 2001 From: Nicolas Schodet Date: Mon, 13 Jun 2011 00:41:38 +0200 Subject: digital/io-hub: try to avoid dropped pawn --- digital/io-hub/src/robospierre/element.c | 12 ++++++------ digital/io-hub/src/robospierre/element.h | 5 +++-- digital/io-hub/src/robospierre/path.c | 14 +++++++------- 3 files changed, 16 insertions(+), 15 deletions(-) (limited to 'digital/io-hub') diff --git a/digital/io-hub/src/robospierre/element.c b/digital/io-hub/src/robospierre/element.c index adc90a3a..e8ee44e0 100644 --- a/digital/io-hub/src/robospierre/element.c +++ b/digital/io-hub/src/robospierre/element.c @@ -739,22 +739,22 @@ element_get_pos (uint8_t element_id) } uint8_t -element_blocking (uint8_t element_id) +element_blocking (uint8_t element_id, uint8_t escape) { element_t e = element_get (element_id); - return e.type == ELEMENT_TOWER; + return e.type == ELEMENT_TOWER || (!escape && e.type == ELEMENT_PAWN); } uint8_t -element_blocking_path (vect_t a, vect_t b, int16_t ab) +element_blocking_path (vect_t a, vect_t b, int16_t ab, uint8_t escape) { uint8_t i; element_t e; - /* For each obstacle, try to find an intersection. */ - for (i = 0; i < UTILS_COUNT (element_table); i++) + /* Only unload area are blocking. */ + for (i = ELEMENT_UNLOAD_START; i <= ELEMENT_UNLOAD_END; i++) { e = element_get (i); - if (e.type == ELEMENT_TOWER) + if (e.type == ELEMENT_TOWER || (!escape && e.type == ELEMENT_PAWN)) { /* Compute square of distance to obstacle, see * distance_segment_point in modules/math/geometry for the method diff --git a/digital/io-hub/src/robospierre/element.h b/digital/io-hub/src/robospierre/element.h index f9420cdb..243f5b94 100644 --- a/digital/io-hub/src/robospierre/element.h +++ b/digital/io-hub/src/robospierre/element.h @@ -191,15 +191,16 @@ element_get (uint8_t element_id) /** Return whether an element is blocking robot. */ uint8_t -element_blocking (uint8_t element_id); +element_blocking (uint8_t element_id, uint8_t blocking); /** Return whether an element is blocking a line segment. * - a: line segment first point. * - b: line segment second point. * - ab: line segment length. + * - escape: trying to escape, be a little bit more permissive. * - returns: 1 if the path should not be used. */ uint8_t -element_blocking_path (vect_t a, vect_t b, int16_t ab); +element_blocking_path (vect_t a, vect_t b, int16_t ab, uint8_t escape); /** Ask to adjust score for the opposed green zone. */ void diff --git a/digital/io-hub/src/robospierre/path.c b/digital/io-hub/src/robospierre/path.c index 7da57ec6..ecdddbf7 100644 --- a/digital/io-hub/src/robospierre/path.c +++ b/digital/io-hub/src/robospierre/path.c @@ -198,23 +198,23 @@ path_pos (uint8_t node, vect_t *pos) } static uint8_t -path_element_blocking (uint8_t node) +path_element_blocking (uint8_t node, uint8_t escape) { vect_t pos; path_pos (node, &pos); int16_t square_x = (pos.x - 450 - 1) / 350; int16_t square_y = (2100 - pos.y - 1) / 350; uint8_t element_id = ELEMENT_UNLOAD_START + square_x + 6 * square_y; - if (element_blocking (element_id)) + if (element_blocking (element_id, escape)) return 1; uint8_t intersection = ((pos.x - 450) / 350) != square_x; if (intersection) { - if (element_blocking (element_id + 1)) + if (element_blocking (element_id + 1, escape)) return 1; - if (element_blocking (element_id + 6)) + if (element_blocking (element_id + 6, escape)) return 1; - if (element_blocking (element_id + 6 + 1)) + if (element_blocking (element_id + 6 + 1, escape)) return 1; } return 0; @@ -278,7 +278,7 @@ path_blocking (uint8_t a, uint8_t b, int16_t *dp) return 0; } /* Test for a blocking element. */ - if (element_blocking_path (va, vb, d)) + if (element_blocking_path (va, vb, d, path.escape_factor)) blocking = 1; /* Handle escaping. */ if (blocking) @@ -306,7 +306,7 @@ path_blocked_update (void) uint8_t valid = 1; /* First, gather information from tables. */ if (!path_nodes[i].usable - || path_element_blocking (i)) + || path_element_blocking (i, path.escape_factor)) valid = 0; else { -- cgit v1.2.3