summaryrefslogtreecommitdiff
path: root/digital
diff options
context:
space:
mode:
authorNicolas Schodet2010-05-14 06:12:12 +0200
committerNicolas Schodet2010-05-14 06:12:12 +0200
commit55b751937aec298da2f055fd9d1f8f622828a78a (patch)
treee57aaa16edede7d2efea059d65cc6d787f6c89cd /digital
parentcbbd836d3ef76fd2b0a85137cfa660bab41949dc (diff)
digital/io/src: forbid path going near the wall
Diffstat (limited to 'digital')
-rw-r--r--digital/io/src/path.c24
1 files 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. */