aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authortslil clingman <tslil@posteo.de>2021-01-21 01:31:22 -0500
committertslil <tslil@posteo.de>2026-08-28 19:37:41 +0100
commite1c9a014420648b2799509016b4fc52dec19bc2d (patch)
treedc7ef6bc9902245506053b96c2348e0fff9cb836
parent19359dde885243e2359f7c560ae801efccee7294 (diff)
Renaming
-rw-r--r--include/negamax_cnn1986.c30
-rw-r--r--include/negamax_cnn1986.h11
-rw-r--r--src/ct1986.c25
-rw-r--r--src/ctaklm.c28
4 files changed, 46 insertions, 48 deletions
diff --git a/include/negamax_cnn1986.c b/include/negamax_cnn1986.c
index fafb38c..1a6d41a 100644
--- a/include/negamax_cnn1986.c
+++ b/include/negamax_cnn1986.c
@@ -5,8 +5,8 @@
// ===================================================================
const float infty = 3.0;
-char ct1986_ptn[9];
-uint8_t ct1986_search_depth = 3;
+char negamax_cnn1986_ptn[9];
+uint8_t negamax_cnn1986_search_depth = 3;
// ===================================================================
// Implementation of a small convolutional neural network
@@ -37,7 +37,7 @@ static union u_f fudge;
#define RELU(x) ((x) = ((x)<0)?0:(x))
float
-ct1986_evaluate_black_win(void) {
+cnn1986_evaluate_black_win(void) {
/* ------------------ *
* Convolution layer *
* ------------------ */
@@ -166,13 +166,13 @@ static const int8_t deltas[4] = { +5, -5, -1, +1};
else if (w == WIN_DRAW) val = infty/2.0; \
else val = -infty; \
val *= colour; \
- } else if (cur_depth == ct1986_search_depth) { \
+ } else if (cur_depth == negamax_cnn1986_search_depth) { \
/* We're at the bottom, evaluate */ \
- val = colour * ct1986_evaluate_black_win(); \
+ val = colour * cnn1986_evaluate_black_win(); \
} else { \
/* We're not at the bottom, recurse first */ \
next_ply(); \
- val = -ct1986_negamax(cur_depth + 1, -beta, -alpha, -colour); \
+ val = -negamax_cnn1986(cur_depth + 1, -beta, -alpha, -colour); \
previous_ply(); \
} \
{ reset }; \
@@ -186,8 +186,8 @@ static const int8_t deltas[4] = { +5, -5, -1, +1};
}
float
-ct1986_negamax(const uint8_t cur_depth, float alpha, float beta,
- const float colour) {
+negamax_cnn1986(const uint8_t cur_depth, float alpha, float beta,
+ const float colour) {
const uint8_t black = (ply & 1),
material = (black) ? black_count : white_count,
flat = material & 127,
@@ -298,7 +298,7 @@ ct1986_negamax(const uint8_t cur_depth, float alpha, float beta,
WIN_EVALUATE_OR_RECURSE({
// If we did update the optimal value, store
// this move
- generate_move(loc, dir, steps, drops, ct1986_ptn);
+ generate_move(loc, dir, steps, drops, negamax_cnn1986_ptn);
},{
// Reset the board data after recursing or
// before returning
@@ -338,7 +338,7 @@ ct1986_negamax(const uint8_t cur_depth, float alpha, float beta,
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);
+ generate_place(loc, STONE_FLAT, negamax_cnn1986_ptn);
},{
// Reset the state
celldat[loc] = 0;
@@ -353,7 +353,7 @@ ct1986_negamax(const uint8_t cur_depth, float alpha, float beta,
colours[loc] = current_colour;
celldat[loc] = NUM_INC | STONE_STANDING;
WIN_EVALUATE_OR_RECURSE({
- generate_place(loc, STONE_STANDING, ct1986_ptn);
+ generate_place(loc, STONE_STANDING, negamax_cnn1986_ptn);
},{
celldat[loc] = 0;
if (black) black_count++;
@@ -369,7 +369,7 @@ ct1986_negamax(const uint8_t cur_depth, float alpha, float beta,
colours[loc] = current_colour;
celldat[loc] = NUM_INC | STONE_CAPSTONE;
WIN_EVALUATE_OR_RECURSE({
- generate_place(loc, STONE_CAPSTONE, ct1986_ptn);
+ generate_place(loc, STONE_CAPSTONE, negamax_cnn1986_ptn);
},{
celldat[loc] = 0;
if (black) black_count |= 128;
@@ -377,13 +377,13 @@ ct1986_negamax(const uint8_t cur_depth, float alpha, float beta,
});
}
}
- ct1986_display_progress(cur_depth);
+ negamax_cnn1986_display_progress(cur_depth);
}
}
return alpha;
}
inline float
-ct1986_generate(void) {
- return ct1986_negamax(0, -infty, infty, (ply&1)?1.0:-1.0);
+negamax_cnn1986_generate(void) {
+ return negamax_cnn1986(0, -infty, infty, (ply&1)?1.0:-1.0);
}
diff --git a/include/negamax_cnn1986.h b/include/negamax_cnn1986.h
index 411d877..799ca4c 100644
--- a/include/negamax_cnn1986.h
+++ b/include/negamax_cnn1986.h
@@ -3,16 +3,15 @@
#include "weights.h"
extern const float infty;
-extern char ct1986_ptn[9];
-extern uint8_t ct1986_search_depth;
-extern inline void ct1986_display_progress(const uint8_t);
+extern char negamax_cnn1986_ptn[9];
+extern uint8_t negamax_cnn1986_search_depth;
+extern inline void negamax_cnn1986_display_progress(const uint8_t);
// Do negamax to depth ct1986_search_depth and return PTN of best move
// in ct1986_ptn, along with its value as the return. The
// ct1986_display_progress function is called on every new square at
// the top level.
-float ct1986_generate(void);
+float negamax_cnn1986_generate(void);
// Internal utility function
-float
-ct1986_evaluate_black_win(void);
+float cnn1986_evaluate_black_win(void);
diff --git a/src/ct1986.c b/src/ct1986.c
index b930b13..49a1075 100644
--- a/src/ct1986.c
+++ b/src/ct1986.c
@@ -3,13 +3,13 @@
#include <string.h>
#include <tak.h>
-#include <minimax_cnn1986.h>
+#include <negamax_cnn1986.h>
const char* esc = "\x1B[L";
FILE *lcd = NULL;
static char *gamelog = 0;
-static int human, search_depth;
+static int human;
static void
write_line(const char *line) {
@@ -93,11 +93,10 @@ new_game(uint8_t size) {
gamelog[0] = 0;
}
-// Set up output function for ct1986
-
+// Set up output function for negamax_cnn1986
static uint8_t perc;
inline void
-ct1986_display_progress(const uint8_t depth) {
+negamax_cnn1986_display_progress(const uint8_t depth) {
if (depth == 0) {
perc++;
// back four spaces and clear line, followed by perc%
@@ -109,12 +108,12 @@ ct1986_display_progress(const uint8_t depth) {
}
static int
-ct1986_turn(const uint8_t search_depth) {
+negamax_cnn1986_turn() {
// Prepare progress bar
fputs("Computing: ", lcd); fflush(lcd);
// Run the minimax
perc = 0;
- float minimax = ct1986_generate(search_depth);
+ float minimax = negamax_cnn1986_generate();
fputc('\n', lcd); fflush(lcd);
// Failed to find a move?
if (minimax <= -infty) {
@@ -123,8 +122,8 @@ ct1986_turn(const uint8_t search_depth) {
} else {
fprintf(lcd, "%s: %s\n",
(ply & 1) ? "Black" : "White",
- ct1986_ptn);
- handle_turn(ct1986_ptn);
+ negamax_cnn1986_ptn);
+ handle_turn(negamax_cnn1986_ptn);
return EXIT_SUCCESS;
}
}
@@ -140,8 +139,8 @@ input_is_not_turn(const char *line) {
case 'l': { do_game_log(); break; }
case 'n': { new_game(5); break; }
case 'd': {
- search_depth = line[1] - '0';
- fprintf(lcd, "Search depth: %d\n", search_depth);
+ negamax_cnn1986_search_depth = line[1] - '0';
+ fprintf(lcd, "Search depth: %d\n", negamax_cnn1986_search_depth);
fflush(lcd);
break;
}
@@ -161,7 +160,7 @@ main(int argc, char **argv) {
if (lcd == NULL) return EXIT_FAILURE;
human = 0;
- search_depth = 1;
+ negamax_cnn1986_search_depth = 3;
new_game(5);
fprintf(lcd, "%sB", esc);
fflush(lcd);
@@ -188,7 +187,7 @@ main(int argc, char **argv) {
break;
}
}
- ct1986_turn(search_depth);
+ negamax_cnn1986_turn();
human = 0;
}
diff --git a/src/ctaklm.c b/src/ctaklm.c
index a1ca69d..da807c8 100644
--- a/src/ctaklm.c
+++ b/src/ctaklm.c
@@ -234,8 +234,8 @@ handle_turn(char *line) {
static void
new_game(uint8_t size) {
reset_state(size);
- printf("New %dx%d game! ct1986 at search depth %d.\n",
- size, size, ct1986_search_depth);
+ printf("New %dx%d game! negamax_cnn1986 at search depth %d.\n",
+ size, size, negamax_cnn1986_search_depth);
if (gamelog) gamelog = realloc(gamelog, sizeof(char));
else gamelog = malloc(sizeof(char));
gamelog[0] = 0;
@@ -296,9 +296,9 @@ load_ptn(const char* fn) {
static float sum_depth, num_check;
-// Set up output function for ct1986
+// Set up output function for negamax_cnn1986
inline void
-ct1986_display_progress(const uint8_t depth) {
+negamax_cnn1986_display_progress(const uint8_t depth) {
sum_depth += depth;
num_check += 1;
if (depth == 0) {
@@ -308,7 +308,7 @@ ct1986_display_progress(const uint8_t depth) {
}
static int
-ct1986_turn(void) {
+negamax_cnn1986_turn(void) {
if (won == 0xFF) {
// Prepare progress bar
fputs("Computing [", stdout);
@@ -317,7 +317,7 @@ ct1986_turn(void) {
fflush(stdout);
// Run the minimax
sum_depth = 0; num_check = 0;
- float minimax = ct1986_generate();
+ float minimax = negamax_cnn1986_generate();
fputs("\033[1C ", stdout);
// Failed to find a move?
if (minimax <= -infty) {
@@ -325,11 +325,11 @@ ct1986_turn(void) {
return EXIT_FAILURE;
} else {
printf("Result: %s (%.2f, %.1e, %.2f)\n",
- ct1986_ptn,
+ negamax_cnn1986_ptn,
minimax*100.0,
num_check,
sum_depth/num_check);
- handle_turn(ct1986_ptn);
+ handle_turn(negamax_cnn1986_ptn);
return EXIT_SUCCESS;
}
} else {
@@ -347,7 +347,7 @@ info, load, log, new, play (b|w), self-play, square <col><row>, <PTN>.");
} else if (!strcmp(line,"info")) {
print_info();
} else if (!strcmp(line,"eval")) {
- float eval = ct1986_evaluate_black_win()*100;
+ float eval = cnn1986_evaluate_black_win()*100;
if (ply & 1) {
printf("Black heuristic chance: %s%.2f%s\n",
blk, eval, rst);
@@ -360,12 +360,12 @@ info, load, log, new, play (b|w), self-play, square <col><row>, <PTN>.");
} else if (!strcmp(line,"new")) {
new_game(5);
} else if (!strcmp(line,"self-play")) {
- while (ct1986_turn() == 0);
+ while (negamax_cnn1986_turn() == 0);
} else if (!strncmp(line,"depth",5)) {
if (strnlen(line,7) == 7 && line[6] >= '0' && line[6] <= '9') {
- ct1986_search_depth = line[6] - '0';
+ negamax_cnn1986_search_depth = line[6] - '0';
printf("New search depth: %d.\n",
- ct1986_search_depth);
+ negamax_cnn1986_search_depth);
} else {
puts("Usage: depth [0-9].");
}
@@ -419,7 +419,7 @@ main(int argc, char **argv) {
(void)(argv);
human = 0;
- ct1986_search_depth = 3;
+ negamax_cnn1986_search_depth = 3;
new_game(5);
char *line = NULL;
@@ -447,7 +447,7 @@ main(int argc, char **argv) {
if (read == -1) {
playing = 0;
} else {
- ct1986_turn();
+ negamax_cnn1986_turn();
human = 0;
}
}