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
# 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,6 +21,6 @@ bin_PROGRAMS += %reldir%/tarot-stacking
%reldir%/libprogram-commons.la \
lib/libgnu.la \
src/libtarot/libtarot.la \
$(LTLIBINTL) \
$(LTLIBTHREAD) \
@INTL_MACOSX_LIBS@
$(AM_LDADD)
INDENTED += %reldir%/tarot_stacking.c
# 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,6 +21,6 @@ bin_PROGRAMS += %reldir%/tarot-status
%reldir%/libprogram-commons.la \
lib/libgnu.la \
src/libtarot/libtarot.la \
$(LTLIBINTL) \
$(LTLIBTHREAD) \
@INTL_MACOSX_LIBS@
$(AM_LDADD)
INDENTED += %reldir%/tarot_status.c
......@@ -4,8 +4,7 @@ Copyright (C) 2019 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
......
......@@ -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
......@@ -16,7 +15,6 @@
*/
#include "program_commons.h"
#include <tuneconfig.h>
static int generate_whole_game = 0;
......@@ -40,31 +38,31 @@ main (int argc, char *argv[])
{
double score;
if (generate_whole_game)
{
TarotPlayer next;
if (tarot_game_get_next (game, &next) != TAROT_GAME_OK)
{
break;
}
}
{
TarotPlayer next;
if (tarot_game_get_next (game, &next) != TAROT_GAME_OK)
{
break;
}
}
tarot_predictor_set_game (cnn, game);
event = tarot_predictor_best (cnn, &score);
if (tarot_game_add_event (game, event) != TAROT_GAME_OK)
{
abort ();
}
{
abort ();
}
if (tarot_game_can_autoreveal_alloc (game, &n_cards, &cards))
{
dog_event = tarot_game_event_alloc_dog (n_cards, cards);
if (tarot_game_add_event (game, dog_event) != TAROT_GAME_OK)
{
abort ();
}
}
{
dog_event = tarot_game_event_alloc_dog (n_cards, cards);
if (tarot_game_add_event (game, dog_event) != TAROT_GAME_OK)
{
abort ();
}
}
if (!generate_whole_game)
{
break;
}
{
break;
}
}
output = tarot_game_save_to_xml_alloc (game);
printf ("%s", output);
......@@ -77,18 +75,19 @@ parse_options (int argc, char *argv[])
int c;
while (1)
{
static struct option long_options[] =
{
{N_ ("help"), no_argument, 0, 'h'},
{N_ ("version"), no_argument, 0, 'v'},
{N_ ("generate"), no_argument, 0, 'g'},
{0, 0, 0, 0}
};
static struct option long_options[] = {
{N_("help"), no_argument, 0, 'h'},
{N_("version"), no_argument, 0, 'v'},
{N_("generate"), no_argument, 0, 'g'},
{0, 0, 0, 0}
};
int option_index = 0;
for (option_index = 0; long_options[option_index].name != NULL; option_index++)
{
long_options[option_index].name = _ (long_options[option_index].name);
}
for (option_index = 0; long_options[option_index].name != NULL;
option_index++)
{
long_options[option_index].name =
_(long_options[option_index].name);
}
option_index = 0;
c = getopt_long (argc, argv, "hvg", long_options, &option_index);
if (c == -1)
......@@ -98,33 +97,31 @@ parse_options (int argc, char *argv[])
case 0:
break;
case 'h':
printf (_ ("Usage: tarot-cnn [OPTIONS]... < GAME\n\
case 'h':
printf (_("Usage: tarot-cnn [OPTIONS]... < GAME\n\
Play as the deep learner in GAME. Options:\n\
- -h, --help: print this message and exit;\n\
- -v, --version: print the program version and exit;\n\
- -g, --generate: play with the same player parameters until the end\n\
of the game.\n\
"));
exit (EXIT_SUCCESS);
break;
exit (EXIT_SUCCESS);
break;
case 'v':
printf (_ ("%s (libtarot %s)\n\
case 'v':
printf (_("%s (libtarot %s)\n\
\n\
Copyright © 2019 Vivien Kraus\nThis is free software; see the source for copying conditions. There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.\n"),
"tarot-cnn",
tarot_libtarot_version ());
exit (EXIT_SUCCESS);
break;
Copyright © 2019 Vivien Kraus\nThis is free software; see the source for copying conditions. There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.\n"), "tarot-cnn", tarot_libtarot_version ());
exit (EXIT_SUCCESS);
break;
case 'g':
generate_whole_game = 1;
break;
case 'g':
generate_whole_game = 1;
break;
case '?':
/* getopt_long already printed an error message. */
exit (EXIT_FAILURE);
exit (EXIT_FAILURE);
break;
default:
......@@ -133,9 +130,9 @@ Copyright © 2019 Vivien Kraus\nThis is free software; see the source for copyin
}
if (optind < argc)
{
fprintf (stderr, _ ("Error: extra arguments:\n"));
fprintf (stderr, _("Error: extra arguments:\n"));
while (optind < argc)
fprintf (stderr, _ ("- %s\n"), argv[optind++]);
fprintf (stderr, _("- %s\n"), argv[optind++]);
exit (EXIT_FAILURE);
}
}
......@@ -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
......@@ -16,13 +15,13 @@
*/
#include "program_commons.h"
#include <tuneconfig.h>
static void parse_options (int argc, char *argv[]);
static void print_row (size_t n, const double *row);
static void
event_handler (const TarotGame *base, TarotPlayer next, const TarotGameEvent *event)
event_handler (const TarotGame * base, TarotPlayer next,
const TarotGameEvent * event)
{
(void) next;
TarotGame *rebuilt = tarot_game_dup (base);
......@@ -54,17 +53,18 @@ parse_options (int argc, char *argv[])
int c;
while (1)
{
static struct option long_options[] =
{
{N_ ("help"), no_argument, 0, 'h'},
{N_ ("version"), no_argument, 0, 'v'},
{0, 0, 0, 0}
};
static struct option long_options[] = {
{N_("help"), no_argument, 0, 'h'},
{N_("version"), no_argument, 0, 'v'},
{0, 0, 0, 0}
};
int option_index = 0;
for (option_index = 0; long_options[option_index].name != NULL; option_index++)
{
long_options[option_index].name = _ (long_options[option_index].name);
}
for (option_index = 0; long_options[option_index].name != NULL;
option_index++)
{
long_options[option_index].name =
_(long_options[option_index].name);
}
option_index = 0;
c = getopt_long (argc, argv, "hv", long_options, &option_index);
if (c == -1)
......@@ -74,28 +74,27 @@ parse_options (int argc, char *argv[])
case 0:
break;
case 'h':
printf (_ ("Usage: tarot-cnn-features [OPTIONS]... < GAME > FEATURES\n\
case 'h':
printf (_
("Usage: tarot-cnn-features [OPTIONS]... < GAME > FEATURES\n\
Extract the tensor-shaped game features. See the info manual for the\n\
details. Options:\n\
- -h, --help: print this message and exit;\n\
- -v, --version: print the program version and exit.\n\
"));
exit (EXIT_SUCCESS);
break;
exit (EXIT_SUCCESS);
break;
case 'v':
printf (_ ("%s (libtarot %s)\n\
case 'v':
printf (_("%s (libtarot %s)\n\
\n\
Copyright © 2019 Vivien Kraus\nThis is free software; see the source for copying conditions. There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.\n"),
"tarot-cnn-features",
tarot_libtarot_version ());
exit (EXIT_SUCCESS);
break;
Copyright © 2019 Vivien Kraus\nThis is free software; see the source for copying conditions. There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.\n"), "tarot-cnn-features", tarot_libtarot_version ());
exit (EXIT_SUCCESS);
break;
case '?':
/* getopt_long already printed an error message. */
exit (EXIT_FAILURE);
exit (EXIT_FAILURE);
break;
default:
......@@ -104,9 +103,9 @@ Copyright © 2019 Vivien Kraus\nThis is free software; see the source for copyin
}
if (optind < argc)
{
fprintf (stderr, _ ("Error: extra arguments:\n"));
fprintf (stderr, _("Error: extra arguments:\n"));
while (optind < argc)
fprintf (stderr, _ ("- %s\n"), argv[optind++]);
fprintf (stderr, _("- %s\n"), argv[optind++]);
exit (EXIT_FAILURE);
}
}
......@@ -118,21 +117,21 @@ print_row (size_t n, const double *data)
for (i = 0; i < n; i++)
{
if (i != 0)
{
printf (",");
}
{
printf (",");
}
if (data[i] == 0.0)
{
printf ("0");
}
{
printf ("0");
}
else if (data[i] == 1.0)
{
printf ("1");
}
{
printf ("1");
}
else
{
printf ("%f", data[i]);
}
{
printf ("%f", data[i]);
}
}
printf ("\n");
}
......@@ -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
......@@ -36,17 +35,22 @@ main (int argc, char *argv[])
parse_options (argc, argv);
game = tarot_game_alloc ();
setup_event = tarot_game_event_alloc_setup (n_players, with_call);
deal_event = tarot_game_event_alloc_deal_all_random (n_players, strlen (*seed), *seed);
deal_event =
tarot_game_event_alloc_deal_all_random (n_players, strlen (*seed), *seed);
if (tarot_game_add_event (game, setup_event) != TAROT_GAME_OK)
{
fprintf (stderr, _ ("Error: could not set the game up for %lu players (call: %d)\n"),
n_players, with_call);
fprintf (stderr,
_
("Error: could not set the game up for %lu players (call: %d)\n"),
n_players, with_call);
return EXIT_FAILURE;
}
if (tarot_game_add_event (game, deal_event) != TAROT_GAME_OK)
{
fprintf (stderr, _ ("Error: could not use this random seed, '%s', to deal. Please retry with a different seed.\n"),
*seed);
fprintf (stderr,
_
("Error: could not use this random seed, '%s', to deal. Please retry with a different seed.\n"),
*seed);
return EXIT_FAILURE;
}
output = tarot_game_save_to_xml_alloc (game);
......@@ -61,21 +65,22 @@ parse_options (int argc, char *argv[])
char *end;
while (1)
{
static struct option long_options[] =
{
{N_ ("help"), no_argument, 0, 'h'},
{N_ ("version"), no_argument, 0, 'v'},
{N_ ("n-players"), required_argument, 0, 'n'},
{N_ ("call-allowed"), no_argument, 0, 'c'},
{N_ ("no-call-allowed"), no_argument, &with_call, 0},
{N_ ("seed"), required_argument, 0, 's'},
{0, 0, 0, 0}
};
static struct option long_options[] = {
{N_("help"), no_argument, 0, 'h'},
{N_("version"), no_argument, 0, 'v'},
{N_("n-players"), required_argument, 0, 'n'},
{N_("call-allowed"), no_argument, 0, 'c'},
{N_("no-call-allowed"), no_argument, &with_call, 0},
{N_("seed"), required_argument, 0, 's'},
{0, 0, 0, 0}
};
int option_index = 0;
for (option_index = 0; long_options[option_index].name != NULL; option_index++)
{
long_options[option_index].name = _ (long_options[option_index].name);
}
for (option_index = 0; long_options[option_index].name != NULL;
option_index++)
{
long_options[option_index].name =
_(long_options[option_index].name);
}
option_index = 0;
c = getopt_long (argc, argv, "hvn:cs:", long_options, &option_index);
if (c == -1)
......@@ -85,8 +90,8 @@ parse_options (int argc, char *argv[])
case 0:
break;
case 'h':
printf (_ ("Usage: tarot-deal [OPTIONS]...\n\
case 'h':
printf (_("Usage: tarot-deal [OPTIONS]...\n\
Create a new game with a random deal for all players. Options:\n\
- -h, --help: print this message and exit\n\
- -v, --version: print the program version and exit\n\
......@@ -100,50 +105,54 @@ Create a new game with a random deal for all players. Options:\n\
If the seed leads to a petit sec, then the deal fails. So in case of\n\
a failure you may want to retry for a few different seeds.\n\
"), n_players);
exit (EXIT_SUCCESS);
break;
exit (EXIT_SUCCESS);
break;
case 'v':
printf (_ ("%s (libtarot %s)\n\
case 'v':
printf (_("%s (libtarot %s)\n\
\n\
Copyright © 2019 Vivien Kraus\nThis is free software; see the source for copying conditions. There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.\n"),
"tarot-deal",
tarot_libtarot_version ());
exit (EXIT_SUCCESS);
break;
Copyright © 2019 Vivien Kraus\nThis is free software; see the source for copying conditions. There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.\n"), "tarot-deal", tarot_libtarot_version ());
exit (EXIT_SUCCESS);
break;
case 'n':
n_players = strtoul (optarg, &end, 10);
if (strcmp (end, optarg) == 0)
{
fprintf (stderr, _ ("Error: the number of players should be a number, not '%s'.\n"),
optarg);
exit (EXIT_FAILURE);
}
else if (strcmp (end, "") != 0)
{
fprintf (stderr, _ ("Error: the number of players (%lu) has an unexpected suffix, '%s': '%s'.\n"),
n_players, end, optarg);
exit (EXIT_FAILURE);
}
n_players = strtoul (optarg, &end, 10);
if (strcmp (end, optarg) == 0)
{
fprintf (stderr,
_
("Error: the number of players should be a number, not '%s'.\n"),
optarg);
exit (EXIT_FAILURE);
}
else if (strcmp (end, "") != 0)
{
fprintf (stderr,
_
("Error: the number of players (%lu) has an unexpected suffix, '%s': '%s'.\n"),
n_players, end, optarg);
exit (EXIT_FAILURE);
}
break;
case 'c':
with_call = 1;
with_call = 1;
break;
case 's':
*seed = strdup (optarg);
if (strlen (*seed) == 0)
{
fprintf (stderr, _ ("Error: the seed must not be empty. The default is usually \"default\".\n"));
exit (EXIT_FAILURE);
}
*seed = strdup (optarg);
if (strlen (*seed) == 0)
{
fprintf (stderr,
_
("Error: the seed must not be empty. The default is usually \"default\".\n"));
exit (EXIT_FAILURE);
}
break;
case '?':
/* getopt_long already printed an error message. */
exit (EXIT_FAILURE);
exit (EXIT_FAILURE);
break;
default:
......@@ -152,9 +161,9 @@ Copyright © 2019 Vivien Kraus\nThis is free software; see the source for copyin
}
if (optind < argc)
{
fprintf (stderr, _ ("Error: extra arguments:\n"));
fprintf (stderr, _("Error: extra arguments:\n"));
while (optind < argc)
fprintf (stderr, _ ("- %s\n"), argv[optind++]);
fprintf (stderr, _("- %s\n"), argv[optind++]);
exit (EXIT_FAILURE);
}
}
......@@ -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
......@@ -16,16 +15,17 @@
*/
#include "program_commons.h"
#include <tuneconfig.h>
static int encoded = 0;
static void parse_options (int argc, char *argv[]);
static int score[5] = { 0, 0, 0, 0, 0 };
static void
event_handler (const TarotGame *base, TarotPlayer next, const TarotGameEvent *event)
event_handler (const TarotGame * base, TarotPlayer next,
const TarotGameEvent * event)
{
char *line = tarot_features_arff_data_alloc (base, event, score[next], encoded);
char *line =
tarot_features_arff_data_alloc (base, event, score[next], encoded);
printf ("%s", line);
free (line);
}
......@@ -41,11 +41,13 @@ main (int argc, char *argv[])
printf ("%s", tarot_features_arff_header (encoded));
if (tarot_game_get_scores (game, &n_players, 0, 5, score) != TAROT_GAME_OK)
{
fprintf (stderr, _ ("Error: this game is not finished yet.\n"));
fprintf (stderr, _("Error: this game is not finished yet.\n"));
tarot_game_free (game);
return EXIT_FAILURE;
}
assert (n_players <= 5);
tarot_program_iterate (game, &event_handler);
tarot_game_free (game);
return EXIT_SUCCESS;
}
......@@ -55,18 +57,19 @@ parse_options (int argc, char *argv[])
int c;
while (1)
{
static struct option long_options[] =
{
{N_ ("help"), no_argument, 0, 'h'},
{N_ ("version"), no_argument, 0, 'v'},
{N_ ("encoded"), no_argument, 0, 'e'},
{0, 0, 0, 0}
};
static struct option long_options[] = {
{N_("help"), no_argument, 0, 'h'},
{N_("version"), no_argument, 0, 'v'},
{N_("encoded"), no_argument, 0, 'e'},
{0, 0, 0, 0}
};
int option_index = 0;
for (option_index = 0; long_options[option_index].name != NULL; option_index++)
{
long_options[option_index].name = _ (long_options[option_index].name);
}
for (option_index = 0; long_options[option_index].name != NULL;
option_index++)
{
long_options[option_index].name =
_(long_options[option_index].name);
}
option_index = 0;
c = getopt_long (argc, argv, "hve", long_options, &option_index);
if (c == -1)
......@@ -76,32 +79,30 @@ parse_options (int argc, char *argv[])
case 0:
break;
case 'h':
printf (_ ("Usage: tarot-features [OPTIONS]... < GAME > FEATURES\n\
case 'h'