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

Provide a tarot-deal command

This command deals a game at random.
parent 66b00890
......@@ -45,6 +45,7 @@
/doc/petit-sec.c
/doc/players-and-cards
/doc/players-and-cards.c
/doc/tarot-deal.man
/doc/tarot-figures
/doc/tarot-status.man
/doc/tarot-tune
......
......@@ -16,8 +16,14 @@
# along with this program. If not, see
# <http://www.gnu.org/licenses/>.
dist_man6_MANS += %reldir%/tarot.man %reldir%/tarot-status.man
MAINTAINERCLEANFILES += $(srcdir)/%reldir%/tarot.man $(srcdir)/%reldir%/tarot-status.man
dist_man6_MANS += \
%reldir%/tarot.man \
%reldir%/tarot-status.man \
%reldir%/tarot-deal.man
MAINTAINERCLEANFILES += \
$(srcdir)/%reldir%/tarot.man \
$(srcdir)/%reldir%/tarot-status.man \
$(srcdir)/%reldir%/tarot-deal.man
help2man_verbose = $(help2man_verbose_@AM_V@)
help2man_verbose_ = $(help2man_verbose_@AM_DEFAULT_V@)
......@@ -30,3 +36,7 @@ $(srcdir)/%reldir%/tarot.man: src/tarot-app/main.vala
$(srcdir)/%reldir%/tarot-status.man: src/tarot-app/tarot_status.c
$(MAKE) $(AM_MAKEFLAGS) src/tarot-app/tarot-status
$(help2man_verbose) ./pre-inst-env help2man tarot-status > $@
$(srcdir)/%reldir%/tarot-deal.man: src/tarot-app/tarot_deal.c
$(MAKE) $(AM_MAKEFLAGS) src/tarot-app/tarot-deal
$(help2man_verbose) ./pre-inst-env help2man tarot-deal > $@
......@@ -10,4 +10,5 @@ src/tarot-app/ai.vala
src/tarot-app/card_painter.vala
src/tarot-app/card_painter_default.vala
src/tarot-app/server.vala
src/tarot-app/tarot_status.c
\ No newline at end of file
src/tarot-app/tarot_status.c
src/tarot-app/tarot_deal.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-24 17:40+0200\n"
"PO-Revision-Date: 2019-08-24 17:47+0200\n"
"POT-Creation-Date: 2019-08-24 18:43+0200\n"
"PO-Revision-Date: 2019-08-24 19:02+0200\n"
"Last-Translator: Vivien Kraus <vivien@planete-kraus.eu>\n"
"Language-Team: French\n"
"Language: fr\n"
......@@ -27,6 +27,7 @@ msgstr ""
"réinstaller le programme.\n"
#: src/tarot-app/main.vala:69 src/tarot-app/tarot_status.c:44
#: src/tarot-app/tarot_deal.c:55
#, c-format
msgid "ERROR: could not initialize libtarot.\n"
msgstr "ERREUR : impossible d'initialiser libtarot.\n"
......@@ -36,10 +37,12 @@ msgid "Print version information and exit"
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:88
msgid "version"
msgstr "version"
#: src/tarot-app/main.vala:100 src/tarot-app/tarot_status.c:76
#: src/tarot-app/tarot_deal.c:128
#, c-format
msgid ""
"%s (libtarot %s)\n"
......@@ -1124,6 +1127,103 @@ msgstr "Erreur : commande inconnue « %s ».\n"
msgid "Error: invalid game.\n"
msgstr "Erreur : partie invalide.\n"
#: src/tarot-app/tarot_deal.c:63
#, c-format
msgid "Error: could not set the game up for %lu players (call: %d)\n"
msgstr "Erreur : impossible de mettre en place la partie pour %lu joueurs (appel : %d)\n"
#: src/tarot-app/tarot_deal.c:69
#, c-format
msgid ""
"Error: could not use this random seed, '%s', to deal. Please retry with a "
"different seed.\n"
msgstr ""
"Erreur : impossible d'utiliser cette graine aléatoire, « %s », pour la\n"
"distribution. Veuillez réessayer avec une graine différente.\n"
#: src/tarot-app/tarot_deal.c:87
msgid "help"
msgstr "aide"
#: src/tarot-app/tarot_deal.c:89
msgid "n-players"
msgstr "n-joueurs"
#: src/tarot-app/tarot_deal.c:90
msgid "call-allowed"
msgstr "appel-autorisé"
#: src/tarot-app/tarot_deal.c:91
msgid "no-call-allowed"
msgstr "appel-interdit"
#: src/tarot-app/tarot_deal.c:92
msgid "seed"
msgstr "graine"
#: src/tarot-app/tarot_deal.c:110
#, c-format
msgid ""
"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"
"- -n N_PLAYERS, --n-players=N_PLAYERS: set the number of players\n"
" (default: %lu)\n"
"- -c, --call-allowed: the game allows a call\n"
"- --no-call-allowed: the game does not allow a call (default)\n"
"- -s, --seed=\"SEED\": set the seed for the random deal. SEED must\n"
" not be empty.\n"
"\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"
msgstr ""
"Utilisation : tarot-deal [OPTIONS]...\n"
"Crée une nouvelle partie avec une distribution aléatoire pour tous les\n"
"joueurs. Options :\n"
"- -h, --aide : affiche ce message d'aide et quitte\n"
"- -v, --version : affiche la version du programme et quitte\n"
"- -n N_JOUEURS, --n-joueurs=N_JOUEURS : définit le nombre de joueurs\n"
" (par défaut : %lu)\n"
"- -c, --appel-autorisé : la partie autorise un appel\n"
"- --appel-interdit : la partie n'autorise aucun appel (comportement\n"
" par défaut)\n"
"- -s, --graine=\"GRAINE\" : définit la graine pour la distribution\n"
" aléatoire. GRAINE ne peut pas être une chaîne vide.\n"
"\n"
"Si la graine mène à un petit sec, alors la distribution échouera.\n"
"Donc en cas d'échec vous voudrez probablement réessayer avec quelques\n"
"autres graines.\n"
#: src/tarot-app/tarot_deal.c:140
#, c-format
msgid "Error: the number of players should be a number, not '%s'.\n"
msgstr "Erreur : le nombre de joueurs doit être un nombre, et pas « %s ».\n"
#: src/tarot-app/tarot_deal.c:146
#, c-format
msgid ""
"Error: the number of players (%lu) has an unexpected suffix, '%s': '%s'.\n"
msgstr "Erreur : le nombre de joueurs (%lu) a un suffixe inattendu, « %s » : « %s ».\n"
#: src/tarot-app/tarot_deal.c:160
#, c-format
msgid ""
"Error: the seed must not be empty. The default is usually \"default\".\n"
msgstr ""
"Erreur : la graine ne doit pas être vide. La valeur par défaut est\n"
"habituellement « default ».\n"
#: src/tarot-app/tarot_deal.c:175
#, c-format
msgid "Error: extra arguments:\n"
msgstr "Erreur : arguments supplémentaires :\n"
#: src/tarot-app/tarot_deal.c:177
#, c-format
msgid "- %s\n"
msgstr "- %s\n"
#~ msgid "Hello, world!\n"
#~ msgstr "Bonjour, le monde !\n"
......@@ -1229,9 +1329,6 @@ msgstr "Erreur : partie invalide.\n"
#~ msgid " - Call: %s\n"
#~ msgstr " - Appel : %s\n"
#~ msgid " - Dog: %s\n"
#~ msgstr " - Chien : %s\n"
#~ msgid " - The discard has been done.\n"
#~ msgstr " - L'écart a été fait.\n"
......@@ -1337,10 +1434,6 @@ msgstr "Erreur : partie invalide.\n"
#~ msgid "Could not add an event of type %s to game %s.\n"
#~ msgstr "Impossible d'ajouter une événement de type %s à la partie %s.\n"
#~ msgid "Error: wrong number of players (%lu) or the call is not accepted\n"
#~ msgstr ""
#~ "Erreur : mauvais nombre de joueurs (%lu), ou l'appel n'est pas autorisé\n"
#~ msgid "Error: wrong seed '%s', try another one\n"
#~ msgstr ""
#~ "Erreur : mauvaise graine aléatoire '%s', essayez-en une différente\n"
......@@ -1641,24 +1734,15 @@ msgstr "Erreur : partie invalide.\n"
#~ msgid "Output file to write for batch processing (defaults to stdout)"
#~ msgstr "Fichier de sortie à écrire (par défaut, la sortie standard)"
#~ msgid "n-players"
#~ msgstr "n-joueurs"
#~ msgid "Specify the number of players for a new game"
#~ msgstr "Spécifie le nombre de joueurs pour une nouvelle partie"
#~ msgid "N"
#~ msgstr "N"
#~ msgid "call-allowed"
#~ msgstr "appel-autorisé"
#~ msgid "The new game can have a call"
#~ msgstr "La partie peut avoir un appel"
#~ msgid "seed"
#~ msgstr "graine"
#~ msgid "The random seed for MCTS-related operations (defaults to 'default')"
#~ msgstr ""
#~ "La graine aléatoire pour les opérations liées à MCTS (par défaut, "
......
......@@ -21,3 +21,4 @@ AM_CPPFLAGS += -I $(srcdir)/%reldir% -I %reldir%
include %reldir%/tarot-cli-program.am
include %reldir%/run-with-c-locale.am
include %reldir%/tarot-status.am
include %reldir%/tarot-deal.am
# tarot-deal.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-deal
%canon_reldir%_tarot_deal_SOURCES = \
%reldir%/tarot_deal.c \
src/gettext.h
%canon_reldir%_tarot_deal_CFLAGS = \
$(AM_CFLAGS)
%canon_reldir%_tarot_deal_LDADD = \
lib/libgnu.la \
src/libtarot/libtarot.la \
$(LTLIBINTL) \
$(LTLIBTHREAD) \
@INTL_MACOSX_LIBS@
/*
* tarot_deal.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 <config.h>
#include <tarot.h>
#include "gettext.h"
#include <locale.h>
#include <stdlib.h>
#include <stdio.h>
#include "xalloc.h"
#include <assert.h>
#include "getopt.h"
#include <string.h>
#define _(String) gettext (String)
#define N_(String) String
static char *default_seed = "default";
static size_t n_players = 4;
static int with_call = 0;
static char **seed = &default_seed;
static void parse_options (int argc, char *argv[]);
int
main (int argc, char *argv[])
{
TarotGame *game = NULL;
TarotGameEvent *setup_event;
TarotGameEvent *deal_event;
char *output;
setlocale (LC_ALL, "");
bindtextdomain (PACKAGE, LOCALEDIR);
textdomain (PACKAGE);
if (tarot_init (LOCALEDIR) != 0)
{
fprintf (stderr, _ ("ERROR: could not initialize libtarot.\n"));
}
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);
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);
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);
return EXIT_FAILURE;
}
output = tarot_game_save_to_xml_alloc (game);
printf ("%s", output);
return EXIT_SUCCESS;
}
static void
parse_options (int argc, char *argv[])
{
int c;
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}
};
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, "hvn:cs:", long_options, &option_index);
if (c == -1)
break;
switch (c)
{
case 0:
break;
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\
- -n N_PLAYERS, --n-players=N_PLAYERS: set the number of players\n\
(default: %lu)\n\
- -c, --call-allowed: the game allows a call\n\
- --no-call-allowed: the game does not allow a call (default)\n\
- -s, --seed=\"SEED\": set the seed for the random deal. SEED must\n\
not be empty.\n\
\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;
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;
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);
}
break;
case 'c':
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);
}
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