Commit 75b984d8 authored by Vivien Kraus's avatar Vivien Kraus
Browse files

Add a function to change the difficulty of the solo game

If we now bootstrap the perceptron on solo-generated games, we now
have an exploration parameter.
parent 87b8a259
.gnulib @ 8e771821
Subproject commit 3ae177f2d92775380a9eed65ee2791fdee5c1a35
Subproject commit 8e771821ac57d404132829ee4604e23853dc9ee6
......@@ -2611,8 +2611,15 @@ return the required size.
#+attr_texinfo: :options {TarotSolo *} tarot_solo_alloc (void)
#+begin_deftypefun
#+texinfo: @deftypefunx {TarotSolo *} tarot_solo_alloc_fuzzy (double @var{fuzziness}, size_t @var{seed_size}, const void *@var{seed}, const TarotAi *@var{ai})
#+texinfo: @deftypefunx {void} tarot_solo_free (TarotSolo *@var{solo})
Allocate and free a new game against the AI.
Allocate and free a new game against the AI. The fuzzy variant uses
an /AI/ that will incorporate a random evaluation in all moves. If
/fuzziness/ is set to 0, then no random evaluation will be considered.
If /fuzziness/ is set to 1, then all moves will be chosen at random.
If /ai/ is =NULL=, then a default AI will be used.
This is an easy way to change the difficulty of the game.
#+end_deftypefun
#+attr_texinfo: :options {void} tarot_solo_copy (TarotSolo *@var{dest}, const TarotSolo *@var{source})
......
......@@ -27,20 +27,57 @@
#define alignof(x) (16)
#endif /* __FRAMAC__ */
TarotSolo *
tarot_solo_alloc (void)
static inline TarotSolo *
solo_alloc_aux (const TarotAi * ai)
{
size_t alignment;
size_t required = solo_construct (0, NULL, &alignment);
size_t required = solo_construct (0, NULL, &alignment, ai);
size_t unused;
void *mem = xmalloc (required);
assert (alignment >= 1 && alignment <= alignof (max_align_t));
unused = solo_construct (required, mem, &alignment);
unused = solo_construct (required, mem, &alignment, ai);
assert (unused == required);
(void) unused;
return mem;
}
TarotSolo *
tarot_solo_alloc (void)
{
TarotAi *perceptron = tarot_ai_alloc_perceptron ();
TarotSolo *ret = solo_alloc_aux (perceptron);
tarot_ai_free (perceptron);
return ret;
}
static inline TarotSolo *
solo_alloc_fuzzy (double fuzziness, size_t seed_size, const void *seed,
const TarotAi * base)
{
TarotAi *ai = tarot_ai_alloc_fuzzy (fuzziness, seed_size, seed, base);
TarotSolo *ret = solo_alloc_aux (ai);
tarot_ai_free (ai);
return ret;
}
TarotSolo *
tarot_solo_alloc_fuzzy (double fuzziness, size_t seed_size, const void *seed,
const TarotAi * base)
{
TarotSolo *ret;
if (base == NULL)
{
TarotAi *perceptron = tarot_ai_alloc_perceptron ();
ret = solo_alloc_fuzzy (fuzziness, seed_size, seed, perceptron);
tarot_ai_free (perceptron);
}
else
{
ret = solo_alloc_fuzzy (fuzziness, seed_size, seed, base);
}
return ret;
}
TarotSolo *
tarot_solo_dup (const TarotSolo * source)
{
......@@ -59,7 +96,10 @@ tarot_solo_free (TarotSolo * solo)
size_t
tarot_solo_construct (size_t max_mem, char *mem, size_t *alignment)
{
return solo_construct (max_mem, mem, alignment);
TarotAi *perceptron = tarot_ai_alloc_perceptron ();
size_t ret = solo_construct (max_mem, mem, alignment, perceptron);
tarot_ai_free (perceptron);
return ret;
}
void
......
......@@ -21,6 +21,7 @@
#include <tarot/game.h>
#include <tarot/player.h>
#include <tarot/cards.h>
#include <tarot/ai.h>
#ifdef __cplusplus
extern "C"
......@@ -34,6 +35,14 @@ extern "C"
* tarot_solo_alloc: (constructor)
*/
TarotSolo *tarot_solo_alloc (void);
/**
* tarot_solo_alloc_fuzzy: (constructor)
* @seed: (array length=seed_size) (element-type char):
*/
TarotSolo *tarot_solo_alloc_fuzzy (double fuzziness, size_t seed_size,
const void *seed, const TarotAi * ai);
TarotSolo *tarot_solo_dup (const TarotSolo * source);
void tarot_solo_free (TarotSolo * solo);
......
......@@ -26,7 +26,7 @@ extern "C"
{
#endif /* __cplusplus */
static size_t solo_construct (size_t max_mem, char *mem_out,
size_t *alignment);
size_t *alignment, const TarotAi * ai);
static void solo_destruct (TarotSolo * solo);
static void solo_copy (TarotSolo * dest, const TarotSolo * source);
static void solo_copy_as (TarotSolo * dest, const TarotSolo * source,
......
......@@ -31,7 +31,8 @@
static inline void solo_advance (TarotSolo * dest);
static inline size_t
solo_construct (size_t max_mem, char *mem, size_t *alignment)
solo_construct (size_t max_mem, char *mem, size_t *alignment,
const TarotAi * ai)
{
size_t required = sizeof (TarotSolo);
*alignment = alignof (TarotSolo);
......@@ -40,7 +41,7 @@ solo_construct (size_t max_mem, char *mem, size_t *alignment)
TarotSolo *solo = (TarotSolo *) mem;
game_initialize (&(solo->game), 4, 0);
solo->myself = 0;
solo->ai = tarot_ai_alloc_perceptron ();
solo->ai = tarot_ai_dup (ai);
return max_mem;
}
return required;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment