-
Notifications
You must be signed in to change notification settings - Fork 0
/
engine.c
10300 lines (8288 loc) · 214 KB
/
engine.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
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
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
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
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
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
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
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
546
547
548
549
550
551
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
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
* Race for the Galaxy AI
*
* Copyright (C) 2009-2011 Keldon Jones
*
* 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 2 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, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#include "rftg.h"
void dump_hand(game *g, int who)
{
card *c_ptr;
int i;
/* Loop over cards */
for (i = 0; i < g->deck_size; i++)
{
/* Get card pointer */
c_ptr = &g->deck[i];
/* Skip cards not owned */
if (c_ptr->owner != who) continue;
/* Skip cards in wrong area */
if (c_ptr->where != WHERE_HAND) continue;
printf("%s\n", c_ptr->d_ptr->name);
}
}
void dump_hand_new(game *g, int who)
{
int x;
/* Start at head */
x = g->p[who].head[WHERE_HAND];
/* Loop over cards */
for ( ; x != -1; x = g->deck[x].next)
{
/* Print name */
printf("%s\n", g->deck[x].d_ptr->name);
}
}
void dump_active(game *g, int who)
{
card *c_ptr;
int i;
/* Loop over cards */
for (i = 0; i < g->deck_size; i++)
{
/* Get card pointer */
c_ptr = &g->deck[i];
/* Skip cards not owned */
if (c_ptr->owner != who) continue;
/* Skip cards in wrong area */
if (c_ptr->where != WHERE_ACTIVE) continue;
printf("%s\n", c_ptr->d_ptr->name);
}
}
void dump_active_new(game *g, int who)
{
int x;
/* Start at head */
x = g->p[who].head[WHERE_ACTIVE];
/* Loop over cards */
for ( ; x != -1; x = g->deck[x].next)
{
/* Print name */
printf("%s\n", g->deck[x].d_ptr->name);
}
}
/*
* Return a random number using the given argument as a seed.
*
* Algorithm from rand() manpage.
*/
int simple_rand(unsigned int *seed)
{
*seed = *seed * 1103515245 + 12345;
return ((unsigned)(*seed/65536) % 32768);
}
/*
* Return the number of cards in the draw deck.
*/
static int count_draw(game *g)
{
card *c_ptr;
int i, n = 0;
/* Loop over cards */
for (i = 0; i < g->deck_size; i++)
{
/* Get card pointer */
c_ptr = &g->deck[i];
/* Count cards in draw deck */
if (c_ptr->where == WHERE_DECK) n++;
}
/* Return count */
return n;
}
/*
* Return the number of card's in the given player's hand or active area.
*/
int count_player_area(game *g, int who, int where)
{
int x, n = 0;
/* Get first card of area chosen */
x = g->p[who].head[where];
/* Loop until end of list */
for ( ; x != -1; x = g->deck[x].next)
{
/* Count card */
n++;
}
/* Return count */
return n;
}
/*
* Return true if the player has a given card design active.
*/
static int player_has(game *g, int who, design *d_ptr)
{
int x;
/* Get first active card */
x = g->p[who].head[WHERE_ACTIVE];
/* Loop over cards */
for ( ; x != -1; x = g->deck[x].next)
{
/* Check for matching type */
if (g->deck[x].d_ptr == d_ptr) return 1;
}
/* Assume not */
return 0;
}
/*
* Return the number of active cards with the given flags.
*
* We check the card's location as of the start of the phase.
*/
int count_active_flags(game *g, int who, int flags)
{
int x, count = 0;
/* Start at first active card */
x = g->p[who].start_head[WHERE_ACTIVE];
/* Loop over cards */
for ( ; x != -1; x = g->deck[x].start_next)
{
/* Check for correct flags */
if ((g->deck[x].d_ptr->flags & flags) == flags) count++;
}
/* Return count */
return count;
}
/*
* Check if a player has selected the given action.
*/
int player_chose(game *g, int who, int act)
{
player *p_ptr;
/* Get player pointer */
p_ptr = &g->p[who];
/* Checking for prestige action */
if (act & ACT_PRESTIGE)
{
/* Player must have selected action with prestige */
return (p_ptr->action[0] == act) || (p_ptr->action[1] == act);
}
else
{
/* Check for either with or without prestige */
return ((p_ptr->action[0] & ACT_MASK) == act ||
(p_ptr->action[1] & ACT_MASK) == act);
}
}
/*
* Refresh the draw deck.
*/
static void refresh_draw(game *g)
{
card *c_ptr;
int i;
/* Message */
if (!g->simulation)
{
/* Send message */
message_add(g, "Refreshing draw deck.\n");
}
/* Loop over cards */
for (i = 0; i < g->deck_size; i++)
{
/* Get card pointer */
c_ptr = &g->deck[i];
/* Skip cards not in discard pile */
if (c_ptr->where != WHERE_DISCARD) continue;
/* Move card to draw deck */
c_ptr->where = WHERE_DECK;
/* Card's location is no longer known to anyone */
c_ptr->known = 0;
}
}
/*
* Return a card index from the draw deck.
*/
int random_draw(game *g)
{
card *c_ptr = NULL;
int i, n;
/* Count draw deck size */
n = count_draw(g);
/* Check for no cards */
if (!n)
{
/* Refresh draw deck */
refresh_draw(g);
/* Recount */
n = count_draw(g);
/* Check for still no cards */
if (!n)
{
/* No card to return */
return -1;
}
}
/* Choose randomly */
n = game_rand(g) % n;
/* Loop over cards */
for (i = 0; i < g->deck_size; i++)
{
/* Get card pointer */
c_ptr = &g->deck[i];
/* Skip cards not in draw deck */
if (c_ptr->where != WHERE_DECK) continue;
/* Check for chosen card */
if (!(n--)) break;
}
/* Clear chosen card's location */
c_ptr->where = -1;
/* Check for just-emptied draw pile */
if (!count_draw(g)) refresh_draw(g);
/* Return chosen card */
return i;
}
/*
* Return the first card pointer from the draw deck.
*
* We use this in simulated games for choosing cards to be used as goods
* and other non-essential tasks. We don't want to use the random number
* generator in these cases.
*/
static int first_draw(game *g)
{
card *c_ptr = NULL;
int i, n;
/* Count draw deck size */
n = count_draw(g);
/* Check for no cards */
if (!n)
{
/* Refresh draw deck */
refresh_draw(g);
/* Recount */
n = count_draw(g);
/* Check for still no cards */
if (!n)
{
/* No card to return */
return -1;
}
}
/* Loop over cards */
for (i = 0; i < g->deck_size; i++)
{
/* Get card pointer */
c_ptr = &g->deck[i];
/* Skip cards not in draw deck */
if (c_ptr->where != WHERE_DECK) continue;
/* Stop at first valid card */
break;
}
/* Clear chosen card's location */
c_ptr->where = -1;
/* Check for just-emptied draw pile */
if (!count_draw(g)) refresh_draw(g);
/* Return chosen card */
return i;
}
/*
* Move a card, keeping track of linked lists.
*
* This MUST be called when a card is moved to or from a player.
*/
void move_card(game *g, int which, int owner, int where)
{
player *p_ptr;
card *c_ptr;
int x;
/* Get card pointer */
c_ptr = &g->deck[which];
/* Check for current owner */
if (c_ptr->owner != -1)
{
/* Get pointer of current owner */
p_ptr = &g->p[c_ptr->owner];
/* Find card in list */
x = p_ptr->head[c_ptr->where];
/* Check for beginning of list */
if (x == which)
{
/* Adjust list forward */
p_ptr->head[c_ptr->where] = c_ptr->next;
c_ptr->next = -1;
}
else
{
/* Loop until moved card is found */
while (g->deck[x].next != which)
{
/* Move forward */
x = g->deck[x].next;
}
/* Remove moved card from list */
g->deck[x].next = c_ptr->next;
c_ptr->next = -1;
}
}
/* Check for new owner */
if (owner != -1)
{
/* Get player pointer of new owner */
p_ptr = &g->p[owner];
/* Add card to beginning of list */
c_ptr->next = p_ptr->head[where];
p_ptr->head[where] = which;
}
/* Adjust location */
c_ptr->owner = owner;
c_ptr->where = where;
}
/*
* Move a card's start of phase location, keeping track of linked lists.
*
* This should only be called when doing funky manipulation of fake game
* states.
*/
void move_start(game *g, int which, int owner, int where)
{
player *p_ptr;
card *c_ptr;
int x;
/* Get card pointer */
c_ptr = &g->deck[which];
/* Check for current owner */
if (c_ptr->start_owner != -1)
{
/* Get pointer of current owner */
p_ptr = &g->p[c_ptr->start_owner];
/* Find card in list */
x = p_ptr->start_head[c_ptr->start_where];
/* Check for beginning of list */
if (x == which)
{
/* Adjust list forward */
p_ptr->start_head[c_ptr->start_where] =
c_ptr->start_next;
c_ptr->start_next = -1;
}
else
{
/* Loop until moved card is found */
while (g->deck[x].start_next != which)
{
/* Move forward */
x = g->deck[x].start_next;
}
/* Remove moved card from list */
g->deck[x].start_next = c_ptr->start_next;
c_ptr->start_next = -1;
}
}
/* Check for new owner */
if (owner != -1)
{
/* Get player pointer of new owner */
p_ptr = &g->p[owner];
/* Add card to beginning of list */
c_ptr->start_next = p_ptr->start_head[where];
p_ptr->start_head[where] = which;
}
/* Adjust location */
c_ptr->start_owner = owner;
c_ptr->start_where = where;
}
/*
* Draw a card from the deck.
*/
void draw_card(game *g, int who)
{
player *p_ptr;
card *c_ptr;
int which;
/* Get player pointer */
p_ptr = &g->p[who];
/* Check for simulated game */
if (g->simulation)
{
/* Count fake cards */
p_ptr->fake_hand++;
/* Track total number of fake cards seen */
p_ptr->total_fake++;
/* Get card from draw pile */
which = random_draw(g);
/* Check for failure */
if (which == -1) return;
/* Get card pointer */
c_ptr = &g->deck[which];
/* Move card to discard to simulate deck cycling */
c_ptr->where = WHERE_DISCARD;
/* Done */
return;
}
/* Choose random card */
which = random_draw(g);
/* Check for failure */
if (which == -1) return;
/* Move card to player's hand */
move_card(g, which, who, WHERE_HAND);
/* Get card pointer */
c_ptr = &g->deck[which];
/* Card's location is known to player */
c_ptr->known |= 1 << who;
}
/*
* Draw a number of cards, as in draw_card() above.
*/
void draw_cards(game *g, int who, int num)
{
int i;
/* Draw required number */
for (i = 0; i < num; i++) draw_card(g, who);
}
/*
* Give a player some prestige.
*/
static void gain_prestige(game *g, int who, int num)
{
player *p_ptr;
/* Get player pointer */
p_ptr = &g->p[who];
/* Add to prestige */
p_ptr->prestige += num;
/* Mark prestige earned this turn */
p_ptr->prestige_turn = 1;
}
/*
* Spend some of a player's prestige.
*/
static void spend_prestige(game *g, int who, int num)
{
player *p_ptr;
/* Get player pointer */
p_ptr = &g->p[who];
/* Decrease prestige */
p_ptr->prestige -= num;
/* Check goal losses */
check_goal_loss(g, who, GOAL_MOST_PRESTIGE);
}
/*
* Check prestige lead at end of each phase.
*/
static void check_prestige(game *g)
{
player *p_ptr;
int i, max = 0, num = 0;
/* Do nothing unless third expansion is present */
if (g->expanded < 3) return;
/* Loop over players */
for (i = 0; i < g->num_players; i++)
{
/* Get player pointer */
p_ptr = &g->p[i];
/* Track most prestige */
if (p_ptr->prestige > max) max = p_ptr->prestige;
}
/* Do nothing if no one has any prestige */
if (max == 0) return;
/* Count number of players tied for most */
for (i = 0; i < g->num_players; i++)
{
/* Get player pointer */
p_ptr = &g->p[i];
/* Check for tied for most */
if (p_ptr->prestige == max) num++;
}
/* Check for single player with most */
for (i = 0; i < g->num_players; i++)
{
/* Check for less than most */
if (p_ptr->prestige < max) p_ptr->prestige_turn = 0;
/* Check for tie for most */
if (num > 1) p_ptr->prestige_turn = 0;
}
}
/*
* Handle start of round prestige bonuses.
*/
void start_prestige(game *g)
{
player *p_ptr;
char msg[1024];
int i, max = 0, num = 0;
/* Do nothing unless third expansion is present */
if (g->expanded < 3) return;
/* Loop over players */
for (i = 0; i < g->num_players; i++)
{
/* Get player pointer */
p_ptr = &g->p[i];
/* Track most prestige */
if (p_ptr->prestige > max) max = p_ptr->prestige;
}
/* Do nothing if no one has any prestige */
if (max == 0) return;
/* Count number of players tied for most */
for (i = 0; i < g->num_players; i++)
{
/* Get player pointer */
p_ptr = &g->p[i];
/* Check for tied for most */
if (p_ptr->prestige == max) num++;
}
/* Reward VP to those with most prestige */
for (i = 0; i < g->num_players; i++)
{
/* Get player pointer */
p_ptr = &g->p[i];
/* Check for most (or tied) */
if (p_ptr->prestige == max)
{
/* Award VP */
p_ptr->vp++;
/* Remove from pool */
g->vp_pool--;
/* Start message */
if (!g->simulation)
{
/* Format message */
sprintf(msg, "%s earns VP", p_ptr->name);
}
/* Check for sole most, and earned this turn */
if (num == 1 && p_ptr->prestige_turn)
{
/* Draw a card as well */
draw_card(g, i);
/* Message */
if (!g->simulation)
{
/* Add to message */
strcat(msg, " and card");
}
}
/* Finish message */
if (!g->simulation)
{
/* Complete message */
strcat(msg, " for Prestige Leader.\n");
/* Send message */
message_add(g, msg);
}
}
/* Clear prestige earned this turn mark */
p_ptr->prestige_turn = 0;
}
/* Clear temp flags on card just drawn */
clear_temp(g);
/* Check intermediate goals */
check_goals(g);
}
/*
* Clear temp flags on all cards and player structures.
*/
void clear_temp(game *g)
{
player *p_ptr;
card *c_ptr;
int i, j;
/* Loop over cards */
for (i = 0; i < g->deck_size; i++)
{
/* Get card pointer */
c_ptr = &g->deck[i];
/* Copy current location */
c_ptr->start_owner = c_ptr->owner;
c_ptr->start_where = c_ptr->where;
/* Copy next card */
c_ptr->start_next = c_ptr->next;
/* Clear unpaid flag */
c_ptr->unpaid = 0;
/* Clear produced flag */
c_ptr->produced = 0;
/* Loop over used flags */
for (j = 0; j < MAX_POWER; j++)
{
/* Clear flag */
c_ptr->used[j] = 0;
}
}
/* Loop over players */
for (i = 0; i < g->num_players; i++)
{
/* Get player pointer */
p_ptr = &g->p[i];
/* Clear bonus used flag */
p_ptr->phase_bonus_used = 0;
/* Clear bonus military */
p_ptr->bonus_military = 0;
/* Clear bonus settle cost reduction */
p_ptr->bonus_reduce = 0;
/* Loop over location heads */
for (j = 0; j < MAX_WHERE; j++)
{
/* Copy start of list */
p_ptr->start_head[j] = p_ptr->head[j];
}
}
}
/*
* Extract an answer to a pending choice from the player's choice log.
*/
static int extract_choice(game *g, int who, int type, int list[], int *nl,
int special[], int *ns)
{
player *p_ptr;
int *l_ptr;
int rv, i, num;
/* Get player pointer */
p_ptr = &g->p[who];
/* Get current position in log */
l_ptr = &p_ptr->choice_log[p_ptr->choice_pos];
/* Check for no data in log */
if (p_ptr->choice_pos >= p_ptr->choice_size)
{
/* Error */
printf("No data available in choice log!\n");
exit(1);
}
/* Check for correct type of answer */
if (*l_ptr != type)
{
/* Error */
printf("Expected %d in choice log, found %d!\n", type, *l_ptr);
exit(1);
}
/* Advance pointer */
l_ptr++;
/* Copy return value */
rv = *l_ptr++;
/* Get number of items returned */
num = *l_ptr++;
/* Check for number of items available */
if (nl)
{
/* Copy number of items in list */
*nl = num;
/* Copy list items */
for (i = 0; i < num; i++)
{
/* Copy item */
list[i] = *l_ptr++;
}
}
else
{
/* Ensure no items were returned */
if (num)
{
/* Error */
printf("Log has items but nowhere to copy them!\n");
exit(1);
}
}
/* Get number of special items returned */
num = *l_ptr++;
/* Check for number of special items available */
if (ns)
{
/* Copy number of special items */
*ns = num;
/* Copy special items */
for (i = 0; i < num; i++)
{
/* Copy item */
special[i] = *l_ptr++;
}
}
else
{
/* Ensure no items were returned */
if (num)
{
/* Error */
printf("Log has specials but nowhere to copy them!\n");
exit(1);
}
}
/* Set log position to current */
p_ptr->choice_pos = l_ptr - p_ptr->choice_log;
/* Return logged answer */
return rv;
}
/*
* Ask a player to make a decision.
*
* If we are replaying a game session, we may already have the decision
* saved in the player's choice log. In that case, pull the decision
* from the log and return it.
*
* In this function we always wait for an answer from the player before
* returning.
*/
static int ask_player(game *g, int who, int type, int list[], int *nl,
int special[], int *ns, int arg1, int arg2, int arg3)
{
player *p_ptr;
/* Get player pointer */
p_ptr = &g->p[who];
/* Check for unconsumed choices in log */
if (p_ptr->choice_pos < p_ptr->choice_size)
{
/* Return logged answer */
return extract_choice(g, who, type, list, nl, special, ns);
}
/* Ask player for answer */
p_ptr->control->make_choice(g, who, type, list, nl, special, ns,
arg1, arg2, arg3);
/* Check for aborted game */
if (g->game_over) return -1;
/* Check for need to wait for answer */
if (p_ptr->control->wait_answer)
{
/* Wait for answer to become available */
p_ptr->control->wait_answer(g, who);
}
/* Return logged answer */
return extract_choice(g, who, type, list, nl, special, ns);
}
/*
* Ask a player to make a decision.
*
* In this function we will return immediately after asking. The answer
* can later be retrieved using extract_answer() above.
*/
static void send_choice(game *g, int who, int type, int list[], int *nl,
int special[], int *ns, int arg1, int arg2, int arg3)
{
player *p_ptr;
/* Get player pointer */
p_ptr = &g->p[who];
/* Check for unconsumed choices in log */
if (p_ptr->choice_pos < p_ptr->choice_size) return;
/* Ask player for answer */
p_ptr->control->make_choice(g, who, type, list, nl, special, ns,
arg1, arg2, arg3);
}
/*
* Wait for all players to have responses ready to the most recent question.
*/
static void wait_for_all(game *g)
{
player *p_ptr;
int i;
/* Loop over players */
for (i = 0; i < g->num_players; i++)
{
/* Get player pointer */
p_ptr = &g->p[i];
/* Check for need to wait for answer */
if (p_ptr->control->wait_answer)
{
/* Wait for answer to become available */
p_ptr->control->wait_answer(g, i);
}
}
}
/*
* Return a list of cards in the given player's given area.
*/
static int get_player_area(game *g, int who, int list[MAX_DECK], int where)
{
int x, n = 0;
/* Start at beginning of list */
x = g->p[who].head[where];
/* Loop over cards */
for ( ; x != -1; x = g->deck[x].next)
{
/* Add card to list */
list[n++] = x;
}
/* Return number found */
return n;
}
/*
* Return a list of cards holding the given type of good.
*/
static int get_goods(game *g, int who, int goods[MAX_DECK], int type)
{
card *c_ptr;
int x, n = 0;
/* Start at first active card */
x = g->p[who].head[WHERE_ACTIVE];
/* Loop over cards */
for ( ; x != -1; x = g->deck[x].next)
{
/* Get card pointer */
c_ptr = &g->deck[x];