Commit c4aebb7b authored by Vivien Kraus's avatar Vivien Kraus
Browse files

Merge branch 'develop' into 'master'

Develop

See merge request !182
parents b3554f5d 595aafe6
Pipeline #202035 passed with stages
in 62 minutes and 15 seconds
......@@ -3,8 +3,7 @@
*
* 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.
* the Free Software Foundation, version 3 of the License.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
......@@ -32,7 +31,10 @@ event_size (size_t n_data)
static inline void
event_copy_data (TarotGameEvent * event, size_t n, const unsigned int *data)
{
memcpy (event->data, data, n * sizeof (*data));
if (n != 0)
{
memcpy (event->data, data, n * sizeof (*data));
}
event->n = n;
}
......@@ -413,7 +415,14 @@ event_get_data (const TarotGameEvent * event, size_t *n, size_t start,
size_t max, TarotCard * cards)
{
*n = event->n;
memcpy (cards, event->data + start, max * sizeof (*cards));
if (max > event->n)
{
max = event->n;
}
if (max != 0)
{
memcpy (cards, event->data + start, max * sizeof (*cards));
}
}
static inline TarotGameEventError
......
# tarot implements the rules of the tarot game
# Copyright (C) 2019 Vivien Kraus
# Copyright (C) 2019, 2020 Vivien Kraus
# 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.
# the Free Software Foundation, version 3 of the License.
#
# This program is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
......@@ -22,7 +21,7 @@ src_libtarot_libtarot_la_SOURCES += \
%reldir%/features.c \
%reldir%/tarot/features_private.h \
%reldir%/tarot/features_private_impl.h \
$(dist_model_DATA:.model=.h)
$(MODEL_SOURCE_HEADER_FILES)
INTROSPECTED_SOURCES += %reldir%/features.c
......
......@@ -3,8 +3,7 @@
*
* 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.
* the Free Software Foundation, version 3 of the License.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
......@@ -322,6 +321,12 @@ tarot_features_strongest_player (size_t n_players,
confidence, call);
}
double
tarot_features_errors (const TarotGame * game)
{
return features_errors (game);
}
size_t
tarot_predictor_construct (size_t max_mem, char *mem, size_t *alignment)
{
......
......@@ -3,8 +3,7 @@
*
* 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.
* the Free Software Foundation, version 3 of the License.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
......@@ -47,7 +46,10 @@ extern "C"
* @encoded: (type boolean):
* @dest_out: (array length=max):
*/
size_t tarot_features_arff_data (const struct TarotGame *base, const struct TarotGameEvent *added, int score, int encoded, size_t max, char *dest_out);
size_t tarot_features_arff_data (const struct TarotGame *base,
const struct TarotGameEvent *added,
int score, int encoded, size_t max,
char *dest_out);
/**
* tarot_features_arff_data_alloc:
......@@ -56,7 +58,9 @@ extern "C"
* @encoded: (type boolean):
* @returns: (transfer full):
*/
char *tarot_features_arff_data_alloc (const struct TarotGame *base, const struct TarotGameEvent *added, int score, int encoded);
char *tarot_features_arff_data_alloc (const struct TarotGame *base,
const struct TarotGameEvent *added,
int score, int encoded);
/* General-purpose features */
......@@ -66,7 +70,8 @@ extern "C"
* @n_players: (out):
* @with_call: (type boolean) (out):
*/
void tarot_features_variant (const struct TarotGame *game, size_t *n_players, int *with_call);
void tarot_features_variant (const struct TarotGame *game,
size_t *n_players, int *with_call);
/**
* tarot_features_position:
......@@ -75,14 +80,16 @@ extern "C"
* @position: (out): the number of players that play before me (for
* bids, decls, or for the current trick)
*/
void tarot_features_position (const struct TarotGame *game, size_t *i_trick, size_t *position);
void tarot_features_position (const struct TarotGame *game, size_t *i_trick,
size_t *position);
/**
* tarot_features_partner_known:
* @game: (type TarotGame):
* @known: (out) (type boolean):
*/
void tarot_features_partner_known (const struct TarotGame *game, int *known);
void tarot_features_partner_known (const struct TarotGame *game,
int *known);
/* Features specific to bidding */
......@@ -91,7 +98,8 @@ extern "C"
* @game: (type TarotGame):
* @minimum: (out):
*/
void tarot_features_bid_minimum (const struct TarotGame *game, TarotBid *minimum);
void tarot_features_bid_minimum (const struct TarotGame *game,
TarotBid * minimum);
/**
* tarot_features_count_faces:
......@@ -103,11 +111,10 @@ extern "C"
* @n_knights: (out):
*/
void tarot_features_count_faces (const struct TarotGame *game,
size_t *n_kings,
size_t *n_marriages,
size_t *n_extended_marriages,
size_t *n_queens,
size_t *n_knights);
size_t *n_kings,
size_t *n_marriages,
size_t *n_extended_marriages,
size_t *n_queens, size_t *n_knights);
/**
* tarot_features_count_minor:
......@@ -118,11 +125,11 @@ extern "C"
* @n_longest: (out):
*/
void tarot_features_count_minor (const struct TarotGame *game,
size_t *n_shortest,
size_t *n_second_shortest,
size_t *n_second_longest,
size_t *n_longest);
size_t *n_shortest,
size_t *n_second_shortest,
size_t *n_second_longest,
size_t *n_longest);
/**
* tarot_features_count_oudlers:
* @game: (type TarotGame):
......@@ -131,9 +138,8 @@ extern "C"
* @has_twentyone: (out) (type boolean):
*/
void tarot_features_count_oudlers (const struct TarotGame *game,
int *has_petit,
int *has_excuse,
int *has_twentyone);
int *has_petit,
int *has_excuse, int *has_twentyone);
/**
* tarot_features_count_trumps:
......@@ -146,12 +152,12 @@ extern "C"
* @median_trumps: (out):
*/
void tarot_features_count_trumps (const struct TarotGame *game,
size_t *n_trumps,
TarotNumber *max_trump,
TarotNumber *min_trump,
TarotNumber *q1_trumps,
TarotNumber *q3_trumps,
TarotNumber *median_trumps);
size_t *n_trumps,
TarotNumber * max_trump,
TarotNumber * min_trump,
TarotNumber * q1_trumps,
TarotNumber * q3_trumps,
TarotNumber * median_trumps);
/**
* tarot_strategy_bid:
......@@ -160,8 +166,8 @@ extern "C"
* @bid: (out):
*/
void tarot_strategy_bid (const struct TarotGame *game,
const struct TarotGameEvent *event,
TarotBid *bid);
const struct TarotGameEvent *event,
TarotBid * bid);
/**
* tarot_strategy_outbid:
......@@ -170,8 +176,8 @@ extern "C"
* @outbid: (out):
*/
void tarot_strategy_outbid (const struct TarotGame *game,
const struct TarotGameEvent *event,
int *outbid);
const struct TarotGameEvent *event,
int *outbid);
/**
* tarot_strategy_call_by_length:
......@@ -183,11 +189,10 @@ extern "C"
* @longest: (out) (type boolean):
*/
void tarot_strategy_call_by_length (const struct TarotGame *game,
const struct TarotGameEvent *event,
int *shortest,
int *second_shortest,
int *second_longest,
int *longest);
const struct TarotGameEvent *event,
int *shortest,
int *second_shortest,
int *second_longest, int *longest);
/**
* tarot_strategy_call_myself:
......@@ -196,8 +201,8 @@ extern "C"
* @myself: (out) (type boolean):
*/
void tarot_strategy_call_myself (const struct TarotGame *game,
const struct TarotGameEvent *event,
int *myself);
const struct TarotGameEvent *event,
int *myself);
/**
* tarot_strategy_call_marriage:
......@@ -206,8 +211,8 @@ extern "C"
* @will_own_marriage: (out) (type boolean):
*/
void tarot_strategy_call_marriage (const struct TarotGame *game,
const struct TarotGameEvent *event,
int *will_own_marriage);
const struct TarotGameEvent *event,
int *will_own_marriage);
/**
* tarot_strategy_discard_save:
......@@ -218,10 +223,10 @@ extern "C"
* @n_jacks_saved: (out):
*/
void tarot_strategy_discard_save (const struct TarotGame *game,
const struct TarotGameEvent *event,
size_t *n_queens_saved,
size_t *n_knights_saved,
size_t *n_jacks_saved);
const struct TarotGameEvent *event,
size_t *n_queens_saved,
size_t *n_knights_saved,
size_t *n_jacks_saved);
/**
* tarot_strategy_discard_junk:
......@@ -230,8 +235,8 @@ extern "C"
* @n_lesser_cards_left_behind: (out):
*/
void tarot_strategy_discard_junk (const struct TarotGame *game,
const struct TarotGameEvent *event,
size_t *n_lesser_cards_left_behind);
const struct TarotGameEvent *event,
size_t *n_lesser_cards_left_behind);
/**
* tarot_strategy_discard_by_length:
......@@ -243,11 +248,11 @@ extern "C"
* @from_longest: (out):
*/
void tarot_strategy_discard_by_length (const struct TarotGame *game,
const struct TarotGameEvent *event,
size_t *from_shortest,
size_t *from_second_shortest,
size_t *from_second_longest,
size_t *from_longest);
const struct TarotGameEvent *event,
size_t *from_shortest,
size_t *from_second_shortest,
size_t *from_second_longest,
size_t *from_longest);
/**
* tarot_features_team:
......@@ -256,8 +261,7 @@ extern "C"
* @defence: (out) (type boolean): whether we may be a defendent
*/
void tarot_features_team (const struct TarotGame *game,
int *attack,
int *defence);
int *attack, int *defence);
/**
* tarot_features_trick_players:
......@@ -266,8 +270,8 @@ extern "C"
* @n_allies_after_last_opponent: (out):
*/
void tarot_features_trick_players (const struct TarotGame *game,
size_t *n_already_played,
size_t *n_allies_after_last_opponent);
size_t *n_already_played,
size_t *n_allies_after_last_opponent);
/**
* tarot_features_minor_suit:
......@@ -286,12 +290,12 @@ extern "C"
* @n_remaining_points: (out):
*/
void tarot_features_minor_suit (const struct TarotGame *game,
int *called_suit,
size_t *n_times_lead,
size_t *n_remaining_cards,
size_t *n_remaining_points,
int *ally_may_be_master,
int *ennemy_may_be_master);
int *called_suit,
size_t *n_times_lead,
size_t *n_remaining_cards,
size_t *n_remaining_points,
int *ally_may_be_master,
int *ennemy_may_be_master);
/**
* tarot_features_trump:
......@@ -301,9 +305,9 @@ extern "C"
* @ennemy_may_be_master: (out) (type boolean):
*/
void tarot_features_trump (const struct TarotGame *game,
size_t *n_remaining,
int *ally_may_be_master,
int *ennemy_may_be_master);
size_t *n_remaining,
int *ally_may_be_master,
int *ennemy_may_be_master);
/**
* tarot_features_points:
......@@ -312,8 +316,7 @@ extern "C"
* @n_oudlers: (out):
*/
void tarot_features_points (const struct TarotGame *game,
size_t *n_halfpoints,
size_t *n_oudlers);
size_t *n_halfpoints, size_t *n_oudlers);
/**
* tarot_strategy_lead:
......@@ -325,11 +328,10 @@ extern "C"
* @trumps: (out) (type boolean):
*/
void tarot_strategy_lead (const struct TarotGame *game,
const struct TarotGameEvent *card,
int *called_suit,
size_t *suit_length,
size_t *n_times_lead,
int *trumps);
const struct TarotGameEvent *card,
int *called_suit,
size_t *suit_length,
size_t *n_times_lead, int *trumps);
/**
* tarot_strategy_purity:
......@@ -341,11 +343,10 @@ extern "C"
* @n_greater_kept: (out):
*/
void tarot_strategy_purity (const struct TarotGame *game,
const struct TarotGameEvent *event,
size_t *n_smaller_kept,
size_t *n_greater_nonface_kept,
size_t *n_points_kept,
size_t *n_greater_kept);
const struct TarotGameEvent *event,
size_t *n_smaller_kept,
size_t *n_greater_nonface_kept,
size_t *n_points_kept, size_t *n_greater_kept);
/**
* tarot_strategy_excuse:
......@@ -354,8 +355,7 @@ extern "C"
* @excuse: (out) (type boolean):
*/
void tarot_strategy_excuse (const struct TarotGame *game,
const struct TarotGameEvent *card,
int *excuse);
const struct TarotGameEvent *card, int *excuse);
/**
* tarot_strategy_trump_master:
......@@ -365,9 +365,9 @@ extern "C"
* @obvious_master: (out) (type boolean):
*/
void tarot_strategy_trump_master (const struct TarotGame *game,
const struct TarotGameEvent *card,
int *actually_master,
int *obvious_master);
const struct TarotGameEvent *card,
int *actually_master,
int *obvious_master);
/**
* tarot_strategy_play_points:
......@@ -377,9 +377,8 @@ extern "C"
* @oudler: (out) (type bool):
*/
void tarot_strategy_play_points (const struct TarotGame *game,
const struct TarotGameEvent *card,
size_t *n_halfpoints,
int *oudler);
const struct TarotGameEvent *card,
size_t *n_halfpoints, int *oudler);
/**
* tarot_features_strongest_player:
......@@ -389,15 +388,20 @@ extern "C"
* @call: (out):
*/
TarotPlayer tarot_features_strongest_player (size_t n_players,
int with_call,
size_t n_cards,
const TarotPlayer *owners,
double *confidence,
TarotCard *call);
int with_call,
size_t n_cards,
const TarotPlayer * owners,
double *confidence,
TarotCard * call);
/**
* tarot_features_errors:
*/
double tarot_features_errors (const TarotGame * game);
struct TarotPredictor;
typedef struct TarotPredictor TarotPredictor;
struct TarotGameEvent;
struct TarotGame;
......@@ -407,24 +411,27 @@ extern "C"
* @mem_out: (array length=max_mem):
* @alignment: (out):
*/
size_t tarot_predictor_construct (size_t max_mem, char *mem_out, size_t *alignment);
size_t tarot_predictor_construct (size_t max_mem, char *mem_out,
size_t *alignment);
void tarot_predictor_copy (TarotPredictor *predictor, const TarotPredictor *source);
void tarot_predictor_copy (TarotPredictor * predictor,
const TarotPredictor * source);
/**
* tarot_predictor_alloc: (constructor)
*/
TarotPredictor *tarot_predictor_alloc (void);
TarotPredictor *tarot_predictor_dup (const TarotPredictor *predictor);
TarotPredictor *tarot_predictor_dup (const TarotPredictor * predictor);
void tarot_predictor_free (TarotPredictor *predictor);
void tarot_predictor_free (TarotPredictor * predictor);
/**
* tarot_predictor_set_game:
* @game: (type TarotGame):
*/
void tarot_predictor_set_game (TarotPredictor *predictor, const struct TarotGame *game);
void tarot_predictor_set_game (TarotPredictor * predictor,
const struct TarotGame *game);
/**
......@@ -432,31 +439,37 @@ extern "C"
* @score: (out):
* @returns: (nullable) (type Tarot.GameEvent) (transfer none):
*/
const struct TarotGameEvent *tarot_predictor_best (const TarotPredictor *predictor, double *score);
const struct TarotGameEvent *tarot_predictor_best (const TarotPredictor *
predictor,
double *score);
/**
* tarot_predictor_eval:
* @score_out: (array length=max):
* @candidates: (array length=n_candidates) (type TarotGameEvent*) (transfer none):
*/
size_t tarot_predictor_eval (const TarotPredictor *predictor, size_t n_candidates, struct TarotGameEvent **candidates,
size_t start, size_t max, double *score_out);
size_t tarot_predictor_eval (const TarotPredictor * predictor,
size_t n_candidates,
struct TarotGameEvent **candidates,
size_t start, size_t max, double *score_out);
/**
* tarot_features_cnn_add:
* @data_out: (array length=max):
*/
size_t tarot_features_cnn_add (const TarotGame *game, size_t max, double *data_out);
size_t tarot_features_cnn_add (const TarotGame * game, size_t max,
double *data_out);
/**
* tarot_features_cnn_alloc:
* @data: (out) (transfer full) (array length=n):
* @n: (out):
*/
void tarot_features_cnn_alloc (const TarotGame *game, double **data, size_t *n);
void tarot_features_cnn_alloc (const TarotGame * game, double **data,
size_t *n);
#ifdef __cplusplus
}
#endif /* __cplusplus */
#endif /* __cplusplus */
#endif /* not H_TAROT_FEATURES_INCLUDED */
#endif /* not H_TAROT_FEATURES_INCLUDED */
......@@ -3,8 +3,7 @@
*
* 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.
* the Free Software Foundation, version 3 of the License.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
......@@ -134,6 +133,8 @@ extern "C"
const TarotPlayer * owners,
double *confidence,
TarotCard * call);
static double features_errors (const TarotGame * game);
static double features_errors_just_bids (const TarotGame * game);
static size_t predictor_construct (size_t max_mem, char *mem,
size_t *alignment);
......
......@@ -3,8 +3,7 @@
*
* 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.
* the Free Software Foundation, version 3 of the License.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
......@@ -29,6 +28,7 @@
#include <string.h>
#include <float.h>
#include <errno.h>
#include "xalloc.h"
static char *features_header_data = NULL;
static char *features_header_encoded_data = NULL;
......@@ -49,6 +49,7 @@ features_fopen_in_dir (const char *dir, const char *basename)
strerror (errno));
abort ();
}
free (filename);
return f;
}
......@@ -290,56 +291,55 @@ features_arff_data (const TarotGame * game, const TarotGameEvent * added,
int s_trump_obvious_master;
size_t s_halfpoints;
int s_oudler;
TarotSuit order[4];
TarotCounter counter;
size_t ret = 0;
tarot_features_variant (game, &f_n_players, &f_with_call);
tarot_features_position (game, &f_trick, &f_position);
tarot_features_partner_known (game, &f_partner_known);
tarot_features_bid_minimum (game, &f_bid_minimum);
tarot_features_count_faces (game, &f_n_kings, &f_n_marriages,
&f_n_extended_marriages, &f_n_queens,
&f_n_knights);
tarot_features_count_minor (game, &f_n_shortest, &f_n_second_shortest,
&f_n_second_longest, &f_n_longest);
tarot_features_count_oudlers (game, &f_has_petit, &f_has_excuse,
&f_has_twentyone);
tarot_features_count_trumps (game, &f_n_trumps, &f_max_trump, &f_min_trump,
&f_q1_trumps, &f_q3_trumps, &f_median_trumps);
tarot_features_team (game, &f_team_attack, &f_team_defence);
tarot_features_trick_players (game, &f_n_trick_players_already_played,
&f_n_allies_after_last_opponent);
tarot_features_minor_suit (game, &f_play_called_suit, &f_play_n_times_lead,
&f_play_suit_remaining,
&f_play_suit_remaining_points,
&f_ally_may_be_minor_master,
&f_ennemy_may_be_minor_master);
tarot_features_trump (game, &f_n_trumps_remaining,
&f_ally_may_be_trump_master,
&f_ennemy_may_be_trump_master);