aboutsummaryrefslogtreecommitdiff
path: root/include/minimax_cnn1986.c
diff options
context:
space:
mode:
Diffstat (limited to 'include/minimax_cnn1986.c')
-rw-r--r--include/minimax_cnn1986.c96
1 files changed, 48 insertions, 48 deletions
diff --git a/include/minimax_cnn1986.c b/include/minimax_cnn1986.c
index 7363b23..e89e5a6 100644
--- a/include/minimax_cnn1986.c
+++ b/include/minimax_cnn1986.c
@@ -24,13 +24,13 @@ union u_f {
static uint32_t state = 1;
static union u_f fudge;
-#define DOXORSHIFT { \
+#define DOXORSHIFT { \
state ^= state << 13; \
state ^= state >> 17; \
state ^= state << 5; \
fudge.u = 0x3f800000 | state >> 10; \
fudge.f = (fudge.f - 1.5) * 0.01; \
-}
+ }
#endif
#define RELU(x) ((x) = ((x)<0)?0:(x))
@@ -138,43 +138,43 @@ previous_ply(void) {
static float val;
static enum WIN_TYPE w;
-#define WIN_EVALUATE_OR_RECURSE(store) { \
- w = 0xFF; \
- if (ply >= 2*5 - 2) w = check_win(); \
- if (w < 0xFF) { \
- /* Somebody won, assign weights accordingly */ \
- if (min == 0) { \
- if (w == WIN_ROAD_BLACK || w == WIN_FLAT_BLACK) \
- val = infty; \
- else val = -infty; \
+#define WIN_EVALUATE_OR_RECURSE(store) { \
+ w = 0xFF; \
+ if (ply >= 2*5 - 2) w = check_win(); \
+ if (w < 0xFF) { \
+ /* Somebody won, assign weights accordingly */ \
+ if (min == 0) { \
+ if (w == WIN_ROAD_BLACK || w == WIN_FLAT_BLACK) \
+ val = infty; \
+ else val = -infty; \
+ } else { \
+ if (w == WIN_ROAD_WHITE || w == WIN_FLAT_WHITE) \
+ val = -infty; \
+ else val = infty; \
+ } \
+ } else if (cur_depth == max_depth) { \
+ /* We're at the bottom, evaluate */ \
+ val = ct1986_evaluate_black_win(); \
+ if ((ply & 1) == 0) val = val - 1.0; \
} else { \
- if (w == WIN_ROAD_WHITE || w == WIN_FLAT_WHITE) \
- val = -infty; \
- else val = infty; \
+ /* We're not at the bottom, recurse first */ \
+ next_ply(); \
+ val = ct1986_minimax(cur_depth + 1, max_depth, 1-min, alpha, beta); \
+ previous_ply(); \
} \
- } else if (cur_depth == max_depth) { \
- /* We're at the bottom, evaluate */ \
- val = ct1986_evaluate_black_win(); \
- if ((ply & 1) == 0) val = val - 1.0; \
- } else { \
- /* We're not at the bottom, recurse first */ \
- next_ply(); \
- val = ct1986_minimax(cur_depth + 1, max_depth, 1-min, alpha, beta); \
- previous_ply(); \
- } \
- /* Update the optimal value */ \
- if (((min > 0) && (val <= optimal)) \
- || ((min == 0) && (val >= optimal))) { \
- optimal = val; \
- if (cur_depth == 0) (store); \
- } \
- /* Update alpha and beta */ \
- if (min) { \
- if (optimal < beta) beta = optimal; \
- } else { \
- if (optimal > alpha) alpha = optimal; \
- } \
-}
+ /* Update the optimal value */ \
+ if (((min > 0) && (val <= optimal)) \
+ || ((min == 0) && (val >= optimal))) { \
+ optimal = val; \
+ if (cur_depth == 0) (store); \
+ } \
+ /* Update alpha and beta */ \
+ if (min) { \
+ if (optimal < beta) beta = optimal; \
+ } else { \
+ if (optimal > alpha) alpha = optimal; \
+ } \
+ }
// UP DOWN LEFT RIGHT
static const int8_t deltas[4] = { +5, -5, -1, +1};
@@ -230,8 +230,8 @@ ct1986_minimax(const uint8_t cur_depth, const uint8_t max_depth,
uint16_t colours_backup[5];
uint8_t celldat_backup[5], drops[5]; // we only use 4, the
- // fifth is to skip a
- // bounds check at (*)
+ // fifth is to skip a
+ // bounds check at (*)
// Back up the row of the board
for (uint8_t y = 0; y < 5; y++) {
colours_backup[y] = colours[THE_COORDS(col, y)];
@@ -249,12 +249,12 @@ ct1986_minimax(const uint8_t cur_depth, const uint8_t max_depth,
celldat_backup[x] = celldat[THE_COORDS(x, row)];
}
}
- /*
- * We don't do anything terribly efficient here just try
- * all the ordered partitions of num ∈ {1 … end_stop}, and
- * skip the partition if it calls for multiple stones at
- * the end with a crush.
- */
+ /*
+ * We don't do anything terribly efficient here just try
+ * all the ordered partitions of num ∈ {1 … end_stop}, and
+ * skip the partition if it calls for multiple stones at
+ * the end with a crush.
+ */
uint8_t gaps, t, idx, mask;
for (uint8_t num = 1; num <= count; num++) {
for (uint8_t steps = 1;
@@ -335,9 +335,9 @@ ct1986_minimax(const uint8_t cur_depth, const uint8_t max_depth,
colours[loc] = current_colour;
celldat[loc] = NUM_INC | STONE_FLAT;
WIN_EVALUATE_OR_RECURSE({
- // If we did update the optimal value, store
- generate_place(loc, STONE_FLAT, ct1986_ptn);
- });
+ // If we did update the optimal value, store
+ generate_place(loc, STONE_FLAT, ct1986_ptn);
+ });
// Reset the state
celldat[loc] = 0;
if (black) black_count++;