game.h 20.3 KB
Newer Older
1
/* tarot implements the rules of the tarot game
Vivien Kraus's avatar
Vivien Kraus committed
2
 * Copyright (C) 2018, 2019, 2020  Vivien Kraus
Vivien Kraus's avatar
Vivien Kraus committed
3
 *
4
5
 * 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
6
 * the Free Software Foundation, version 3 of the License.
Vivien Kraus's avatar
Vivien Kraus committed
7
8
9
10
11
12
13
 *
 * 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
14
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
Vivien Kraus's avatar
Vivien Kraus committed
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
 */

#ifndef H_TAROT_GAME_INCLUDED
#define H_TAROT_GAME_INCLUDED

#include <stddef.h>

#include <tarot/bid.h>
#include <tarot/player.h>
#include <tarot/step.h>
#include <tarot/cards.h>
#include <tarot/game_event.h>

#ifdef __cplusplus
extern "C"
{
#endif                          /* __cplusplus */

  struct TarotGame;
  typedef struct TarotGame TarotGame;

  struct TarotGameIterator;
  typedef struct TarotGameIterator TarotGameIterator;

  typedef enum
  {
    TAROT_GAME_OK = 0,
    TAROT_GAME_INVEV,
Vivien Kraus's avatar
Vivien Kraus committed
43
44
    TAROT_GAME_NA,
    TAROT_GAME_TOOLATE
Vivien Kraus's avatar
Vivien Kraus committed
45
46
47
48
49
50
51
52
53
54
  } TarotGameError;

  /**
   * tarot_game_alloc: (constructor)
   */
  TarotGame *tarot_game_alloc (void);
  TarotGame *tarot_game_dup (const TarotGame * source);
  void tarot_game_free (TarotGame * game);

  void tarot_game_copy (TarotGame * dest, const TarotGame * source);
Vivien Kraus's avatar
Vivien Kraus committed
55
56
57
  TarotGameError tarot_game_copy_as (TarotGame * dest,
                                     const TarotGame * source,
                                     TarotPlayer who);
Vivien Kraus's avatar
Vivien Kraus committed
58
59
60

  TarotStep tarot_game_step (const TarotGame * game);

Vivien Kraus's avatar
Vivien Kraus committed
61
62
63
64
  /**
   * tarot_game_duplicate_set_deal:
   * @owners: (array length=n_owners):
   */
Vivien Kraus's avatar
Vivien Kraus committed
65
66
67
68
69
70
71
  TarotGameError tarot_game_duplicate_set_deal (TarotGame * game,
                                                size_t n_owners,
                                                const TarotPlayer * owners);
  TarotGameError tarot_game_duplicate_set_taker (TarotGame * game,
                                                 TarotPlayer taker);
  TarotGameError tarot_game_duplicate_set_call (TarotGame * game,
                                                TarotCard call);
Vivien Kraus's avatar
Vivien Kraus committed
72

Vivien Kraus's avatar
Vivien Kraus committed
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
  TarotGameIterator *tarot_game_iterator (const TarotGame * game);

  TarotGameIterator *tarot_game_iterator_dup
    (const TarotGameIterator * source);

  void tarot_game_iterator_free (TarotGameIterator * game_iterator);

  size_t tarot_game_n_players (const TarotGame * game);

  /**
   * tarot_game_with_call:
   * Returns: (type boolean):
   */
  int tarot_game_with_call (const TarotGame * game);

  /**
   * tarot_game_get_next:
   * @next: (out):
   */
  TarotGameError tarot_game_get_next (const TarotGame * game,
                                      TarotPlayer * next);

  /**
   * tarot_game_get_main_player:
   * @main: (out):
   */
  TarotGameError tarot_game_get_main_player (const TarotGame * game,
                                             TarotPlayer * main);

  /**
   * tarot_game_get_deal_all:
104
   * @owners_out: (array length=max):
Vivien Kraus's avatar
Vivien Kraus committed
105
106
107
108
   * @n: (out):
   */
  TarotGameError tarot_game_get_deal_all (const TarotGame * game, size_t *n,
                                          size_t start, size_t max,
109
                                          TarotPlayer * owners_out);
Vivien Kraus's avatar
Vivien Kraus committed
110
111
112
113
114
115
116
117
118
119
120

  /**
   * tarot_game_get_deal_all_alloc: (rename-to tarot_game_get_deal_all)
   * @owners: (out) (array length=n):
   */
  TarotGameError tarot_game_get_deal_all_alloc (const TarotGame * game,
                                                size_t *n,
                                                TarotPlayer ** owners);

  /**
   * tarot_game_get_deal_of:
121
   * @deal_out: (array length=max):
Vivien Kraus's avatar
Vivien Kraus committed
122
123
124
125
126
   * @n: (out):
   */
  TarotGameError tarot_game_get_deal_of (const TarotGame * game,
                                         TarotPlayer who, size_t *n,
                                         size_t start, size_t max,
127
                                         TarotCard * deal_out);
Vivien Kraus's avatar
Vivien Kraus committed
128
129
130
131
132
133
134
135
136
137
138

  /**
   * tarot_game_get_deal_of_alloc: (rename-to tarot_game_get_deal_of)
   * @cards: (out) (array length=n):
   */
  TarotGameError tarot_game_get_deal_of_alloc (const TarotGame * game,
                                               TarotPlayer who, size_t *n,
                                               TarotCard ** cards);

  /**
   * tarot_game_get_cards:
139
   * @cards_out: (array length=max):
Vivien Kraus's avatar
Vivien Kraus committed
140
141
142
143
144
   * @n: (out):
   */
  TarotGameError tarot_game_get_cards (const TarotGame * game,
                                       TarotPlayer who, size_t *n,
                                       size_t start, size_t max,
145
                                       TarotCard * cards_out);
Vivien Kraus's avatar
Vivien Kraus committed
146
147
148
149
150
151
152
153
154
155
156

  /**
   * tarot_game_get_cards_alloc: (rename-to tarot_game_get_cards)
   * @cards: (out) (array length=n):
   */
  TarotGameError tarot_game_get_cards_alloc (const TarotGame * game,
                                             TarotPlayer who, size_t *n,
                                             TarotCard ** cards);

  /**
   * tarot_game_get_bids:
Vivien Kraus's avatar
Vivien Kraus committed
157
   * @n: (out):
158
   * @bids_out: (array length=max):
Vivien Kraus's avatar
Vivien Kraus committed
159
160
161
   */
  TarotGameError tarot_game_get_bids (const TarotGame * game, size_t *n,
                                      TarotPlayer start, size_t max,
162
                                      TarotBid * bids_out);
Vivien Kraus's avatar
Vivien Kraus committed
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179

  /**
   * tarot_game_get_bids_alloc: (rename-to tarot_game_get_bids)
   * @bids: (out) (array length=n):
   */
  TarotGameError tarot_game_get_bids_alloc (const TarotGame * game, size_t *n,
                                            TarotBid ** bids);

  /**
   * tarot_game_get_taker:
   * @taker: (out):
   */
  TarotGameError tarot_game_get_taker (const TarotGame * game,
                                       TarotPlayer * taker);

  /**
   * tarot_game_get_declarations:
Vivien Kraus's avatar
Vivien Kraus committed
180
   * @n: (out):
181
   * @decls_out: (array length=max) (type boolean):
Vivien Kraus's avatar
Vivien Kraus committed
182
183
184
   */
  TarotGameError tarot_game_get_declarations (const TarotGame * game,
                                              size_t *n, TarotPlayer start,
185
                                              size_t max, int *decls_out);
Vivien Kraus's avatar
Vivien Kraus committed
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217

  /**
   * tarot_game_get_declarations_alloc: (rename-to tarot_game_get_declarations)
   * @declarations: (out) (array length=n) (element-type boolean):
   */
  TarotGameError tarot_game_get_declarations_alloc (const TarotGame * game,
                                                    size_t *n,
                                                    int **declarations);

  /**
   * tarot_game_get_declarant:
   * @declarant: (out):
   */
  TarotGameError tarot_game_get_declarant (const TarotGame * game,
                                           TarotPlayer * declarant);

  /**
   * tarot_game_get_call:
   * @card: (out):
   */
  TarotGameError tarot_game_get_call (const TarotGame * game,
                                      TarotCard * card);

  /**
   * tarot_game_get_partner:
   * @partner: (out):
   */
  TarotGameError tarot_game_get_partner (const TarotGame * game,
                                         TarotPlayer * partner);

  /**
   * tarot_game_get_dog:
218
   * @cards_out: (array length=max):
Vivien Kraus's avatar
Vivien Kraus committed
219
220
221
222
   * @n: (out):
   */
  TarotGameError tarot_game_get_dog (const TarotGame * game, size_t *n,
                                     size_t start, size_t max,
223
                                     TarotCard * cards_out);
Vivien Kraus's avatar
Vivien Kraus committed
224
225
226
227
228
229
230
231
232
233
234

  /**
   * tarot_game_get_dog_alloc: (rename-to tarot_game_get_dog)
   * @cards: (out) (array length=n_cards):
   */
  TarotGameError tarot_game_get_dog_alloc (const TarotGame * game,
                                           size_t *n_cards,
                                           TarotCard ** cards);

  /**
   * tarot_game_get_full_discard:
235
   * @cards_out: (array length=max):
Vivien Kraus's avatar
Vivien Kraus committed
236
237
238
239
   * @n: (out):
   */
  TarotGameError tarot_game_get_full_discard (const TarotGame * game,
                                              size_t *n, size_t start,
Vivien Kraus's avatar
Vivien Kraus committed
240
241
                                              size_t max,
                                              TarotCard * cards_out);
Vivien Kraus's avatar
Vivien Kraus committed
242
243
244
245
246
247
248
249
250
251
252

  /**
   * tarot_game_get_full_discard_alloc:
   * @cards: (out) (array length=n):
   */
  TarotGameError tarot_game_get_full_discard_alloc (const TarotGame * game,
                                                    size_t *n,
                                                    TarotCard ** cards);

  /**
   * tarot_game_get_public_discard:
253
   * @cards_out: (array length=max):
Vivien Kraus's avatar
Vivien Kraus committed
254
255
256
257
258
   * @n: (out):
   */
  TarotGameError tarot_game_get_public_discard (const TarotGame * game,
                                                size_t *n, size_t start,
                                                size_t max,
259
                                                TarotCard * cards_out);
Vivien Kraus's avatar
Vivien Kraus committed
260
261
262
263
264
265
266
267
268
269
270

  /**
   * tarot_game_get_public_discard_alloc:
   * @cards: (out) (array length=n):
   */
  TarotGameError tarot_game_get_public_discard_alloc (const TarotGame * game,
                                                      size_t *n,
                                                      TarotCard ** cards);

  /**
   * tarot_game_get_handful:
Vivien Kraus's avatar
Vivien Kraus committed
271
   * @n_cards: (out):
Vivien Kraus's avatar
Vivien Kraus committed
272
   * @size: (out):
Vivien Kraus's avatar
Vivien Kraus committed
273
   * @cards: (array length=max):
Vivien Kraus's avatar
Vivien Kraus committed
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
   */
  TarotGameError tarot_game_get_handful (const TarotGame * game,
                                         TarotPlayer p, int *size,
                                         size_t *n_cards, size_t start,
                                         size_t max, TarotCard * cards);

  /**
   * tarot_game_get_handful_alloc: (rename-to tarot_game_get_handful)
   * @size: (out):
   * @cards: (out) (array length=n_cards):
   */
  TarotGameError tarot_game_get_handful_alloc (const TarotGame * game,
                                               TarotPlayer p, int *size,
                                               size_t *n_cards,
                                               TarotCard ** cards);

  /**
   * tarot_game_n_tricks:
   */
  size_t tarot_game_n_tricks (const TarotGame * game);

  /**
   * tarot_game_get_current_trick:
   * @current: (out):
   */
  TarotGameError tarot_game_get_current_trick (const TarotGame * game,
                                               size_t *current);

  /**
   * tarot_game_get_lead_suit:
   * @lead_suit: (out):
   */
  TarotGameError tarot_game_get_lead_suit (const TarotGame * game,
                                           size_t i_trick,
                                           TarotSuit * lead_suit);

  /**
   * tarot_game_get_max_trump:
   * @max_trump: (out):
   */
  TarotGameError tarot_game_get_max_trump (const TarotGame * game,
                                           size_t i_trick,
                                           TarotNumber * max_trump);

  /**
   * tarot_game_get_trick_leader:
   * @leader: (out):
   */
  TarotGameError tarot_game_get_trick_leader (const TarotGame * game,
                                              size_t i_trick,
                                              TarotPlayer * leader);

  /**
   * tarot_game_get_trick_taker:
   * @taker: (out):
   */
  TarotGameError tarot_game_get_trick_taker (const TarotGame * game,
                                             size_t i_trick,
                                             TarotPlayer * taker);

  struct TarotGameCardAnalysis
  {
    TarotCard card;
    int cannot_follow;
    int cannot_overtrump;
    int cannot_undertrump;
  };
  typedef struct TarotGameCardAnalysis TarotGameCardAnalysis;

  /**
   * tarot_game_get_trick_cards:
   * @n_cards: (out):
346
   * @cards_out: (array length=max):
Vivien Kraus's avatar
Vivien Kraus committed
347
348
349
350
351
   */
  TarotGameError tarot_game_get_trick_cards (const TarotGame * game,
                                             size_t i_trick,
                                             size_t *n_cards, size_t start,
                                             size_t max,
Vivien Kraus's avatar
Vivien Kraus committed
352
353
                                             TarotGameCardAnalysis *
                                             cards_out);
Vivien Kraus's avatar
Vivien Kraus committed
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374

  /**
   * tarot_game_get_trick_cards_alloc: (rename-to tarot_game_get_trick_cards)
   * @cards: (out) (array length=n_cards):
   */
  TarotGameError tarot_game_get_trick_cards_alloc
    (const TarotGame * game,
     size_t i_trick, size_t *n_cards, TarotGameCardAnalysis ** cards);

  /**
   * tarot_game_get_points_in_trick:
   * @halfpoints: (out):
   * @oudlers: (out):
   */
  TarotGameError tarot_game_get_points_in_trick (const TarotGame * game,
                                                 size_t i_trick,
                                                 unsigned int *halfpoints,
                                                 unsigned int *oudlers);

  /**
   * tarot_game_get_scores:
Vivien Kraus's avatar
Vivien Kraus committed
375
   * @n: (out):
376
   * @scores_out: (array length=max):
Vivien Kraus's avatar
Vivien Kraus committed
377
378
379
   */
  TarotGameError tarot_game_get_scores (const TarotGame * game, size_t *n,
                                        size_t start, size_t max,
380
                                        int *scores_out);
Vivien Kraus's avatar
Vivien Kraus committed
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421

  /**
   * tarot_game_get_scores_alloc: (rename-to tarot_game_get_scores)
   * @scores: (out) (array length=n):
   */
  TarotGameError tarot_game_get_scores_alloc (const TarotGame * game,
                                              size_t *n, int **scores);

  /**
   * tarot_game_get_hint_bid:
   * @player: (out):
   * @mini: (out):
   */
  TarotGameError tarot_game_get_hint_bid (const TarotGame * game,
                                          TarotPlayer * player,
                                          TarotBid * mini);

  /**
   * tarot_game_get_hint_decl:
   * @player: (out):
   * @allowed: (out) (type boolean):
   */
  TarotGameError tarot_game_get_hint_decl (const TarotGame * game,
                                           TarotPlayer * player,
                                           int *allowed);

  /**
   * tarot_game_get_hint_call:
   * @player: (out):
   * @mini: (out):
   */
  TarotGameError tarot_game_get_hint_call (const TarotGame * game,
                                           TarotPlayer * player,
                                           TarotNumber * mini);

  /**
   * tarot_game_get_hint_discard:
   * @player: (out):
   * @n_cards: (out):
   * @n_prio: (out):
   * @n_additional: (out):
422
423
   * @prio_out: (array length=max_prio):
   * @additional_out: (array length=max_additional):
Vivien Kraus's avatar
Vivien Kraus committed
424
425
426
427
428
429
430
   */
  TarotGameError tarot_game_get_hint_discard (const TarotGame * game,
                                              TarotPlayer * player,
                                              size_t *n_cards,
                                              size_t *n_prio,
                                              size_t start_prio,
                                              size_t max_prio,
431
                                              TarotCard * prio_out,
Vivien Kraus's avatar
Vivien Kraus committed
432
433
434
                                              size_t *n_additional,
                                              size_t start_additional,
                                              size_t max_additional,
435
                                              TarotCard * additional_out);
Vivien Kraus's avatar
Vivien Kraus committed
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459

  /**
   * tarot_game_get_hint_discard_alloc: (rename-to tarot_game_get_hint_discard)
   * @player: (out):
   * @n_cards: (out):
   * @prio: (out) (array length=n_prio):
   * @additional: (out) (array length=n_additional):
   */
  TarotGameError tarot_game_get_hint_discard_alloc (const TarotGame * game,
                                                    TarotPlayer * player,
                                                    size_t *n_cards,
                                                    size_t *n_prio,
                                                    TarotCard ** prio,
                                                    size_t *n_additional,
                                                    TarotCard ** additional);

  /**
   * tarot_game_get_hint_handful:
   * @player: (out):
   * @n_simple: (out):
   * @n_double: (out):
   * @n_triple: (out):
   * @n_prio: (out):
   * @n_additional: (out):
460
461
   * @prio_out: (array length=max_prio):
   * @additional_out: (array length=max_additional):
Vivien Kraus's avatar
Vivien Kraus committed
462
463
464
465
466
467
468
469
470
   */
  TarotGameError tarot_game_get_hint_handful (const TarotGame * game,
                                              TarotPlayer * player,
                                              size_t *n_simple,
                                              size_t *n_double,
                                              size_t *n_triple,
                                              size_t *n_prio,
                                              size_t start_prio,
                                              size_t max_prio,
471
                                              TarotCard * prio_out,
Vivien Kraus's avatar
Vivien Kraus committed
472
473
474
                                              size_t *n_additional,
                                              size_t start_additional,
                                              size_t max_additional,
475
                                              TarotCard * additional_out);
Vivien Kraus's avatar
Vivien Kraus committed
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499

  /**
   * tarot_game_get_hint_handful_alloc: (rename-to tarot_game_get_hint_handful)
   * @player: (out):
   * @n_simple: (out):
   * @n_double: (out):
   * @n_triple: (out):
   * @prio: (out) (array length=n_prio):
   * @additional: (out) (array length=n_additional):
   */
  TarotGameError tarot_game_get_hint_handful_alloc (const TarotGame * game,
                                                    TarotPlayer * player,
                                                    size_t *n_simple,
                                                    size_t *n_double,
                                                    size_t *n_triple,
                                                    size_t *n_prio,
                                                    TarotCard ** prio,
                                                    size_t *n_additional,
                                                    TarotCard ** additional);

  /**
   * tarot_game_get_hint_card:
   * @player: (out):
   * @n: (out):
500
   * @playable_out: (array length=max):
Vivien Kraus's avatar
Vivien Kraus committed
501
502
503
504
505
   */
  TarotGameError tarot_game_get_hint_card (const TarotGame * game,
                                           TarotPlayer * player,
                                           size_t *n,
                                           size_t start,
Vivien Kraus's avatar
Vivien Kraus committed
506
507
                                           size_t max,
                                           TarotCard * playable_out);
Vivien Kraus's avatar
Vivien Kraus committed
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545

  /**
   * tarot_game_get_hint_card_alloc: (rename-to tarot_game_get_hint_card)
   * @player: (out):
   * @playable: (out) (array length=n_playable):
   */
  TarotGameError tarot_game_get_hint_card_alloc (const TarotGame * game,
                                                 TarotPlayer * player,
                                                 size_t *n_playable,
                                                 TarotCard ** playable);

  /**
   * tarot_game_check_event:
   * Returns: (type boolean):
   */
  int tarot_game_check_event (const TarotGame * game,
                              const TarotGameEvent * event);

  /**
   * tarot_game_check_card:
   * @cannot_follow: (type boolean) (out):
   * @lead_suit: (out):
   * @cannot_overtrump: (type boolean) (out):
   * @max_trump: (out):
   * @cannot_undertrump: (type boolean) (out):
   * Returns: (type boolean):
   */
  int tarot_game_check_card (const TarotGame * game, TarotCard card,
                             int *cannot_follow, TarotSuit * lead_suit,
                             int *cannot_overtrump, TarotNumber * max_trump,
                             int *cannot_undertrump);

  TarotGameError tarot_game_add_event (TarotGame * game,
                                       const TarotGameEvent * event);

  /**
   * tarot_game_can_autoreveal:
   * @n_dog: (out):
546
   * @dog_out: (array length=max):
Vivien Kraus's avatar
Vivien Kraus committed
547
548
549
   * Returns: (type boolean):
   */
  int tarot_game_can_autoreveal (const TarotGame * game, size_t *n_dog,
Vivien Kraus's avatar
Vivien Kraus committed
550
551
                                 size_t start, size_t max,
                                 TarotCard * dog_out);
Vivien Kraus's avatar
Vivien Kraus committed
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578

  /**
   * tarot_game_can_autoreveal_alloc: (rename-to tarot_game_can_autoreveal)
   * @cards: (out) (array length=n):
   * Returns: (type boolean):
   */
  int tarot_game_can_autoreveal_alloc (const TarotGame * game, size_t *n,
                                       TarotCard ** cards);

  /* WARNING: This function may succeed but lead to a state where a
     player has no playable card!!  Don't use this directly, rather
     use tarot_counter_and_game_impute. */
  int tarot_game_assign_missing_card (TarotGame * game, TarotCard card,
                                      TarotPlayer owner);

  /**
   * tarot_game_iterator_next_value:
   * Returns: (nullable):
   */
  const TarotGameEvent *tarot_game_iterator_next_value (TarotGameIterator *
                                                        iterator);

#ifdef __cplusplus
}
#endif                          /* __cplusplus */

#endif                          /* not H_TAROT_GAME_INCLUDED */