aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--7w.h2
-rw-r--r--data.c47
-rw-r--r--util.c2
-rw-r--r--wonder.c32
4 files changed, 47 insertions, 36 deletions
diff --git a/7w.h b/7w.h
index 6d80213..b6ad441 100644
--- a/7w.h
+++ b/7w.h
@@ -52,3 +52,5 @@
#define COLORMILITARY 31
#define COLORSCIENTIFIC 32
#define COLORGUILD 35
+
+#define INDEF 8
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)
diff --git a/util.c b/util.c
index 829e7d1..2935600 100644
--- a/util.c
+++ b/util.c
@@ -8,6 +8,7 @@ static void replace(char a[], char b[], int x, int y);
#define POOLSIZE 10000
static int ipool[POOLSIZE];
static int *ipoolp = ipool;
+
int* get_intarray(int size)
{
if(ipoolp + size > ipool + POOLSIZE) ipoolp = ipool;
@@ -18,6 +19,7 @@ int* get_intarray(int size)
static char cpool[POOLSIZE];
static char *cpoolp = cpool;
+
char* get_chararray(int size)
{
if(cpoolp + size > cpool + POOLSIZE) cpoolp = cpool;
diff --git a/wonder.c b/wonder.c
index c916e95..51c032e 100644
--- a/wonder.c
+++ b/wonder.c
@@ -21,6 +21,7 @@ void io_clearscreen();
int* data_getbuilt(int p);
void io_printplain(int x, int y, char *s);
int* data_getdefinites(int p);
+int** data_getindefinites(int p);
int wonder_numstages(int player)
{
@@ -34,7 +35,7 @@ int wonder_numstages(int player)
int print_wonder(int x, int y, int player, int cursor)
{
- int i;
+ int i, j;
io_printborder(x, y++);
y = io_printtext(x, y, 29, cards_getname(data_getwonder(player), 0));
y = io_printtext(x, y, 29, cat("Produces: 1 ", getname(cards_gettype(data_getwonder(player), 0))));
@@ -43,18 +44,26 @@ int print_wonder(int x, int y, int player, int cursor)
//Print resource incomes
int *def = data_getdefinites(player);
- int has = 0;
- for(i = 0; i < GOLD; i++)
- if(def[i]) has = 1;
- if(has) {
- y = io_printtext(x, y, 29, "Production:");
- for(i = 0; i < GOLD; i++) {
- if(def[i]) {
- y = io_printtext(x, y, 29, cat(cat(cat(" ", getname(i)), ": "), itoa(def[i])));
- }
+ def[cards_gettype(data_getwonder(player), 0)]++;
+ int **indef = data_getindefinites(player);
+ y = io_printtext(x, y, 29, "Production:");
+ for(i = 0; i < GOLD; i++) {
+ if(def[i]) {
+ y = io_printtext(x, y, 29, cat(cat(cat(" ", getname(i)), ": "), itoa(def[i])));
}
- io_printborder(x, y++);
}
+ for(i = 0; i < INDEF; i++) {
+ char *text = "";
+ for(j = 0; j < 4; j++) {
+ if(indef[i][j] != -1)
+ text = cat(cat(text, "/"), getname(indef[i][j]));
+ }
+ if(text[0] != '\0') {
+ y = io_printtext(x, y, 29, text);
+ io_printplain(x+2, y-1, " ");
+ }
+ }
+ io_printborder(x, y++);
//Print wonder stages
for(i = 0; i < wonder_numstages(player); i++) {
@@ -73,7 +82,6 @@ int print_wonder(int x, int y, int player, int cursor)
//Print what has been built
int *built = data_getbuilt(player);
- int j;
int print = -1;
for(j = 0; built[j] != -1; j+=2) {
io_printname(x, y++, built[j], built[j+1]);
bgstack15