diff options
| author | tslil <tslil@posteo.de> | 2021-01-12 21:42:35 -0500 |
|---|---|---|
| committer | tslil <tslil@posteo.de> | 2026-08-28 19:37:41 +0100 |
| commit | 4ad67ac92de26b12cbf6cd671de689e7d11ebebb (patch) | |
| tree | 49ced293e408b4cdf2ba389f019cfe4d131a5070 | |
| parent | f33d6fc3b09ade5b57b9438b54519e36e4261362 (diff) | |
Well it works, and it's bad. Many bugs fixed in interim
| -rw-r--r-- | include/ct1975.c | 36 | ||||
| -rw-r--r-- | include/tak.c | 14 | ||||
| -rw-r--r-- | src/ctaklm.c | 5 |
3 files changed, 31 insertions, 24 deletions
diff --git a/include/ct1975.c b/include/ct1975.c index 61f1fee..c0256eb 100644 --- a/include/ct1975.c +++ b/include/ct1975.c @@ -120,22 +120,22 @@ ct1975_generate_ptn(void display_progress(void)) { const uint8_t loc = THE_COORDS(col, row); const uint8_t count = COUNT_AT(loc); // Only try moves after CPS - if (count && ply>2 && ((colours[loc] & 1) == current_colour)) { - // There are stones, can we move them? - // For every direction. I'm not a huge fan of looping - // through enums, but it's better than manually unrolling - // this. Sufficiently smart compilers? + if (count && ((colours[loc] & 1) == current_colour) && ply>2) { + // There are stones, can we move them in a given direction? + // I'm not a huge fan of looping through enums, but it's + // better than manually unrolling this. Sufficiently smart + // compilers? for (enum MOVE_DIRECTION dir = M_UP; dir <= M_RIGHT; dir++) { // Back-up the row/column of the board if (dir == M_UP || dir == M_DOWN) { - for (uint8_t k = 0; k < board_size; k++) { - colours_backup[k] = colours[THE_COORDS(k, row)]; - celldat_backup[k] = celldat[THE_COORDS(k, row)]; + for (uint8_t y = 0; y < board_size; y++) { + colours_backup[y] = colours[THE_COORDS(col, y)]; + celldat_backup[y] = celldat[THE_COORDS(col, y)]; } } else { - for (uint8_t k = 0; k < board_size; k++) { - colours_backup[k] = colours[THE_COORDS(col, k)]; - celldat_backup[k] = celldat[THE_COORDS(col, k)]; + for (uint8_t x = 0; x < board_size; x++) { + colours_backup[x] = colours[THE_COORDS(x, row)]; + celldat_backup[x] = celldat[THE_COORDS(x, row)]; } } // We don't do anything terribly efficient or smart here, @@ -172,14 +172,14 @@ ct1975_generate_ptn(void display_progress(void)) { } // Reset the board data if (dir == M_UP || dir == M_DOWN) { - for (uint8_t k = 0; k < board_size; k++) { - colours[THE_COORDS(k, row)] = colours_backup[k]; - celldat[THE_COORDS(k, row)] = celldat_backup[k]; + for (uint8_t y = 0; y < board_size; y++) { + colours[THE_COORDS(col, y)] = colours_backup[y]; + celldat[THE_COORDS(col, y)] = celldat_backup[y]; } } else { - for (uint8_t k = 0; k < board_size; k++) { - colours[THE_COORDS(col, k)] = colours_backup[k]; - celldat[THE_COORDS(col, k)] = celldat_backup[k]; + for (uint8_t x = 0; x < board_size; x++) { + colours[THE_COORDS(x, row)] = colours_backup[x]; + celldat[THE_COORDS(x, row)] = celldat_backup[x]; } } } @@ -198,7 +198,7 @@ ct1975_generate_ptn(void display_progress(void)) { // Legal placement, evaluate it if (r == ACT_OK) { this = ct1975_evaluate_black_win(); - if (ply < 3 && BETTER(this, ct1975_optimal)) { + if (BETTER(this, ct1975_optimal)) { // Update the chosen action ct1975_optimal = this; generate_place(board_size, loc, stone, ct1975_ptn); diff --git a/include/tak.c b/include/tak.c index bb06a16..47a9cc6 100644 --- a/include/tak.c +++ b/include/tak.c @@ -132,22 +132,28 @@ try_move(const int8_t location, const enum MOVE_DIRECTION direction, switch (direction) { case M_UP: { delta = +board_size; - if (location + delta * steps > NUM_SQUARES) return ACT_ILLEGAL; + if (location + delta * steps > NUM_SQUARES) + return ACT_ILLEGAL; break; }; case M_DOWN: { delta = -board_size; - if (location + delta * steps < 0) return ACT_ILLEGAL; + if (location + delta * steps < 0) + return ACT_ILLEGAL; break; }; case M_RIGHT: { delta = +1; - if (location + delta * steps > NUM_SQUARES) return ACT_ILLEGAL; + if ((location + steps * delta) / board_size + > location / board_size) + return ACT_ILLEGAL; break; }; case M_LEFT: { delta = -1; - if (location + delta * steps < 0) return ACT_ILLEGAL; + if ((location + steps * delta) / board_size + < location / board_size) + return ACT_ILLEGAL; break; }; }; diff --git a/src/ctaklm.c b/src/ctaklm.c index 87fc30f..13326f9 100644 --- a/src/ctaklm.c +++ b/src/ctaklm.c @@ -60,7 +60,8 @@ print_cell_line(const uint8_t line, } } if (idx < stack_size) { - put_stone(STONE_AT(location), colours[location] & (1 << idx), + put_stone(STONE_AT(location), + (colours[location] & (1 << idx)) ? C_BLACK : C_WHITE, idx == 0, idx >= board_size); } else { putchar(' '); @@ -125,7 +126,7 @@ print_square(const uint8_t col, const uint8_t row) { uint8_t mask = 1 << (stack_size - 1); for (uint8_t k = 0; k < stack_size; k++, mask >>= 1) { put_stone(STONE_AT(THE_COORDS(col, row)), - colours[THE_COORDS(col, row)] & mask, + (colours[THE_COORDS(col, row)] & mask) ? C_BLACK : C_WHITE, k+1 == stack_size, stack_size-k >= board_size); } |
