From 4ad67ac92de26b12cbf6cd671de689e7d11ebebb Mon Sep 17 00:00:00 2001 From: tslil Date: Tue, 12 Jan 2021 21:42:35 -0500 Subject: Well it works, and it's bad. Many bugs fixed in interim --- include/ct1975.c | 36 ++++++++++++++++++------------------ 1 file changed, 18 insertions(+), 18 deletions(-) (limited to 'include/ct1975.c') 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); -- cgit v1.3.1