-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathplaydom.c
executable file
·143 lines (129 loc) · 3.17 KB
/
playdom.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
#include "dominion.h"
#include <stdio.h>
#include "rngs.h"
#include <stdlib.h>
int main (int argc, char** argv) {
int money;
int smithyPos;
int adventurerPos;
int i;
int numSmithies;
int numAdventurers;
struct gameState G;
int k[10] = {adventurer, gardens, embargo, village, minion, mine, cutpurse,
sea_hag, tribute, smithy};
printf ("Starting game.\n");
if(argc > 1)
initializeGame(2, k, atoi(argv[1]), &G);
else { printf("BAD!!"); exit(-1); }
money = 0;
smithyPos = -1;
adventurerPos = -1;
i=0;
numSmithies = 0;
numAdventurers = 0;
while (!isGameOver(&G)) {
money = 0;
smithyPos = -1;
adventurerPos = -1;
for (i = 0; i < numHandCards(&G); i++) {
if (handCard(i, &G) == copper)
money++;
else if (handCard(i, &G) == silver)
money += 2;
else if (handCard(i, &G) == gold)
money += 3;
else if (handCard(i, &G) == smithy)
smithyPos = i;
else if (handCard(i, &G) == adventurer)
adventurerPos = i;
}
if (whoseTurn(&G) == 0) {
if (smithyPos != -1) {
printf("0: smithy played from position %d\n", smithyPos);
playCard(smithyPos, -1, -1, -1, &G);
printf("smithy played.\n");
money = 0;
i=0;
while(i<numHandCards(&G)){
if (handCard(i, &G) == copper){
playCard(i, -1, -1, -1, &G);
money++;
}
else if (handCard(i, &G) == silver){
playCard(i, -1, -1, -1, &G);
money += 2;
}
else if (handCard(i, &G) == gold){
playCard(i, -1, -1, -1, &G);
money += 3;
}
i++;
}
}
if (money >= 8) {
printf("0: bought province\n");
buyCard(province, &G);
}
else if (money >= 6) {
printf("0: bought gold\n");
buyCard(gold, &G);
}
else if ((money >= 4) && (numSmithies < 2)) {
printf("0: bought smithy\n");
buyCard(smithy, &G);
numSmithies++;
}
else if (money >= 3) {
printf("0: bought silver\n");
buyCard(silver, &G);
}
printf("0: end turn\n");
endTurn(&G);
}
else {
if (adventurerPos != -1) {
printf("1: adventurer played from position %d\n", adventurerPos);
playCard(adventurerPos, -1, -1, -1, &G);
money = 0;
i=0;
while(i<numHandCards(&G)){
if (handCard(i, &G) == copper){
playCard(i, -1, -1, -1, &G);
money++;
}
else if (handCard(i, &G) == silver){
playCard(i, -1, -1, -1, &G);
money += 2;
}
else if (handCard(i, &G) == gold){
playCard(i, -1, -1, -1, &G);
money += 3;
}
i++;
}
}
if (money >= 8) {
printf("1: bought province\n");
buyCard(province, &G);
}
else if ((money >= 6) && (numAdventurers < 2)) {
printf("1: bought adventurer\n");
buyCard(adventurer, &G);
numAdventurers++;
}else if (money >= 6){
printf("1: bought gold\n");
buyCard(gold, &G);
}
else if (money >= 3){
printf("1: bought silver\n");
buyCard(silver, &G);
}
printf("1: endTurn\n");
endTurn(&G);
}
} // end of While
printf ("Finished game.\n");
printf ("Player 0: %d\nPlayer 1: %d\n", scoreFor(0, &G), scoreFor(1, &G));
return 0;
}