blob: 9c120f504fa91ac4c27b7ac896318e9838f342ba (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
|
/*
This file is part of ctak.
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 ctak. If not, see <https://www.gnu.org/licenses/>.
*/
#include "pv.h"
#ifdef RECORD_PV
#include "nn.h"
static pv_leaf_t published_leaf;
static float terminal_value(const enum WIN_TYPE winner) {
switch (winner) {
case WIN_FLAT_BLACK:
case WIN_ROAD_BLACK:
return 1.0f;
case WIN_FLAT_WHITE:
case WIN_ROAD_WHITE:
return -1.0f;
default:
return 0.0f;
}
}
void pv_capture_leaf(pv_leaf_t *leaf, tak_state_p state,
const enum WIN_TYPE winner) {
nn_prepare_head(leaf->head, state);
nn_cell_idxs(leaf->cells, state);
const uint8_t n_cells = state->board_size * state->board_size;
for (uint8_t loc = n_cells; loc < PV_MAX_CELLS; loc++)
leaf->cells[loc] = 0;
leaf->current_colour = (uint8_t)state->current_colour;
leaf->terminal = (uint8_t)(winner < 0xFF);
leaf->terminal_value = leaf->terminal ? terminal_value(winner) : 0.0f;
}
void pv_publish_leaf(const pv_leaf_t *leaf) { published_leaf = *leaf; }
const pv_leaf_t *pv_get_leaf(void) { return &published_leaf; }
#else
typedef int pv_disabled_translation_unit;
#endif
|