Commit 623ea999 authored by Vivien Kraus's avatar Vivien Kraus

Implement --discard, --handful and --play

parent 71dfd50f
......@@ -23,6 +23,9 @@ include = "int tarot_run_bid (char *input, TarotBid bid, char **output);";
include = "int tarot_run_decl (char *input, int decl, char **output);";
include = "int tarot_run_call (char *input, TarotCard card, char **output);";
include = "int tarot_run_dog (char *input, TarotCardArray *cards, char **output);";
include = "int tarot_run_discard (char *input, TarotCardArray *cards, char **output);";
include = "int tarot_run_handful (char *input, TarotCardArray *cards, char **output);";
include = "int tarot_run_play (char *input, TarotCard card, char **output);";
include = "int opts_main (int argc, char **argv);";
include = "int main (int argc, char **argv) { setenv (\"SYSCONFDIR\", SYSCONFDIR, 0); return opts_main (argc, argv); }";
include = "static char *read_input ();";
......@@ -90,10 +93,17 @@ parse_as_card_array (const char *arg)
{
abort ();
}
while ((to_read = strstr (to_read, ",")) != NULL)
if (strcmp (arg, "") == 0)
{
to_read += strlen (",");
n_args++;
n_args = 0;
}
else
{
while ((to_read = strstr (to_read, ",")) != NULL)
{
to_read += strlen (",");
n_args++;
}
}
if (tarot_card_array_resize (ret, n_args) != 0)
{
......@@ -301,6 +311,40 @@ main = {
cards = parse_as_card_array (OPT_ARG (DOG));
res = tarot_run_dog (input, cards, &output);
break;
case INDEX_OPT_DISCARD:
input = read_input ();
if (OPT_ARG (DISCARD) == NULL)
{
cards = parse_as_card_array ("");
}
else
{
cards = parse_as_card_array (OPT_ARG (DISCARD));
}
res = tarot_run_discard (input, cards, &output);
break;
case INDEX_OPT_HANDFUL:
input = read_input ();
if (OPT_ARG (HANDFUL) == NULL)
{
cards = parse_as_card_array ("");
}
else
{
cards = parse_as_card_array (OPT_ARG (HANDFUL));
}
res = tarot_run_handful (input, cards, &output);
break;
case INDEX_OPT_PLAY:
input = read_input ();
card = tarot_card_parse (OPT_ARG (PLAY), &end);
if (OPT_ARG (PLAY) == end)
{
fprintf (stderr, "Error: expected a card, not '%s'\n", OPT_ARG (PLAY));
USAGE (1);
}
res = tarot_run_play (input, card, &output);
break;
}
write_output (output);
free (input);
......@@ -403,6 +447,35 @@ flag = {
doc = 'In this mode, the dog is revealed. This action is only required when the deal is not fully known. The argument is a comma-separated list of 6 or 3 cards (3 for the 5-player variant).';
};
flag = {
name = discard;
no-preset;
equivalence = new-game;
arg-type = string;
arg-optional;
descrip = "Reveal the discard, as \"AH,2H,3H,...\"";
doc = 'In this mode, the discard is done. The argument is a comma-separated list of @emph{at most} 6 or 3 cards (3 for the 5-player variant). If you are not the taker, and there are no discarded trumps, then you do not need to pass an argument.';
};
flag = {
name = handful;
no-preset;
equivalence = new-game;
arg-type = string;
arg-optional;
descrip = "Show a handful, as \"1T,2T,3T,...\"";
doc = 'In this mode, the next player shows a handful of a certain number of cards, eventually 0. If a handful of 0 cards is selected, then the next player will only be able to play a card. In such a case, it is not necessary to give an argument for the action.';
};
flag = {
name = play;
no-preset;
equivalence = new-game;
arg-type = string;
descrip = "Play a card";
doc = 'In this mode, the next player plays a card.';
};
flag = {
name = status;
no-preset;
......
......@@ -270,6 +270,63 @@ namespace Tarot {
output = game.save_to_xml ();
return 0;
}
public static int run_discard (string input, Tarot.CardArray cards, out string? output) {
var game = new Tarot.Game.alloc ();
output = null;
if (game.load_from_xml (input) != 0) {
stderr.printf ("ERROR: this game is not valid.\n");
return 1;
}
var e = new Tarot.GameEvent.alloc ();
if (e.set_discard (cards) != 0) {
stderr.printf ("ERROR: this is not possible.\n");
return 1;
}
if (game.add_event (e) != 0) {
stderr.printf ("ERROR: this is not possible.\n");
return 1;
}
output = game.save_to_xml ();
return 0;
}
public static int run_handful (string input, Tarot.CardArray cards, out string? output) {
var game = new Tarot.Game.alloc ();
output = null;
if (game.load_from_xml (input) != 0) {
stderr.printf ("ERROR: this game is not valid.\n");
return 1;
}
var e = new Tarot.GameEvent.alloc ();
if (e.set_handful (cards) != 0) {
stderr.printf ("ERROR: this is not possible.\n");
return 1;
}
if (game.add_event (e) != 0) {
stderr.printf ("ERROR: this is not possible.\n");
return 1;
}
output = game.save_to_xml ();
return 0;
}
public static int run_play (string input, Tarot.Card card, out string? output) {
var game = new Tarot.Game.alloc ();
var e = new Tarot.GameEvent.alloc ();
output = null;
if (game.load_from_xml (input) != 0) {
stderr.printf ("ERROR: this game is not valid.\n");
return 1;
}
if (e.set_card (card) != 0) {
stderr.printf ("ERROR: this is not possible.\n");
return 1;
}
if (game.add_event (e) != 0) {
stderr.printf ("ERROR: this is not possible.\n");
return 1;
}
output = game.save_to_xml ();
return 0;
}
private string print_bid_cell (Tarot.Bid bid) {
switch (bid) {
case Tarot.Bid.PASS:
......
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