summaryrefslogtreecommitdiff
path: root/22.c
diff options
context:
space:
mode:
Diffstat (limited to '22.c')
-rw-r--r--22.c50
1 files changed, 25 insertions, 25 deletions
diff --git a/22.c b/22.c
index f29f78e..bcde74a 100644
--- a/22.c
+++ b/22.c
@@ -78,38 +78,38 @@ elf_turn(struct elf * elf, char turn)
int
elf_move(struct elf * elf, char const * map, int cols, int rows, int distance)
{
- int skip, wrap, base;
+ while (distance > 0) {
+ int skip, wrap, base, newpos;
- switch (elf->dir) {
- case D_NORTH:
- skip = -cols;
- wrap = cols * rows;
- break;
+ switch (elf->dir) {
+ case D_NORTH:
+ skip = -cols;
+ wrap = cols * rows;
+ break;
- case D_EAST:
- skip = 1;
- wrap = cols;
- break;
+ case D_EAST:
+ skip = 1;
+ wrap = cols;
+ break;
- case D_SOUTH:
- skip = cols;
- wrap = cols * rows;
- break;
+ case D_SOUTH:
+ skip = cols;
+ wrap = cols * rows;
+ break;
- case D_WEST:
- skip = -1;
- wrap = cols;
- break;
+ case D_WEST:
+ skip = -1;
+ wrap = cols;
+ break;
- default:
- fprintf(stderr, "Unexpected direction %d\n", elf->dir);
- return -1;
- }
+ default:
+ fprintf(stderr, "Unexpected direction %d\n", elf->dir);
+ return -1;
+ }
- base = (elf->pos / wrap) * wrap;
+ base = (elf->pos / wrap) * wrap;
- while (distance > 0) {
- int newpos = base + modulo(elf->pos + skip, wrap);
+ newpos = base + modulo(elf->pos + skip, wrap);
while (map[newpos] == ' ' || map[newpos] == '\n')
newpos = base + modulo(newpos + skip, wrap);