From aa7617f41345b39c52cf1874a57ab34e9c8dcab6 Mon Sep 17 00:00:00 2001 From: girst Date: Wed, 22 Jul 2020 19:22:22 +0200 Subject: [PATCH] prefer landing on closed cell with w/b/u/d --- mines.c | 17 +++++++++-------- mines.h | 4 ++-- 2 files changed, 11 insertions(+), 10 deletions(-) diff --git a/mines.c b/mines.c index 9db1956..cbeffbd 100644 --- a/mines.c +++ b/mines.c @@ -174,11 +174,11 @@ int minesviiper(void) { case CTRSEQ_CURSOR_RIGHT: case 'l': move_hi (g.p[0], g.p[1]+1); break; //TODO: W, B, U, D (bigword: only consider open/close state) - case 'w': to_next_boundary (g.p[0], g.p[1], '>', 1); break; - case 'b': to_next_boundary (g.p[0], g.p[1], '<', 1); break; - case 'u': to_next_boundary (g.p[0], g.p[1], '^', 1); break; - case 'd': to_next_boundary (g.p[0], g.p[1], 'v', 1); break; - case 'e': to_next_boundary (g.p[0], g.p[1], '>', 0); break; + case 'w': to_next_boundary (g.p[0], g.p[1], '>'); break; + case 'b': to_next_boundary (g.p[0], g.p[1], '<'); break; + case 'u': to_next_boundary (g.p[0], g.p[1], '^'); break; + case 'd': to_next_boundary (g.p[0], g.p[1], 'v'); break; + case 'e': to_next_boundary (g.p[0], g.p[1], '>'); break; case '0': /* fallthrough */ case '^': move_hi (g.p[0], 0 ); break; case '$': move_hi (g.p[0], f.w-1 ); break; @@ -516,17 +516,18 @@ void move_hi (int l, int c) { } /* to_next_boundary(): move into the supplied direction until a change in open- -state or flag-state is found and move there. falls back to BIG_MOVE. */ +state or flag-state is found and move there. prefer landing on a closed cell by +advancing once more when landing on an opened cell. falls back to BIG_MOVE. */ #define FIND_BOUND(X, L, C, L1, C1, MAX, OP) do {\ new_ ## X OP ## = BIG_MOVE;\ for (int i = X OP 1; i > 0 && i < f.MAX-1; i OP ## OP)\ if (((f.c[L ][C ].o<<2) + f.c[L ][C ].f) \ != ((f.c[L1][C1].o<<2) + f.c[L1][C1].f)) {\ - new_ ## X = i OP advance;\ + new_ ## X = i OP !f.c[L1][C1].o;\ break;\ }\ } while(0) -void to_next_boundary (int l, int c, char direction, int advance) { +void to_next_boundary (int l, int c, char direction) { int new_l = l; int new_c = c; switch (direction) { diff --git a/mines.h b/mines.h index 2c2e6a2..3f880e7 100644 --- a/mines.h +++ b/mines.h @@ -18,7 +18,7 @@ #define KEYHELP \ "Keybindings:\n" \ " hjkl :move left/down/up/right\n" \ - " bduw :move to next boundary\n" \ + " bduw :move to next boundary (landing on closed cell)\n" \ " ^Gg$ :move to the left/bottom/top/right\n" \ " z :center cursor on minefield\n" \ " o :open/choord\n" \ @@ -72,7 +72,7 @@ int minesviiper(void); void fill_minefield (int, int); void move_ph (int, int); void move_hi (int, int); -void to_next_boundary (int, int, char, int); +void to_next_boundary (int, int, char); int find (int, char, int); int getch (unsigned char*); int getch_wrapper (void); -- 2.39.3