mcts.c 2.21 KB
Newer Older
1
2
/* tarot implements the rules of the tarot game
 * Copyright (C) 2018, 2019  Vivien Kraus
Vivien Kraus's avatar
Vivien Kraus committed
3
 *
4
5
 * 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
6
 * the Free Software Foundation, version 3 of the License.
Vivien Kraus's avatar
Vivien Kraus committed
7
8
9
10
11
12
13
 *
 * 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
14
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
Vivien Kraus's avatar
Vivien Kraus committed
15
16
17
18
19
20
21
22
 */

#include <config.h>
#include <tarot/xml.h>
#include <tarot/mcts_private.h>
#include "xalloc.h"
#include <string.h>

Vivien Kraus's avatar
Vivien Kraus committed
23
24
25
26
27
#ifdef __FRAMAC__
#undef alignof
#define alignof(x) (16)
#endif /* __FRAMAC__ */

Vivien Kraus's avatar
Vivien Kraus committed
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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
size_t
tarot_mcts_construct (size_t max_mem, char *mem, size_t *alignment,
                      size_t max_pool)
{
  return mcts_construct (max_mem, mem, alignment, max_pool);
}

TarotMcts *
tarot_mcts_alloc (size_t max)
{
  size_t alignment;
  size_t required = mcts_construct (0, NULL, &alignment, max);
  size_t unused;
  void *mem = xmalloc (required);
  assert (alignment >= 1 && alignment <= alignof (max_align_t));
  unused = mcts_construct (required, mem, &alignment, max);
  assert (unused == required);
  (void) unused;
  return mem;
}

void
tarot_mcts_copy (TarotMcts * dest, const TarotMcts * source)
{
  mcts_copy (dest, source);
}

TarotMcts *
tarot_mcts_dup (size_t new_max_mem, const TarotMcts * source)
{
  TarotMcts *ret = tarot_mcts_alloc (new_max_mem);
  mcts_copy (ret, source);
  return ret;
}

void
tarot_mcts_free (TarotMcts * mcts)
{
  free (mcts);
}

TarotMctsError
tarot_mcts_set_base (TarotMcts * mcts, const TarotGame * base)
{
  return mcts_set_base (mcts, base);
}

void
tarot_mcts_seed (TarotMcts * mcts, size_t seed_size, const void *seed)
{
Vivien Kraus's avatar
Vivien Kraus committed
78
  mcts_seed (mcts, seed_size, seed);
Vivien Kraus's avatar
Vivien Kraus committed
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
}

TarotMctsError
tarot_mcts_run (TarotMcts * mcts, size_t n_iterations)
{
  return mcts_run (mcts, n_iterations);
}

const TarotGameEvent *
tarot_mcts_get_best (const TarotMcts * mcts)
{
  return mcts_get_best (mcts);
}

#include <tarot/mcts_private_impl.h>