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

Implement tarot-stacking

This program behaves exactly like =tarot-mcts=, except of course it
does not use the same algorithm.
parent d96b7a80
......@@ -130,6 +130,7 @@
/src/tarot-app/tarot-en
/src/tarot-app/tarot-mcts
/src/tarot-app/tarot-parser-stamp
/src/tarot-app/tarot-stacking
/src/tarot-app/tarot-status
/src/tarot-app/tarot-vala-stamp
/src/tarot-app/tarot_app.h
......
......@@ -25,7 +25,8 @@ MAINTAINERCLEANFILES += \
$(srcdir)/%reldir%/tarot.man \
$(srcdir)/%reldir%/tarot-status.man \
$(srcdir)/%reldir%/tarot-deal.man \
$(srcdir)/%reldir%/tarot-mcts.man
$(srcdir)/%reldir%/tarot-mcts.man \
$(srcdir)/%reldir%/tarot-stacking.man
help2man_verbose = $(help2man_verbose_@AM_V@)
help2man_verbose_ = $(help2man_verbose_@AM_DEFAULT_V@)
......@@ -46,3 +47,7 @@ $(srcdir)/%reldir%/tarot-deal.man: src/tarot-app/tarot_deal.c
$(srcdir)/%reldir%/tarot-mcts.man: src/tarot-app/tarot_mcts.c
$(MAKE) $(AM_MAKEFLAGS) src/tarot-app/tarot-mcts
$(help2man_verbose) ./pre-inst-env help2man tarot-mcts > $@
$(srcdir)/%reldir%/tarot-stacking.man: src/tarot-app/tarot_stacking.c
$(MAKE) $(AM_MAKEFLAGS) src/tarot-app/tarot-stacking
$(help2man_verbose) ./pre-inst-env help2man tarot-stacking > $@
......@@ -13,4 +13,5 @@ src/tarot-app/server.vala
src/tarot-app/tarot_status.c
src/tarot-app/tarot_deal.c
src/tarot-app/program_commons.c
src/tarot-app/tarot_mcts.c
\ No newline at end of file
src/tarot-app/tarot_mcts.c
src/tarot-app/tarot_stacking.c
\ No newline at end of file
......@@ -8,8 +8,8 @@ msgid ""
msgstr ""
"Project-Id-Version: tarot 0.4.2.83-ebdc-dirty\n"
"Report-Msgid-Bugs-To: vivien@planete-kraus.eu\n"
"POT-Creation-Date: 2019-08-25 10:32+0200\n"
"PO-Revision-Date: 2019-08-25 10:43+0200\n"
"POT-Creation-Date: 2019-08-25 11:07+0200\n"
"PO-Revision-Date: 2019-08-25 11:11+0200\n"
"Last-Translator: Vivien Kraus <vivien@planete-kraus.eu>\n"
"Language-Team: French\n"
"Language: fr\n"
......@@ -37,11 +37,13 @@ msgstr "Affiche l'information de version et quitte"
#: src/tarot-app/main.vala:83 src/tarot-app/main.vala:93
#: src/tarot-app/tarot_deal.c:70 src/tarot-app/tarot_mcts.c:100
#: src/tarot-app/tarot_stacking.c:87
msgid "version"
msgstr "version"
#: src/tarot-app/main.vala:100 src/tarot-app/tarot_status.c:58
#: src/tarot-app/tarot_deal.c:110 src/tarot-app/tarot_mcts.c:151
#: src/tarot-app/tarot_stacking.c:117
#, c-format
msgid ""
"%s (libtarot %s)\n"
......@@ -1138,6 +1140,7 @@ msgstr ""
"distribution. Veuillez réessayer avec une graine différente.\n"
#: src/tarot-app/tarot_deal.c:69 src/tarot-app/tarot_mcts.c:99
#: src/tarot-app/tarot_stacking.c:86
msgid "help"
msgstr "aide"
......@@ -1213,11 +1216,13 @@ msgstr ""
"habituellement « default ».\n"
#: src/tarot-app/tarot_deal.c:158 src/tarot-app/tarot_mcts.c:273
#: src/tarot-app/tarot_stacking.c:140
#, c-format
msgid "Error: extra arguments:\n"
msgstr "Erreur : arguments supplémentaires :\n"
#: src/tarot-app/tarot_deal.c:160 src/tarot-app/tarot_mcts.c:275
#: src/tarot-app/tarot_stacking.c:142
#, c-format
msgid "- %s\n"
msgstr "- %s\n"
......@@ -1263,7 +1268,7 @@ msgstr "paramètre-aléatoire"
msgid "parameter-agreed"
msgstr "paramètre-accord"
#: src/tarot-app/tarot_mcts.c:107
#: src/tarot-app/tarot_mcts.c:107 src/tarot-app/tarot_stacking.c:88
msgid "generate"
msgstr "générer"
......@@ -1417,6 +1422,23 @@ msgstr ""
"Erreur : la capacité de mémoire est épuisée. Veuillez passer --mémoire-"
"max=TAILLE.\n"
#: src/tarot-app/tarot_stacking.c:106
#, c-format
msgid ""
"Usage: tarot-stacking [OPTIONS]... < GAME\n"
"Play as the stacking 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"
msgstr ""
"Utilisation : tarot-stacking [OPTIONS]... < PARTIE\n"
"Joue comme l'apprenti stacking dans la PARTIE. Options :\n"
"- -h, --aide : affiche ce message et quitte ;\n"
"- -v, --version : affiche la version du programme et quitte ;\n"
"- -g, --générer : joue avec les mêmes paramètres jusqu'à la fin de la\n"
" partie.\n"
#~ msgid "Hello, world!\n"
#~ msgstr "Bonjour, le monde !\n"
......
......@@ -24,3 +24,4 @@ include %reldir%/tarot-program-commons.am
include %reldir%/tarot-status.am
include %reldir%/tarot-deal.am
include %reldir%/tarot-mcts.am
include %reldir%/tarot-stacking.am
# tarot-stacking.am
#
# Copyright (C) 2019 Vivien Kraus <vivien@planete-kraus.eu>
#
# 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 this program. If not, see
# <http://www.gnu.org/licenses/>.
bin_PROGRAMS += %reldir%/tarot-stacking
%canon_reldir%_tarot_stacking_SOURCES = \
%reldir%/tarot_stacking.c
%canon_reldir%_tarot_stacking_LDADD = \
%reldir%/libprogram-commons.la \
lib/libgnu.la \
src/libtarot/libtarot.la \
$(LTLIBINTL) \
$(LTLIBTHREAD) \
@INTL_MACOSX_LIBS@
/*
* tarot_stacking.c
*
* Copyright (C) 2019 Vivien Kraus <vivien@planete-kraus.eu>
*
* 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 this program. If not, see
* <http://www.gnu.org/licenses/>.
*/
#include "program_commons.h"
#include <tuneconfig.h>
static int generate_whole_game = 0;
static void parse_options (int argc, char *argv[]);
int
main (int argc, char *argv[])
{
TarotGame *game = NULL;
char *output;
TarotPredictor *stacking = NULL;
const TarotGameEvent *event = NULL;
TarotGameEvent *dog_event;
size_t n_cards;
TarotCard *cards;
tarot_program_setup ();
parse_options (argc, argv);
game = tarot_program_read_game ();
stacking = tarot_predictor_alloc ();
while (1)
{
double score;
if (generate_whole_game)
{
break;
TarotPlayer next;
if (tarot_game_get_next (game, &next) != TAROT_GAME_OK)
{
break;
}
}
tarot_predictor_set_game (stacking, game);
event = tarot_predictor_best (stacking, &score);
if (tarot_game_add_event (game, event) != TAROT_GAME_OK)
{
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 ();
}
}
if (!generate_whole_game)
{
break;
}
}
output = tarot_game_save_to_xml_alloc (game);
printf ("%s", output);
return EXIT_SUCCESS;
}
static void
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}
};
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);
}
option_index = 0;
c = getopt_long (argc, argv, "hvg", long_options, &option_index);
if (c == -1)
break;
switch (c)
{
case 0:
break;
case 'h':
printf (_ ("Usage: tarot-stacking [OPTIONS]... < GAME\n\
Play as the stacking 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;
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-stacking",
tarot_libtarot_version ());
exit (EXIT_SUCCESS);
break;
case 'g':
generate_whole_game = 1;
break;
case '?':
/* getopt_long already printed an error message. */
exit (EXIT_FAILURE);
break;
default:
abort ();
}
}
if (optind < argc)
{
fprintf (stderr, _ ("Error: extra arguments:\n"));
while (optind < argc)
fprintf (stderr, _ ("- %s\n"), argv[optind++]);
exit (EXIT_FAILURE);
}
}
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