summaryrefslogtreecommitdiff
path: root/include
diff options
context:
space:
mode:
authortslil <tslil@posteo.de>2021-01-12 21:42:35 -0500
committertslil <tslil@posteo.de>2026-08-28 19:37:41 +0100
commit4ad67ac92de26b12cbf6cd671de689e7d11ebebb (patch)
tree49ced293e408b4cdf2ba389f019cfe4d131a5070 /include
parentf33d6fc3b09ade5b57b9438b54519e36e4261362 (diff)
Well it works, and it's bad. Many bugs fixed in interim
Diffstat (limited to 'include')
-rw-r--r--include/ct1975.c36
-rw-r--r--include/tak.c14
2 files changed, 28 insertions, 22 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;
};
};