diff options
author | Adam Spragg <adam@spra.gg> | 2023-01-03 09:56:05 +0000 |
---|---|---|
committer | Adam Spragg <adam@spra.gg> | 2023-01-03 09:56:05 +0000 |
commit | db6d1da86b80a545e0df38795ee869be57b8b89d (patch) | |
tree | 6d71f025a469acee05e5d47dabc95e439f779bcd /22.c | |
parent | 10d7a89b299364f0501c500c6d97460a65ad9d14 (diff) |
Puzzle 22: Change where we check for movement special cases
Diffstat (limited to '22.c')
-rw-r--r-- | 22.c | 42 |
1 files changed, 20 insertions, 22 deletions
@@ -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) { |