aboutsummaryrefslogtreecommitdiff
path: root/data.c
diff options
context:
space:
mode:
authorNathan Vance <nathav63@gmail.com>2015-02-22 23:04:50 -0500
committerNathan Vance <nathav63@gmail.com>2015-02-22 23:04:50 -0500
commitc5e6b7b4c1adab9c40ea7c73e828605cbad833f8 (patch)
tree04251e3529c5481885c7ae0a91107b95f360bd63 /data.c
parentAdded basic purchasing with definites (diff)
download7w-c5e6b7b4c1adab9c40ea7c73e828605cbad833f8.tar.gz
7w-c5e6b7b4c1adab9c40ea7c73e828605cbad833f8.tar.bz2
7w-c5e6b7b4c1adab9c40ea7c73e828605cbad833f8.zip
Added more support for idefinites, but has major bugs!
Diffstat (limited to 'data.c')
-rw-r--r--data.c47
1 files changed, 23 insertions, 24 deletions
diff --git a/data.c b/data.c
index a1669f6..656c80a 100644
--- a/data.c
+++ b/data.c
@@ -208,19 +208,25 @@ void data_removedefinites(int p, int *cost)
}
}
-#define INDEF 16
-
-int* data_getindefinites(int p)
+int** data_getindefinites(int p)
{
- int *ret = get_intarray(INDEF);
- int i, j, k;
+ int i, j, k, l, m, *prod;
+ static int *ret[INDEF];
+ for(i = 0; i < INDEF; i++) {
+ ret[i] = get_intarray(4);
+ for(j = 0; j < 4; j++)
+ ret[i][j] = -1;
+ }
k = 0;
- for(i = 0; i < INDEF; i++) ret[i] = 0;
for(i = 0; i < 2; i++) {
for(j = 0; j < 7; j++) {
if(data_productiontype(i, player[p][i][j]) == 2) {
- ret[k++] = i;
- ret[k++] = player[p][i][j];
+ m = 0;
+ prod = cards_getproduction(i, player[p][i][j]);
+ for(l = 0; l < GOLD; l++) {
+ if(prod[l]) ret[k][m++] = l;
+ }
+ k++;
}
}
}
@@ -236,24 +242,17 @@ int data_iszerocost(int *cost)
return free;
}
-static int recurse(int *cost, int *indef)
+static int recurse(int *cost, int **indef, int c)
{
+ if(c == INDEF) return 0;
int i;
- int ncost[GOLD], nindef[INDEF], *prod;
+ int ncost[GOLD];
for(i = 0; i < GOLD; i++) ncost[i] = cost[i];
- for(i = 0; i < INDEF; i++) nindef[i] = indef[i];
- for(i = 0; i < INDEF && nindef[i] != 0; i += 2);
- if(i < INDEF) {
- prod = cards_getproduction(nindef[i-1], nindef[i]);
- nindef[i-1] = nindef[i] = 0;
- for(i = 0; i < GOLD; i++) {
- if(prod[i] && ncost[i]) {
- ncost[i] -= prod[i];
- if(data_iszerocost(ncost)) return 1;
- if(recurse(ncost, nindef)) return 1;
- ncost[i] += prod[i];
- }
- }
+ for(i = 0; i < 4 && indef[c][i] != -1; i++) {
+ ncost[indef[c][i]]--;
+ if(data_iszerocost(ncost)) return 1;
+ if(recurse(ncost, indef, c+1)) return 1;
+ ncost[indef[c][i]]++;
}
return 0;
}
@@ -265,7 +264,7 @@ int data_canafford(int p, int *cost)
int i, j, k;
data_removedefinites(p, cost);
if(data_iszerocost(cost)) return 2;
- return recurse(cost, data_getindefinites(p));
+ return recurse(cost, data_getindefinites(p), 0);
}
int* data_getbuilt(int p)
bgstack15