From 55b751937aec298da2f055fd9d1f8f622828a78a Mon Sep 17 00:00:00 2001 From: Nicolas Schodet Date: Fri, 14 May 2010 06:12:12 +0200 Subject: digital/io/src: forbid path going near the wall --- digital/io/src/path.c | 24 +++++++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-) diff --git a/digital/io/src/path.c b/digital/io/src/path.c index e7c9d547..2381a7ce 100644 --- a/digital/io/src/path.c +++ b/digital/io/src/path.c @@ -25,6 +25,8 @@ #include "common.h" #include "defs.h" #include "path.h" +#include "bot.h" +#include "playground.h" #include "food.h" @@ -250,11 +252,27 @@ path_blocking (uint8_t a, uint8_t b, int16_t *dp) else return 1; } - else + /* Test for the wall. */ + if (va.x < BOT_SIZE_RADIUS || va.x >= PG_WIDTH - BOT_SIZE_RADIUS + || vb.x < BOT_SIZE_RADIUS || vb.x >= PG_WIDTH - BOT_SIZE_RADIUS) { - *dp = d; - return 0; + int16_t dx = va.x - vb.x; + int16_t dy = va.y - vb.y; + /* Do not authorise path going parallel to the wall. */ + if (UTILS_ABS (dx) < UTILS_ABS (dy)) + { + if (escape_factor) + { + *dp = d * escape_factor; + return 0; + } + else + return 1; + } } + /* No blocking. */ + *dp = d; + return 0; } /** Update the cache of blocked nodes. */ -- cgit v1.2.3