From db6d1da86b80a545e0df38795ee869be57b8b89d Mon Sep 17 00:00:00 2001 From: Adam Spragg Date: Tue, 3 Jan 2023 09:56:05 +0000 Subject: Puzzle 22: Change where we check for movement special cases --- 22.c | 42 ++++++++++++++++++++---------------------- 1 file changed, 20 insertions(+), 22 deletions(-) (limited to '22.c') diff --git a/22.c b/22.c index 2a47a79..9da3e6d 100644 --- a/22.c +++ b/22.c @@ -100,30 +100,28 @@ elf_move(struct elf * elf, char const * map, int cols, int rows, enum map_type m return -1; } - newelf.x = modulo(elf->x + dx, cols); - newelf.y = modulo(elf->y + dy, rows); - newelf.dir = elf->dir; - elem = map[newelf.x + newelf.y * cols]; - - if (elem == ' ' || elem == '\n') { - switch (mtype) { - case M_FLAT: - // Just keep going until we wrap around to a non-blank position - while (elem == ' ' || elem == '\n') { - newelf.x = modulo(newelf.x + dx, cols); - newelf.y = modulo(newelf.y + dy, rows); - elem = map[newelf.x + newelf.y * cols]; - } - break; + switch (mtype) { + case M_FLAT: + newelf.x = modulo(elf->x + dx, cols); + newelf.y = modulo(elf->y + dy, rows); + newelf.dir = elf->dir; + elem = map[newelf.x + newelf.y * cols]; + + // Just keep going until we wrap around to a non-blank position + while (elem == ' ' || elem == '\n') { + newelf.x = modulo(newelf.x + dx, cols); + newelf.y = modulo(newelf.y + dy, rows); + elem = map[newelf.x + newelf.y * cols]; + } + break; - case M_NET: - fprintf(stderr, "Map type not yet supported!\n"); - return -1; + case M_NET: + fprintf(stderr, "Map type not yet supported!\n"); + return -1; - default: - fprintf(stderr, "Unknown map type %d\n", mtype); - return -1; - } + default: + fprintf(stderr, "Unknown map type %d\n", mtype); + return -1; } switch (elem) { -- cgit v1.2.1