/* This file is part of ct. This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with ct. If not, see . */ #include "cnn1986.h" #include "weights.h" // =================================================================== // Implementation of a small convolutional neural network // =================================================================== static float flattened[CONV_NUM+2]; 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< 1.0) { return 1.0; } else if (output < -1.0) { return -1.0; } return output; }