aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authortslil clingman <tslil@posteo.de>2021-03-28 00:19:05 -0400
committertslil <tslil@posteo.de>2026-08-28 19:37:41 +0100
commit2dbb9fa9b69e49d49cebb1c17559f6fe67600a4d (patch)
tree6b90825474eb34e121b3788036ff0350484ae07b
parent00a04c2929bdc8f8f4bf7d5d8cf413ebfb3cd006 (diff)
Fix copyright notice in files, and small preemptive optimisation
Eventually there'll be a more complicated data generation step than the one we're presently using, so having it in-lined in the loop is wasteful. Ideally also this would be update per ply and we could avoid recalculating it entirely for every query -- though it's probably ``fast enough'' for now. Also, caching is WIP.
-rw-r--r--include/actions.c2
-rw-r--r--include/actions.h2
-rw-r--r--include/cnn1986.c50
-rw-r--r--include/cnn1986.h2
-rw-r--r--include/lcdlib.c2
-rw-r--r--include/lcdlib.h2
-rw-r--r--include/negamax.c2
-rw-r--r--include/negamax.h2
-rw-r--r--include/tak.c2
-rw-r--r--include/tak.h2
-rw-r--r--include/tt_llcht.c2
-rw-r--r--include/tt_llcht.h2
-rw-r--r--include/weights.c2
-rw-r--r--include/weights.h2
-rw-r--r--include/xorshift64.c2
-rw-r--r--include/xorshift64.h2
-rw-r--r--include/zobrist.c2
-rw-r--r--include/zobrist.h2
18 files changed, 47 insertions, 37 deletions
diff --git a/include/actions.c b/include/actions.c
index 0b7d860..374f4f9 100644
--- a/include/actions.c
+++ b/include/actions.c
@@ -12,7 +12,7 @@
General Public License for more details.
You should have received a copy of the GNU General Public License
- along with Takwrap. If not, see <https://www.gnu.org/licenses/>.
+ along with ct. If not, see <https://www.gnu.org/licenses/>.
*/
#include "actions.h"
diff --git a/include/actions.h b/include/actions.h
index 37c8d9e..75c881e 100644
--- a/include/actions.h
+++ b/include/actions.h
@@ -12,7 +12,7 @@
General Public License for more details.
You should have received a copy of the GNU General Public License
- along with Takwrap. If not, see <https://www.gnu.org/licenses/>.
+ along with ct. If not, see <https://www.gnu.org/licenses/>.
*/
#ifndef ACTIONS_H
diff --git a/include/cnn1986.c b/include/cnn1986.c
index dc0e116..9191ec8 100644
--- a/include/cnn1986.c
+++ b/include/cnn1986.c
@@ -12,7 +12,7 @@
General Public License for more details.
You should have received a copy of the GNU General Public License
- along with Takwrap. If not, see <https://www.gnu.org/licenses/>.
+ along with ct. If not, see <https://www.gnu.org/licenses/>.
*/
#include "cnn1986.h"
@@ -27,8 +27,34 @@ static float dense1[DENSE1_NUM];
static float dense2[DENSE2_NUM];
#define RELU(x) ((x) = ((x)<0)?0:(x))
-
float cnn1986_evaluate_black_win(void) {
+ /* --------------- *
+ * Generate input *
+ * --------------- */
+
+ float cur_board[board_size*board_size][KERN_CHAN];
+ for (int y = 0; y < board_size; y++) {
+ for (int x = 0; x < board_size; x++) {
+ const int loc = x+y*board_size;
+ for (int c = 0; c < KERN_CHAN; c++) { // heh, c++
+ float lookup = 0;
+ if (COUNT_AT(loc)>c) {
+ if (c==0) {
+ if (STONE_AT(loc) == STONE_STANDING) {
+ lookup = (colours[loc] & 1) ? +0.25 : -0.25;
+ } else if (STONE_AT(loc) == STONE_CAPSTONE) {
+ lookup = (colours[loc] & 1) ? +1.00 : -1.00;
+ } else {
+ lookup = (colours[loc] & 1) ? +0.50 : -0.50;
+ }
+ } else {
+ lookup = (colours[loc] & (1<<c)) ? +0.50 : -0.50;
+ }
+ }
+ cur_board[loc][c] = lookup;
+ }
+ }
+ }
/* ------------------ *
* Convolution layer *
* ------------------ */
@@ -44,25 +70,9 @@ float cnn1986_evaluate_black_win(void) {
for (uint8_t kx = 0; kx < KERN_SIZE; kx++) {
for (uint8_t c = 0; c < KERN_CHAN; c++) {
// Where we are on the board
- const uint8_t loc = kx+bx+(ky+by)*5;
- // Look up what's on the board at this location, and
- // multiply it. For c=0 we have to do some extra work
- float lookup = 0;
- if (COUNT_AT(loc)>c) {
- if (c==0) {
- if (STONE_AT(loc) == STONE_STANDING) {
- lookup = (colours[loc] & 1) ? +0.25 : -0.25;
- } else if (STONE_AT(loc) == STONE_CAPSTONE) {
- lookup = (colours[loc] & 1) ? +1.00 : -1.00;
- } else {
- lookup = (colours[loc] & 1) ? +0.50 : -0.50;
- }
- } else {
- lookup = (colours[loc] & (1<<c)) ? +0.50 : -0.50;
- }
- }
+ const uint8_t loc = kx+bx+(ky+by)*board_size;
flattened[kern+KERN_NUM*(bx+by*KERN_OSIZE)]
- += lookup*conv2d_weights[kern][ky][kx][c];
+ += cur_board[loc][c]*conv2d_weights[kern][ky][kx][c];
}
}
}
diff --git a/include/cnn1986.h b/include/cnn1986.h
index 97f84d9..40a0920 100644
--- a/include/cnn1986.h
+++ b/include/cnn1986.h
@@ -12,7 +12,7 @@
General Public License for more details.
You should have received a copy of the GNU General Public License
- along with Takwrap. If not, see <https://www.gnu.org/licenses/>.
+ along with ct. If not, see <https://www.gnu.org/licenses/>.
*/
#include <tak.h>
diff --git a/include/lcdlib.c b/include/lcdlib.c
index efbdf3d..4d8c33e 100644
--- a/include/lcdlib.c
+++ b/include/lcdlib.c
@@ -12,7 +12,7 @@
General Public License for more details.
You should have received a copy of the GNU General Public License
- along with Takwrap. If not, see <https://www.gnu.org/licenses/>.
+ along with ct. If not, see <https://www.gnu.org/licenses/>.
*/
#include "lcdlib.h"
diff --git a/include/lcdlib.h b/include/lcdlib.h
index 7750c7b..87aef12 100644
--- a/include/lcdlib.h
+++ b/include/lcdlib.h
@@ -12,7 +12,7 @@
General Public License for more details.
You should have received a copy of the GNU General Public License
- along with Takwrap. If not, see <https://www.gnu.org/licenses/>.
+ along with ct. If not, see <https://www.gnu.org/licenses/>.
*/
#include <stdlib.h>
diff --git a/include/negamax.c b/include/negamax.c
index 0afa153..a970b83 100644
--- a/include/negamax.c
+++ b/include/negamax.c
@@ -12,7 +12,7 @@
General Public License for more details.
You should have received a copy of the GNU General Public License
- along with Takwrap. If not, see <https://www.gnu.org/licenses/>.
+ along with ct. If not, see <https://www.gnu.org/licenses/>.
*/
#include "negamax.h"
diff --git a/include/negamax.h b/include/negamax.h
index 4a09ecb..f56f405 100644
--- a/include/negamax.h
+++ b/include/negamax.h
@@ -12,7 +12,7 @@
General Public License for more details.
You should have received a copy of the GNU General Public License
- along with Takwrap. If not, see <https://www.gnu.org/licenses/>.
+ along with ct. If not, see <https://www.gnu.org/licenses/>.
*/
#include <stdint.h>
diff --git a/include/tak.c b/include/tak.c
index b93660f..78d3854 100644
--- a/include/tak.c
+++ b/include/tak.c
@@ -12,7 +12,7 @@
General Public License for more details.
You should have received a copy of the GNU General Public License
- along with Takwrap. If not, see <https://www.gnu.org/licenses/>.
+ along with ct. If not, see <https://www.gnu.org/licenses/>.
*/
#include "tak.h"
diff --git a/include/tak.h b/include/tak.h
index 1c73002..8a1d8be 100644
--- a/include/tak.h
+++ b/include/tak.h
@@ -12,7 +12,7 @@
General Public License for more details.
You should have received a copy of the GNU General Public License
- along with Takwrap. If not, see <https://www.gnu.org/licenses/>.
+ along with ct. If not, see <https://www.gnu.org/licenses/>.
*/
#ifndef TAK_H
diff --git a/include/tt_llcht.c b/include/tt_llcht.c
index 1ea8767..60f8ccc 100644
--- a/include/tt_llcht.c
+++ b/include/tt_llcht.c
@@ -12,7 +12,7 @@
General Public License for more details.
You should have received a copy of the GNU General Public License
- along with Takwrap. If not, see <https://www.gnu.org/licenses/>.
+ along with ct. If not, see <https://www.gnu.org/licenses/>.
*/
#include "tt_llcht.h"
diff --git a/include/tt_llcht.h b/include/tt_llcht.h
index c23f814..377de10 100644
--- a/include/tt_llcht.h
+++ b/include/tt_llcht.h
@@ -12,7 +12,7 @@
General Public License for more details.
You should have received a copy of the GNU General Public License
- along with Takwrap. If not, see <https://www.gnu.org/licenses/>.
+ along with ct. If not, see <https://www.gnu.org/licenses/>.
*/
#ifndef TT_LLCHT_H
diff --git a/include/weights.c b/include/weights.c
index ec28401..1aba298 100644
--- a/include/weights.c
+++ b/include/weights.c
@@ -12,7 +12,7 @@
General Public License for more details.
You should have received a copy of the GNU General Public License
- along with Takwrap. If not, see <https://www.gnu.org/licenses/>.
+ along with ct. If not, see <https://www.gnu.org/licenses/>.
*/
#include "weights.h"
diff --git a/include/weights.h b/include/weights.h
index f736198..eff0a68 100644
--- a/include/weights.h
+++ b/include/weights.h
@@ -12,7 +12,7 @@
General Public License for more details.
You should have received a copy of the GNU General Public License
- along with Takwrap. If not, see <https://www.gnu.org/licenses/>.
+ along with ct. If not, see <https://www.gnu.org/licenses/>.
*/
#define KERN_SIZE 3
diff --git a/include/xorshift64.c b/include/xorshift64.c
index b743d68..6fd8577 100644
--- a/include/xorshift64.c
+++ b/include/xorshift64.c
@@ -12,7 +12,7 @@
General Public License for more details.
You should have received a copy of the GNU General Public License
- along with Takwrap. If not, see <https://www.gnu.org/licenses/>.
+ along with ct. If not, see <https://www.gnu.org/licenses/>.
*/
#include "xorshift64.h"
diff --git a/include/xorshift64.h b/include/xorshift64.h
index 0b48f39..54392a0 100644
--- a/include/xorshift64.h
+++ b/include/xorshift64.h
@@ -12,7 +12,7 @@
General Public License for more details.
You should have received a copy of the GNU General Public License
- along with Takwrap. If not, see <https://www.gnu.org/licenses/>.
+ along with ct. If not, see <https://www.gnu.org/licenses/>.
*/
#ifndef XORSHIFT_H
diff --git a/include/zobrist.c b/include/zobrist.c
index bedfa68..48a115b 100644
--- a/include/zobrist.c
+++ b/include/zobrist.c
@@ -12,7 +12,7 @@
General Public License for more details.
You should have received a copy of the GNU General Public License
- along with Takwrap. If not, see <https://www.gnu.org/licenses/>.
+ along with ct. If not, see <https://www.gnu.org/licenses/>.
*/
#include "zobrist.h"
diff --git a/include/zobrist.h b/include/zobrist.h
index 8bf19cb..be657fc 100644
--- a/include/zobrist.h
+++ b/include/zobrist.h
@@ -12,7 +12,7 @@
General Public License for more details.
You should have received a copy of the GNU General Public License
- along with Takwrap. If not, see <https://www.gnu.org/licenses/>.
+ along with ct. If not, see <https://www.gnu.org/licenses/>.
*/
#include <xorshift64.h>