diff options
author | Adam Spragg <adam@spra.gg> | 2022-12-28 15:07:24 +0000 |
---|---|---|
committer | Adam Spragg <adam@spra.gg> | 2022-12-28 15:07:24 +0000 |
commit | a52c78cebcb47106f900b933b3bc5c65a94e459e (patch) | |
tree | 8454b2304548ecf8fe610775b8525754d7bbc7a3 /23.c | |
parent | 985d8d2db0cb743f5fd1982b5c5af4615eb53931 (diff) |
Cache nearby elf positions
Diffstat (limited to '23.c')
-rw-r--r-- | 23.c | 36 |
1 files changed, 16 insertions, 20 deletions
@@ -176,50 +176,46 @@ int trymove(char * buf, int cols, int rows, int round, int i, int j) { static char const dirs[4] = { DIR_N, DIR_S, DIR_W, DIR_E }; + int e_n, e_s, e_w, e_e, e_nw, e_ne, e_sw, e_se; int d, dir; if (!loc_elf(*pos(buf, cols, rows, i, j))) // ??? return -1; - if (!loc_elf(*posd(buf, cols, rows, i, j, DIR_N)) - && !loc_elf(*posd(buf, cols, rows, i, j, DIR_S)) - && !loc_elf(*posd(buf, cols, rows, i, j, DIR_W)) - && !loc_elf(*posd(buf, cols, rows, i, j, DIR_E)) - && !loc_elf(*posd(buf, cols, rows, i, j, DIR_NW)) - && !loc_elf(*posd(buf, cols, rows, i, j, DIR_NE)) - && !loc_elf(*posd(buf, cols, rows, i, j, DIR_SW)) - && !loc_elf(*posd(buf, cols, rows, i, j, DIR_SE))) + e_n = loc_elf(*posd(buf, cols, rows, i, j, DIR_N)); + e_s = loc_elf(*posd(buf, cols, rows, i, j, DIR_S)); + e_w = loc_elf(*posd(buf, cols, rows, i, j, DIR_W)); + e_e = loc_elf(*posd(buf, cols, rows, i, j, DIR_E)); + e_nw = loc_elf(*posd(buf, cols, rows, i, j, DIR_NW)); + e_ne = loc_elf(*posd(buf, cols, rows, i, j, DIR_NE)); + e_sw = loc_elf(*posd(buf, cols, rows, i, j, DIR_SW)); + e_se = loc_elf(*posd(buf, cols, rows, i, j, DIR_SE)); + + if (!e_n && !e_s && !e_w && !e_e + && !e_nw && !e_ne && !e_sw && !e_se) // No elves nearby, do not move. return 0; for (d = 0, dir = 0; d < arrlen(dirs) && dir == 0; ++d) { switch (dirs[(round + d) % 4]) { case DIR_N: - if (!loc_elf(*posd(buf, cols, rows, i, j, DIR_N)) - && !loc_elf(*posd(buf, cols, rows, i, j, DIR_NW)) - && !loc_elf(*posd(buf, cols, rows, i, j, DIR_NE))) + if (!e_n && !e_nw && !e_ne) dir = DIR_N; break; case DIR_S: - if (!loc_elf(*posd(buf, cols, rows, i, j, DIR_S)) - && !loc_elf(*posd(buf, cols, rows, i, j, DIR_SW)) - && !loc_elf(*posd(buf, cols, rows, i, j, DIR_SE))) + if (!e_s && !e_sw && !e_se) dir = DIR_S; break; case DIR_W: - if (!loc_elf(*posd(buf, cols, rows, i, j, DIR_W)) - && !loc_elf(*posd(buf, cols, rows, i, j, DIR_NW)) - && !loc_elf(*posd(buf, cols, rows, i, j, DIR_SW))) + if (!e_w && !e_nw && !e_sw) dir = DIR_W; break; case DIR_E: - if (!loc_elf(*posd(buf, cols, rows, i, j, DIR_E)) - && !loc_elf(*posd(buf, cols, rows, i, j, DIR_NE)) - && !loc_elf(*posd(buf, cols, rows, i, j, DIR_SE))) + if (!e_e && !e_ne && !e_se) dir = DIR_E; break; |